From: Tim 'mithro' Ansell Date: Thu, 29 Nov 2018 04:18:31 +0000 (-0800) Subject: Only write file if contents will change. X-Git-Tag: 24jan2021_ls180~1029^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3ff6a18a45ff4840530d97cd1f6d97e7596afeb5;p=litex.git Only write file if contents will change. --- diff --git a/litex/build/tools.py b/litex/build/tools.py index 28e1937d..81326201 100644 --- a/litex/build/tools.py +++ b/litex/build/tools.py @@ -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():