generate_buildbot_json.py (3706B)
1 #!/usr/bin/env vpython3 2 # Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. 3 # 4 # Use of this source code is governed by a BSD-style license 5 # that can be found in the LICENSE file in the root of the source 6 # tree. An additional intellectual property rights grant can be found 7 # in the file PATENTS. All contributing project authors may 8 # be found in the AUTHORS file in the root of the source tree. 9 """Script to generate the test spec JSON files and the mixins.pyl file from the 10 ADDITIONAL_MIXINS dictonary. Calls Chromium's generate_buildbot_json. 11 """ 12 13 import ast 14 import os 15 import subprocess 16 import sys 17 18 _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) 19 _SRC_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR)) 20 _TESTING_BBOT_DIR = os.path.join(_SRC_DIR, 'testing', 'buildbot') 21 sys.path.insert(0, _SRC_DIR) 22 sys.path.insert(0, _TESTING_BBOT_DIR) 23 24 from testing.buildbot import generate_buildbot_json 25 26 # Add custom mixins here. 27 WEBRTC_MIXIN_FILE_NAME = os.path.join(_SCRIPT_DIR, 'mixins_webrtc.pyl') 28 MIXIN_FILE_NAME = os.path.join(_SCRIPT_DIR, 'mixins.pyl') 29 MIXINS_PYL_TEMPLATE = """\ 30 # GENERATED FILE - DO NOT EDIT. 31 # Generated by {script_name} using data from 32 # {data_source} 33 # 34 # Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. 35 # 36 # Use of this source code is governed by a BSD-style license 37 # that can be found in the LICENSE file in the root of the source 38 # tree. An additional intellectual property rights grant can be found 39 # in the file PATENTS. All contributing project authors may 40 # be found in the AUTHORS file in the root of the source tree. 41 42 {mixin_data} 43 """ 44 45 46 def generate_mixins_file_from_used_mixins(generator): 47 chromium_mixins = generator.load_pyl_file( 48 os.path.join(_TESTING_BBOT_DIR, 'mixins.pyl')) 49 seen_mixins = set() 50 for waterfall in generator.waterfalls: 51 seen_mixins = seen_mixins.union(waterfall.get('mixins', set())) 52 for bot_name, tester in waterfall['machines'].items(): 53 del bot_name 54 seen_mixins = seen_mixins.union(tester.get('mixins', set())) 55 for suite in generator.test_suites.values(): 56 for test in suite.values(): 57 if isinstance(test, list): 58 # This is for mixins defined in variants.pyl. 59 for variant in test: 60 seen_mixins = seen_mixins.union( 61 variant.get('mixins', set())) 62 else: 63 seen_mixins = seen_mixins.union(test.get('mixins', set())) 64 65 found_mixins = ast.literal_eval(open(WEBRTC_MIXIN_FILE_NAME).read()) 66 for mixin in seen_mixins: 67 if mixin not in found_mixins: 68 found_mixins[mixin] = chromium_mixins[mixin] 69 elif mixin in chromium_mixins: 70 assert False, ( 71 '"%s" is already defined in Chromium\'s mixins.pyl' % mixin) 72 73 format_data = { 74 'script_name': os.path.basename(__file__), 75 'data_source': 'mixins_webrtc.pyl and Chromium\'s mixins.pyl', 76 'mixin_data': dict(sorted(found_mixins.items())), 77 } 78 with open(MIXIN_FILE_NAME, 'w') as f: 79 f.write(MIXINS_PYL_TEMPLATE.format(**format_data)) 80 81 return subprocess.call(['yapf', '-i', MIXIN_FILE_NAME]) 82 83 84 def main(): 85 override_args = ['--pyl-files-dir', _SCRIPT_DIR] 86 webrtc_args = generate_buildbot_json.BBJSONGenerator.parse_args( 87 override_args) 88 webrtc_generator = generate_buildbot_json.BBJSONGenerator(webrtc_args) 89 webrtc_generator.load_configuration_files() 90 webrtc_generator.resolve_configuration_files() 91 92 generate_mixins_file_from_used_mixins(webrtc_generator) 93 return webrtc_generator.main() 94 95 96 if __name__ == '__main__': # pragma: no cover 97 sys.exit(main())