forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpo-31536: Avoid wholesale rebuild after
make regen-all
(python#3678)
* bpo-31536: Avoid wholesale rebuild after `make regen-all` * Add NEWS
- Loading branch information
Showing
4 changed files
with
86 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Build/2017-09-20-21-32-21.bpo-31536.KUDjno.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Avoid wholesale rebuild after `make regen-all` if nothing changed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) |