Commit 98a3550b by Shahbaz Youssefi Committed by Commit Bot

Add a presubmit step to make sure autogenerated code is up-to-date

While here, added a presubmit test for the Bug: tag too. Bug: angleproject:3046 Change-Id: I7030685230b4ce4bfc435c14ef85324e16b76274 Reviewed-on: https://chromium-review.googlesource.com/c/1402061 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 4f3b207d
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for code generation.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details on the presubmit API built into depot_tools.
"""
from subprocess import call
def TestCodeGeneration(input_api, output_api):
code_gen_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'scripts/run_code_generation.py')
cmd_name = 'run_code_generation'
cmd = [input_api.python_executable, code_gen_path, '--verify-no-dirty']
test_cmd = input_api.Command(
name=cmd_name,
cmd=cmd,
kwargs={},
message=output_api.PresubmitError)
if input_api.verbose:
print('Running ' + cmd_name)
return input_api.RunTests([test_cmd])
def CheckChangeOnUpload(input_api, output_api):
output = TestCodeGeneration(input_api, output_api)
if not input_api.change.BUG:
output += [output_api.PresubmitError(
'Must provide a Bug: line.')]
return output
def CheckChangeOnCommit(input_api, output_api):
return []
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# #
# run_code_reneration.py: # run_code_generation.py:
# Runs ANGLE format table and other script run_code_renerationgeneration. # Runs ANGLE format table and other script code generation scripts.
import hashlib import hashlib
import json import json
...@@ -183,6 +183,10 @@ old_hashes = json.load(open(hash_fname)) ...@@ -183,6 +183,10 @@ old_hashes = json.load(open(hash_fname))
new_hashes = {} new_hashes = {}
any_dirty = False 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. # Reset the CWD to the root ANGLE directory.
...@@ -192,12 +196,16 @@ for name, info in sorted(generators.iteritems()): ...@@ -192,12 +196,16 @@ for name, info in sorted(generators.iteritems()):
if any_input_dirty(name, info['inputs'] + [script]): if any_input_dirty(name, info['inputs'] + [script]):
any_dirty = True any_dirty = True
# Set the CWD to the script directory. if not verify_only:
os.chdir(get_child_script_dirname(script)) # 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)
print('Running ' + name + ' code generator') if verify_only:
if subprocess.call(['python', os.path.basename(script)]) != 0: sys.exit(any_dirty)
sys.exit(1)
if any_dirty: if any_dirty:
args = [] args = []
......
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