diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-04-03 17:28:18 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-04-03 18:41:55 +0530 |
commit | 777435c4708713f74279a02fb51910b1fbc841b4 (patch) | |
tree | a7a84f2b69d5af758430a02bf4a318e5dfbd69e5 /gsk/gen-gsk-gresources-xml.py | |
parent | fb325afc79536c6c1547eb42e57fca1f9fa11b8b (diff) | |
download | gtk+-777435c4708713f74279a02fb51910b1fbc841b4.tar.gz |
meson: Reduce useless relinking on reconfigure
When we reconfigure, `configure_file()` is called again, and
`*.gresource.xml` files are regenerated, which causes many (all?)
binaries to be relinked. Now we only write those out if the contents
actually changed (or if the output didn't already exist).
This is exactly what Meson already does with `configure_file()` when
`command:` is not used.
While we're at it, also do the same for `gen-c-array.py` and
`gentypefuncs.py` for completeness. Now even if the input to those
changes, re-building of those custom targets may not result in
relinking if the outputted C files have the same contents.
Diffstat (limited to 'gsk/gen-gsk-gresources-xml.py')
-rw-r--r-- | gsk/gen-gsk-gresources-xml.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/gsk/gen-gsk-gresources-xml.py b/gsk/gen-gsk-gresources-xml.py index 1032d84ad9..5db5044b09 100644 --- a/gsk/gen-gsk-gresources-xml.py +++ b/gsk/gen-gsk-gresources-xml.py @@ -5,6 +5,20 @@ # Usage: gen-gsk-gresources-xml OUTPUT-FILE [INPUT-FILE1] [INPUT-FILE2] ... import os, sys +import filecmp + +def replace_if_changed(new, old): + ''' + Compare contents and only replace if changed to avoid triggering a rebuild. + ''' + try: + changed = not filecmp.cmp(new, old, shallow=False) + except FileNotFoundError: + changed = True + if changed: + os.replace(new, old) + else: + os.remove(new) source_shaders = [] vulkan_compiled_shaders = [] @@ -45,8 +59,9 @@ xml += ''' if len(sys.argv) > 1 and sys.argv[1] != '-': outfile = sys.argv[1] - f = open(outfile, 'w') - f.write(xml) - f.close() + tmpfile = outfile + '~' + with open(tmpfile, 'w') as f: + f.write(xml) + replace_if_changed(tmpfile, outfile) else: print(xml) |