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