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 = {
},
}
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "r") as f:
......@@ -169,7 +170,8 @@ def md5(fname):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def any_input_dirty(name, inputs):
def any_input_dirty(name, inputs, new_hashes, old_hashes):
found_dirty_input = False
for finput in inputs:
key = name + ":" + finput
......@@ -178,22 +180,31 @@ def any_input_dirty(name, inputs):
found_dirty_input = True
return found_dirty_input
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':
def any_old_hash_missing(new_hashes, old_hashes):
for name, _ in old_hashes.iteritems():
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']
if any_input_dirty(name, info['inputs'] + [script]):
if any_input_dirty(name, info['inputs'] + [script], new_hashes, old_hashes):
any_dirty = True
if not verify_only:
......@@ -204,10 +215,13 @@ for name, info in sorted(generators.iteritems()):
if subprocess.call(['python', os.path.basename(script)]) != 0:
sys.exit(1)
if verify_only:
if any_old_hash_missing(new_hashes, old_hashes):
any_dirty = True
if verify_only:
sys.exit(any_dirty)
if any_dirty:
if any_dirty:
args = []
if os.name == 'nt':
args += ['git.bat']
......@@ -222,3 +236,7 @@ if any_dirty:
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