blob: 43ae366cc8e43cb1ae55cb4104f6de3fb6cbd79f [file] [log] [blame]
Jeremy Leconte0c4059c2022-04-04 07:58:40 +02001#!/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
10ADDITIONAL_MIXINS dictonary. Calls Chromium's generate_buildbot_json.
11"""
12
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000013import ast
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020014import os
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000015import subprocess
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020016import sys
17
18_SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
19_SRC_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR))
20sys.path.insert(0, _SRC_DIR)
21sys.path.insert(0, os.path.join(_SRC_DIR, 'testing', 'buildbot'))
22
23from testing.buildbot import generate_buildbot_json
24
25# Add custom mixins here.
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000026WEBRTC_MIXIN_FILE_NAME = os.path.join(_SCRIPT_DIR, 'mixins_webrtc.pyl')
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020027MIXIN_FILE_NAME = os.path.join(_SCRIPT_DIR, 'mixins.pyl')
28MIXINS_PYL_TEMPLATE = """\
29# GENERATED FILE - DO NOT EDIT.
30# Generated by {script_name} using data from
31# {data_source}
32#
33# Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
34#
35# Use of this source code is governed by a BSD-style license
36# that can be found in the LICENSE file in the root of the source
37# tree. An additional intellectual property rights grant can be found
38# in the file PATENTS. All contributing project authors may
39# be found in the AUTHORS file in the root of the source tree.
40
41{mixin_data}
42"""
43
44
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000045def generate_mixins_file_from_used_mixins(generator):
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020046 chromium_args = generate_buildbot_json.BBJSONGenerator.parse_args(argv=None)
47 chromium_generator = generate_buildbot_json.BBJSONGenerator(chromium_args)
48 chromium_generator.load_configuration_files()
49
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000050 seen_mixins = set()
51 for waterfall in generator.waterfalls:
52 seen_mixins = seen_mixins.union(waterfall.get('mixins', set()))
53 for bot_name, tester in waterfall['machines'].items():
54 del bot_name
55 seen_mixins = seen_mixins.union(tester.get('mixins', set()))
56 for suite in generator.test_suites.values():
57 for test in suite.values():
Jeremy Leconte83fd8432023-01-12 14:27:13 +010058 if isinstance(test, list):
59 # This is for mixins defined in variants.pyl.
60 for variant in test:
61 seen_mixins = seen_mixins.union(variant.get('mixins', set()))
62 else:
63 seen_mixins = seen_mixins.union(test.get('mixins', set()))
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000064
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_generator.mixins[mixin]
69 elif mixin in chromium_generator.mixins:
70 assert False, '"%s" is already defined in Chromium\'s mixins.pyl' % mixin
71
72 format_data = {
73 'script_name': os.path.basename(__file__),
74 'data_source': 'mixins_webrtc.pyl and Chromium\'s mixins.pyl',
75 'mixin_data': dict(sorted(found_mixins.items())),
76 }
77 with open(MIXIN_FILE_NAME, 'w') as f:
78 f.write(MIXINS_PYL_TEMPLATE.format(**format_data))
79
80 return subprocess.call(['yapf', '-i', MIXIN_FILE_NAME])
81
82
83def main():
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020084 override_args = ['--pyl-files-dir', _SCRIPT_DIR]
85 webrtc_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args)
86 webrtc_generator = generate_buildbot_json.BBJSONGenerator(webrtc_args)
87 webrtc_generator.load_configuration_files()
88 webrtc_generator.resolve_configuration_files()
89
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000090 generate_mixins_file_from_used_mixins(webrtc_generator)
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020091 return webrtc_generator.main()
92
93
94if __name__ == '__main__': # pragma: no cover
95 sys.exit(main())