• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
10ADDITIONAL_MIXINS dictonary. Calls Chromium's generate_buildbot_json.
11"""
12
13import ast
14import os
15import subprocess
16import 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.
26WEBRTC_MIXIN_FILE_NAME = os.path.join(_SCRIPT_DIR, 'mixins_webrtc.pyl')
27MIXIN_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
45def generate_mixins_file_from_used_mixins(generator):
46  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
50  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():
79  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
85  generate_mixins_file_from_used_mixins(webrtc_generator)
86  return webrtc_generator.main()
87
88
89if __name__ == '__main__':  # pragma: no cover
90  sys.exit(main())
91