1#!/usr/bin/env python 2# Copyright 2021 The ANGLE Project Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""Script to generate the test spec JSON files. Calls Chromium's generate_buildbot_json. 6 7=== NOTE: DO NOT RUN THIS SCRIPT DIRECTLY. === 8Run scripts/run_code_generation.py instead to update necessary hashes. 9 10""" 11 12import os 13import pprint 14import sys 15import subprocess 16 17d = os.path.dirname 18THIS_DIR = d(os.path.abspath(__file__)) 19TESTING_BBOT_DIR = os.path.join(d(d(THIS_DIR)), 'testing', 'buildbot') 20sys.path.insert(0, TESTING_BBOT_DIR) 21 22import generate_buildbot_json 23 24# Add custom mixins here. 25ADDITIONAL_MIXINS = { 26 'angle_skia_gold_test': { 27 '$mixin_append': { 28 'args': [ 29 '--git-revision=${got_angle_revision}', 30 # BREAK GLASS IN CASE OF EMERGENCY 31 # Uncommenting this argument will bypass all interactions with Skia 32 # Gold in any tests that use it. This is meant as a temporary 33 # emergency stop in case of a Gold outage that's affecting the bots. 34 # '--bypass-skia-gold-functionality', 35 ], 36 'precommit_args': [ 37 '--gerrit-issue=${patch_issue}', 38 '--gerrit-patchset=${patch_set}', 39 '--buildbucket-id=${buildbucket_build_id}', 40 ], 41 } 42 }, 43} 44MIXIN_FILE_NAME = os.path.join(THIS_DIR, 'mixins.pyl') 45MIXINS_PYL_TEMPLATE = """\ 46# GENERATED FILE - DO NOT EDIT. 47# Generated by {script_name} using data from {data_source} 48# 49# Copyright 2021 The ANGLE Project Authors. All rights reserved. 50# Use of this source code is governed by a BSD-style license that can be 51# found in the LICENSE file. 52# 53# This is a .pyl, or "Python Literal", file. You can treat it just like a 54# .json file, with the following exceptions: 55# * all keys must be quoted (use single quotes, please); 56# * comments are allowed, using '#' syntax; and 57# * trailing commas are allowed. 58# 59# For more info see Chromium's mixins.pyl in testing/buildbot. 60 61{mixin_data} 62""" 63 64 65def main(): 66 if len(sys.argv) > 1: 67 gen_bb_json = os.path.join(TESTING_BBOT_DIR, 'generate_buildbot_json.py') 68 mixins_pyl = os.path.join(TESTING_BBOT_DIR, 'mixins.pyl') 69 inputs = [ 70 'test_suite_exceptions.pyl', 'test_suites.pyl', 'variants.pyl', 'waterfalls.pyl', 71 gen_bb_json, mixins_pyl 72 ] 73 outputs = ['angle.json', 'mixins.pyl'] 74 if sys.argv[1] == 'inputs': 75 print(','.join(inputs)) 76 elif sys.argv[1] == 'outputs': 77 print(','.join(outputs)) 78 else: 79 print('Invalid script parameters') 80 return 1 81 return 0 82 83 chromium_args = generate_buildbot_json.BBJSONGenerator.parse_args(sys.argv[1:]) 84 chromium_generator = generate_buildbot_json.BBJSONGenerator(chromium_args) 85 chromium_generator.load_configuration_files() 86 87 override_args = sys.argv[1:] + ['--pyl-files-dir', THIS_DIR] 88 angle_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args) 89 angle_generator = generate_buildbot_json.BBJSONGenerator(angle_args) 90 angle_generator.load_configuration_files() 91 angle_generator.resolve_configuration_files() 92 93 seen_mixins = set() 94 for waterfall in angle_generator.waterfalls: 95 seen_mixins = seen_mixins.union(waterfall.get('mixins', set())) 96 for bot_name, tester in waterfall['machines'].iteritems(): 97 seen_mixins = seen_mixins.union(tester.get('mixins', set())) 98 for suite in angle_generator.test_suites.values(): 99 if isinstance(suite, list): 100 # Don't care about this, it's a composition, which shouldn't include a 101 # swarming mixin. 102 continue 103 for test in suite.values(): 104 assert isinstance(test, dict) 105 seen_mixins = seen_mixins.union(test.get('mixins', set())) 106 107 found_mixins = ADDITIONAL_MIXINS.copy() 108 for mixin in seen_mixins: 109 if mixin in found_mixins: 110 continue 111 assert (mixin in chromium_generator.mixins) 112 found_mixins[mixin] = chromium_generator.mixins[mixin] 113 114 pp = pprint.PrettyPrinter(indent=2) 115 116 format_data = { 117 'script_name': os.path.basename(__file__), 118 'data_source': 'waterfall.pyl and Chromium\'s mixins.pyl', 119 'mixin_data': pp.pformat(found_mixins), 120 } 121 generated_mixin_pyl = MIXINS_PYL_TEMPLATE.format(**format_data) 122 123 with open(MIXIN_FILE_NAME, 'w') as f: 124 f.write(generated_mixin_pyl) 125 f.close() 126 127 return angle_generator.main() 128 129 130if __name__ == '__main__': # pragma: no cover 131 sys.exit(main()) 132