Only write file if contents will change.
authorTim 'mithro' Ansell <me@mith.ro>
Thu, 29 Nov 2018 04:18:31 +0000 (20:18 -0800)
committerTim 'mithro' Ansell <me@mith.ro>
Mon, 2 Sep 2019 21:26:41 +0000 (14:26 -0700)
litex/build/tools.py

index 28e1937d5a64844b8d76837ecc509b36bcb152fc..8132620129cf7edff3f43066d247a5db783aeaac 100644 (file)
@@ -28,8 +28,13 @@ def write_to_file(filename, contents, force_unix=False):
     newline = None
     if force_unix:
         newline = "\n"
-    with open(filename, "w", newline=newline) as f:
-        f.write(contents)
+    old_contents = None
+    if os.path.exists(filename):
+        with open(filename, "r", newline=newline) as f:
+            old_contents = f.read()
+    if old_contents != contents:
+        with open(filename, "w", newline=newline) as f:
+            f.write(contents)
 
 
 def arch_bits():