diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-09-20 21:57:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-09-20 21:57:56 (GMT) |
commit | b091bec824137f286b22084be5f8d397d21b9abb (patch) | |
tree | 39ac8ea636a3df84dd613007e0dfa6209736db73 /Tools/scripts | |
parent | aaf6fc0982c916cb71d9e0afcd7dda4ba495793b (diff) | |
download | cpython-b091bec824137f286b22084be5f8d397d21b9abb.zip cpython-b091bec824137f286b22084be5f8d397d21b9abb.tar.gz cpython-b091bec824137f286b22084be5f8d397d21b9abb.tar.bz2 |
bpo-31536: Avoid wholesale rebuild after `make regen-all` (#3678)
* bpo-31536: Avoid wholesale rebuild after `make regen-all`
* Add NEWS
Diffstat (limited to 'Tools/scripts')
-rw-r--r-- | Tools/scripts/update_file.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Tools/scripts/update_file.py b/Tools/scripts/update_file.py new file mode 100644 index 0000000..224585c --- /dev/null +++ b/Tools/scripts/update_file.py @@ -0,0 +1,28 @@ +""" +A script that replaces an old file with a new one, only if the contents +actually changed. If not, the new file is simply deleted. + +This avoids wholesale rebuilds when a code (re)generation phase does not +actually change the in-tree generated code. +""" + +import os +import sys + + +def main(old_path, new_path): + with open(old_path, 'rb') as f: + old_contents = f.read() + with open(new_path, 'rb') as f: + new_contents = f.read() + if old_contents != new_contents: + os.replace(new_path, old_path) + else: + os.unlink(new_path) + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: %s <path to be updated> <path with new contents>" % (sys.argv[0],)) + sys.exit(1) + main(sys.argv[1], sys.argv[2]) |