Commit 2f1c1d7e by Jamie Madill Committed by Commit Bot

Minor improvements to run_code_generation.

Isolate variables better. And add a check for out-of-date hases. Currently if a generator is removed the hashes will stick around. Bug: angleproject:3227 Change-Id: I9b9da245b9b29093b1f3f320a81810cd7da82395 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1500575 Commit-Queue: Jamie Madill <jmadill@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent b8cff9e9
...@@ -162,6 +162,7 @@ generators = { ...@@ -162,6 +162,7 @@ generators = {
}, },
} }
def md5(fname): def md5(fname):
hash_md5 = hashlib.md5() hash_md5 = hashlib.md5()
with open(fname, "r") as f: with open(fname, "r") as f:
...@@ -169,7 +170,8 @@ def md5(fname): ...@@ -169,7 +170,8 @@ def md5(fname):
hash_md5.update(chunk) hash_md5.update(chunk)
return hash_md5.hexdigest() return hash_md5.hexdigest()
def any_input_dirty(name, inputs):
def any_input_dirty(name, inputs, new_hashes, old_hashes):
found_dirty_input = False found_dirty_input = False
for finput in inputs: for finput in inputs:
key = name + ":" + finput key = name + ":" + finput
...@@ -178,47 +180,63 @@ def any_input_dirty(name, inputs): ...@@ -178,47 +180,63 @@ def any_input_dirty(name, inputs):
found_dirty_input = True found_dirty_input = True
return found_dirty_input return found_dirty_input
os.chdir(script_dir)
old_hashes = json.load(open(hash_fname))
new_hashes = {}
any_dirty = False
verify_only = False def any_old_hash_missing(new_hashes, old_hashes):
if len(sys.argv) > 1 and sys.argv[1] == '--verify-no-dirty': for name, _ in old_hashes.iteritems():
verify_only = True if name not in new_hashes:
return True
return False
def main():
os.chdir(script_dir)
old_hashes = json.load(open(hash_fname))
new_hashes = {}
any_dirty = False
verify_only = False
if len(sys.argv) > 1 and sys.argv[1] == '--verify-no-dirty':
verify_only = True
for name, info in sorted(generators.iteritems()):
for name, info in sorted(generators.iteritems()): # Reset the CWD to the root ANGLE directory.
os.chdir(root_dir)
script = info['script']
# Reset the CWD to the root ANGLE directory. if any_input_dirty(name, info['inputs'] + [script], new_hashes, old_hashes):
os.chdir(root_dir) any_dirty = True
script = info['script']
if any_input_dirty(name, info['inputs'] + [script]): if not verify_only:
# Set the CWD to the script directory.
os.chdir(get_child_script_dirname(script))
print('Running ' + name + ' code generator')
if subprocess.call(['python', os.path.basename(script)]) != 0:
sys.exit(1)
if any_old_hash_missing(new_hashes, old_hashes):
any_dirty = True any_dirty = True
if not verify_only: if verify_only:
# Set the CWD to the script directory. sys.exit(any_dirty)
os.chdir(get_child_script_dirname(script))
print('Running ' + name + ' code generator')
if subprocess.call(['python', os.path.basename(script)]) != 0:
sys.exit(1)
if verify_only:
sys.exit(any_dirty)
if any_dirty:
args = []
if os.name == 'nt':
args += ['git.bat']
else:
args += ['git']
# The diff can be so large the arguments to clang-format can break the Windows command
# line length limits. Work around this by calling git cl format with --full.
args += ['cl', 'format', '--full']
print('Calling git cl format')
subprocess.call(args)
os.chdir(script_dir) if any_dirty:
json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True, args = []
separators=(',', ':\n ')) if os.name == 'nt':
args += ['git.bat']
else:
args += ['git']
# The diff can be so large the arguments to clang-format can break the Windows command
# line length limits. Work around this by calling git cl format with --full.
args += ['cl', 'format', '--full']
print('Calling git cl format')
subprocess.call(args)
os.chdir(script_dir)
json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True,
separators=(',', ':\n '))
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment