diff options
author | plundblad <plundblad@chromium.org> | 2015-05-11 11:12:39 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-11 18:14:06 +0000 |
commit | 9e0db32de116c0e36f66ca2785485e412451fe24 (patch) | |
tree | 9942d9587d1150523535af3dff5af3aefd83d9c6 /tools/gypv8sh.py | |
parent | a30f77e9853d7583ed53f1048ac178194737bf38 (diff) | |
download | chromium_src-9e0db32de116c0e36f66ca2785485e412451fe24.zip chromium_src-9e0db32de116c0e36f66ca2785485e412451fe24.tar.gz chromium_src-9e0db32de116c0e36f66ca2785485e412451fe24.tar.bz2 |
Avoid clobbering generated files if the content hasn't changed.
When editing javascript gtest files, the generated C++ file that runs the
tests rarely changes. Not rewriting them avoids recompiles and
relinks of the test binary which speeds up incremental builds.
R=dmazzoni@chromium.org
BUG=
Review URL: https://codereview.chromium.org/1129893004
Cr-Commit-Position: refs/heads/master@{#329187}
Diffstat (limited to 'tools/gypv8sh.py')
-rwxr-xr-x | tools/gypv8sh.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/gypv8sh.py b/tools/gypv8sh.py index 9724ed4..2a1fada 100755 --- a/tools/gypv8sh.py +++ b/tools/gypv8sh.py @@ -15,6 +15,16 @@ import sys import shutil +def HasSameContent(filename, content): + '''Returns true if the given file is readable and has the given content.''' + try: + with open(filename) as file: + return file.read() == content + except: + # Ignore all errors and fall back on a safe bet. + return False + + def main (): parser = optparse.OptionParser() parser.set_usage( @@ -55,8 +65,9 @@ def main (): p = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) out, err = p.communicate() - with open(cxxoutfile, 'wb') as f: - f.write(out) + if not HasSameContent(cxxoutfile, out): + with open(cxxoutfile, 'wb') as f: + f.write(out) shutil.copyfile(inputfile, jsoutfile) except Exception, ex: if os.path.exists(cxxoutfile): @@ -67,4 +78,4 @@ def main (): if __name__ == '__main__': - sys.exit(main()) + sys.exit(main()) |