Disable hashes for ANGLE features generator

Features autogen files are small, fast to regenerate.
Run the generator in --verify-only mode and check content every time,
instead of using hashes.

Bug: angleproject:8193
Change-Id: I3988ab50a6c33171b7b7252c03f34a74f09fcf18
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4604579
Commit-Queue: Roman Lavrov <romanl@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Roman Lavrov
2023-06-09 18:39:52 -04:00
committed by Angle LUCI CQ
parent f1e1987261
commit 1572f609c1
3 changed files with 51 additions and 42 deletions

View File

@@ -140,6 +140,20 @@ def header_path(class_name):
return 'autogen/' + make_header_name(class_name)
def write_or_verify_file(filename, content, verify_only):
if verify_only:
try:
with open(filename) as f:
# Note: .gitattributes "* text=auto" handles LF <-> CRLF on Windows
return f.read() == content
except FileNotFoundError:
return False
else:
with open(filename, 'w') as fout:
fout.write(content)
return True
def main():
if len(sys.argv) == 2 and sys.argv[1] == 'inputs':
print(','.join(list(feature_files.keys())))
@@ -149,6 +163,10 @@ def main():
',' + feature_list_header_file + ',' + feature_list_source_file)
return
# --verify-only enables dirty checks without relying on checked in hashes.
# Compares the content of the existing file with the generated content.
verify_only = '--verify-only' in sys.argv
name_map = {}
for src_file, (category_prefix, class_name) in feature_files.items():
@@ -191,9 +209,8 @@ def main():
NAME=class_name.upper(),
features='\n'.join(features))
with open(header_path(class_name), 'w') as fout:
fout.write(header)
fout.close()
if not write_or_verify_file(header_path(class_name), header, verify_only):
return 1
# Generate helpers for use by tests to override a feature or not.
feature_enums = []
@@ -206,21 +223,21 @@ def main():
feature_strings.append(
template_feature_string.format(VarName=VarName, display_name=display_name))
with open(feature_list_header_file, 'w') as fout:
fout.write(
if not write_or_verify_file(
feature_list_header_file,
template_feature_list_header.format(
script_name=os.path.basename(__file__),
input_file_name='*_features.json',
features='\n'.join(' ' + v for v in feature_enums)))
fout.close()
features='\n'.join(' ' + v for v in feature_enums)), verify_only):
return 1
with open(feature_list_source_file, 'w') as fout:
fout.write(
if not write_or_verify_file(
feature_list_source_file,
template_feature_list_source.format(
script_name=os.path.basename(__file__),
input_file_name='*_features.json',
features='\n'.join(feature_strings)))
fout.close()
features='\n'.join(feature_strings)), verify_only):
return 1
if __name__ == '__main__':

View File

@@ -1,28 +0,0 @@
{
"include/platform/autogen/FeaturesD3D_autogen.h":
"d0af019005a4e771f23bf59501da6ad8",
"include/platform/autogen/FeaturesGL_autogen.h":
"ed6342efe54ee4e3fc2b0e4431e4483c",
"include/platform/autogen/FeaturesMtl_autogen.h":
"d7d21bebe1e95f7b9041769e9db4e975",
"include/platform/autogen/FeaturesVk_autogen.h":
"765cdbfaac839d8270eb58f61a5a6e93",
"include/platform/autogen/FrontendFeatures_autogen.h":
"032d7687e0bc9e6ba5bd86029fd71ff2",
"include/platform/d3d_features.json":
"c3f7694511855304b3f678a6ad461d1e",
"include/platform/frontend_features.json":
"db98716ec9e23fc17f32bf9bc53cc331",
"include/platform/gen_features.py":
"7d85e07af44194d80615899accde596f",
"include/platform/gl_features.json":
"deb7ed855cb00b5cbedf4f3c5bab329a",
"include/platform/mtl_features.json":
"c1430ea5f79a6da446914b467058d9e7",
"include/platform/vk_features.json":
"4bf60b8b8430c680ca789cb48257ea3d",
"util/autogen/angle_features_autogen.cpp":
"58ece285f162dd37588c75bc815c13d5",
"util/autogen/angle_features_autogen.h":
"251a5ef9e8222dd9ecb3b7ad0d9cb5a5"
}

View File

@@ -66,8 +66,6 @@ def auto_script(script):
generators = {
'ANGLE features':
'include/platform/gen_features.py',
'ANGLE format':
'src/libANGLE/renderer/gen_angle_format_table.py',
'ANGLE load functions table':
@@ -135,6 +133,12 @@ generators = {
}
# Fast and supports --verify-only without hashes.
hashless_generators = {
'ANGLE features': 'include/platform/gen_features.py',
}
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "r") as f:
@@ -252,8 +256,22 @@ def main():
if not runningSingleGenerator and any_old_hash_missing(all_new_hashes, all_old_hashes):
any_dirty = True
# Handle hashless_generators separately as these don't have hash maps.
hashless_generators_dirty = False
for name, script in sorted(hashless_generators.items()):
cmd = [get_executable_name(script), os.path.basename(script)]
rc = subprocess.call(cmd + ['--verify-only'], cwd=get_child_script_dirname(script))
if rc != 0:
print(name + ' generator dirty')
# Don't set any_dirty as we don't need git cl format in this case.
hashless_generators_dirty = True
if not args.verify_only:
print('Running ' + name + ' code generator')
subprocess.check_call(cmd, cwd=get_child_script_dirname(script))
if args.verify_only:
sys.exit(any_dirty)
return int(any_dirty or hashless_generators_dirty)
if any_dirty:
args = ['git.bat'] if os.name == 'nt' else ['git']
@@ -273,6 +291,8 @@ def main():
json.dump(new_hashes, f, indent=2, sort_keys=True, separators=(',', ':\n '))
f.write('\n') # json.dump doesn't end with newline
return 0
if __name__ == '__main__':
sys.exit(main())