blob: aa0375198f4b572be84c3e726499b71369a0e9d1 [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():
58 seen_mixins = seen_mixins.union(test.get('mixins', set()))
59
60 found_mixins = ast.literal_eval(open(WEBRTC_MIXIN_FILE_NAME).read())
61 for mixin in seen_mixins:
62 if mixin not in found_mixins:
63 found_mixins[mixin] = chromium_generator.mixins[mixin]
64 elif mixin in chromium_generator.mixins:
65 assert False, '"%s" is already defined in Chromium\'s mixins.pyl' % mixin
66
67 format_data = {
68 'script_name': os.path.basename(__file__),
69 'data_source': 'mixins_webrtc.pyl and Chromium\'s mixins.pyl',
70 'mixin_data': dict(sorted(found_mixins.items())),
71 }
72 with open(MIXIN_FILE_NAME, 'w') as f:
73 f.write(MIXINS_PYL_TEMPLATE.format(**format_data))
74
75 return subprocess.call(['yapf', '-i', MIXIN_FILE_NAME])
76
77
78def main():
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020079 override_args = ['--pyl-files-dir', _SCRIPT_DIR]
80 webrtc_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args)
81 webrtc_generator = generate_buildbot_json.BBJSONGenerator(webrtc_args)
82 webrtc_generator.load_configuration_files()
83 webrtc_generator.resolve_configuration_files()
84
Mirko Bonadei5c8993c2022-04-04 18:43:54 +000085 generate_mixins_file_from_used_mixins(webrtc_generator)
Jeremy Leconte0c4059c2022-04-04 07:58:40 +020086 return webrtc_generator.main()
87
88
89if __name__ == '__main__': # pragma: no cover
90 sys.exit(main())