Commit 3c1f5a6b by Jamie Madill Committed by Commit Bot

Include script outputs in run_code_generation.py.

This will prevent incorrect modifications to outputs from being checked into the repository. Requires a few changes to some generators. Bug: angleproject:3227 Change-Id: I5285cb78a9d85df155a5272edf8b6b8cd27fc04c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1515212Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent f576a708
...@@ -26,10 +26,10 @@ def get_child_script_dirname(script): ...@@ -26,10 +26,10 @@ def get_child_script_dirname(script):
def clean_path_slashes(path): def clean_path_slashes(path):
return path.replace("\\", "/") return path.replace("\\", "/")
# Takes a script input file name which is relative to the code generation script's directory and # Takes a script file name which is relative to the code generation script's directory and
# changes it to be relative to the angle root directory # changes it to be relative to the angle root directory
def rebase_script_path(script_path, input_file_path): def rebase_script_path(script_path, relative_path):
return os.path.relpath(os.path.join(os.path.dirname(script_path), input_file_path), root_dir) return os.path.relpath(os.path.join(os.path.dirname(script_path), relative_path), root_dir)
def grab_from_script(script, param): def grab_from_script(script, param):
res = subprocess.check_output(['python', script, param]).strip() res = subprocess.check_output(['python', script, param]).strip()
...@@ -41,10 +41,13 @@ def auto_script(script): ...@@ -41,10 +41,13 @@ def auto_script(script):
# Set the CWD to the script directory. # Set the CWD to the script directory.
os.chdir(get_child_script_dirname(script)) os.chdir(get_child_script_dirname(script))
base_script = os.path.basename(script) base_script = os.path.basename(script)
return { info = {
'inputs': grab_from_script(base_script, 'inputs'), 'inputs': grab_from_script(base_script, 'inputs'),
'outputs': grab_from_script(base_script, 'outputs') 'outputs': grab_from_script(base_script, 'outputs')
} }
# Reset the CWD to the root ANGLE directory.
os.chdir(root_dir)
return info
hash_fname = "run_code_generation_hashes.json" hash_fname = "run_code_generation_hashes.json"
...@@ -98,23 +101,37 @@ def md5(fname): ...@@ -98,23 +101,37 @@ def md5(fname):
return hash_md5.hexdigest() return hash_md5.hexdigest()
def any_input_dirty(name, inputs, new_hashes, old_hashes): def any_hash_dirty(name, filenames, new_hashes, old_hashes):
found_dirty_input = False found_dirty_hash = False
for finput in inputs: for filename in filenames:
key = name + ":" + finput key = name + ":" + filename
new_hashes[key] = md5(finput) if not os.path.isfile(filename):
if (not key in old_hashes) or (old_hashes[key] != new_hashes[key]): found_dirty_hash = True
found_dirty_input = True else:
return found_dirty_input new_hashes[key] = md5(filename)
if (not key in old_hashes) or (old_hashes[key] != new_hashes[key]):
found_dirty_hash = True
return found_dirty_hash
def any_old_hash_missing(new_hashes, old_hashes): def any_old_hash_missing(new_hashes, old_hashes):
for name, _ in old_hashes.iteritems(): for name, _ in old_hashes.iteritems():
if name not in new_hashes: if name not in new_hashes:
script, file = name.split(':')
print('%s missing from generated hashes.' % file)
return True return True
return False return False
def update_output_hashes(script, outputs, new_hashes):
for output in outputs:
if not os.path.isfile(output):
print('Output is missing from %s: %s' % (script, output))
sys.exit(1)
key = script + ":" + output
new_hashes[key] = md5(output)
def main(): def main():
os.chdir(script_dir) os.chdir(script_dir)
old_hashes = json.load(open(hash_fname)) old_hashes = json.load(open(hash_fname))
...@@ -126,13 +143,9 @@ def main(): ...@@ -126,13 +143,9 @@ def main():
verify_only = True verify_only = True
for name, script in sorted(generators.iteritems()): for name, script in sorted(generators.iteritems()):
info = auto_script(script) info = auto_script(script)
filenames = info['inputs'] + info['outputs'] + [script]
# Reset the CWD to the root ANGLE directory. if any_hash_dirty(name, filenames, new_hashes, old_hashes):
os.chdir(root_dir)
if any_input_dirty(name, info['inputs'] + [script], new_hashes, old_hashes):
any_dirty = True any_dirty = True
if not verify_only: if not verify_only:
...@@ -161,6 +174,11 @@ def main(): ...@@ -161,6 +174,11 @@ def main():
print('Calling git cl format') print('Calling git cl format')
subprocess.call(args) subprocess.call(args)
# Update the output hashes again since they can be formatted.
for name, script in sorted(generators.iteritems()):
info = auto_script(script)
update_output_hashes(name, info['outputs'], new_hashes)
os.chdir(script_dir) os.chdir(script_dir)
json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True, json.dump(new_hashes, open(hash_fname, "w"), indent=2, sort_keys=True,
separators=(',', ':\n ')) separators=(',', ':\n '))
......
...@@ -53,7 +53,9 @@ namespace rx ...@@ -53,7 +53,9 @@ namespace rx
class DispatchTableGL : angle::NonCopyable class DispatchTableGL : angle::NonCopyable
{{ {{
public: public:
// clang-format off
{table_data} {table_data}
// clang-format on
DispatchTableGL(); DispatchTableGL();
virtual ~DispatchTableGL() = default; virtual ~DispatchTableGL() = default;
......
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