blob: a9b560d8e648da0ee33c2bc039816e2884e52881 [file] [log] [blame]
Christoffer Jansson4e8a7732022-02-08 09:01:12 +01001#!/usr/bin/env vpython3
2
kjellandera013a022016-11-14 05:54:22 -08003# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
4#
5# Use of this source code is governed by a BSD-style license
6# that can be found in the LICENSE file in the root of the source
7# tree. An additional intellectual property rights grant can be found
8# in the file PATENTS. All contributing project authors may
9# be found in the AUTHORS file in the root of the source tree.
10
Oleh Prypinb708e932018-03-18 17:34:20 +010011"""MB - the Meta-Build wrapper around GN.
kjellandera013a022016-11-14 05:54:22 -080012
Oleh Prypinb708e932018-03-18 17:34:20 +010013MB is a wrapper script for GN that can be used to generate build files
kjellandera013a022016-11-14 05:54:22 -080014for sets of canned configurations and analyze them.
15"""
16
kjellandera013a022016-11-14 05:54:22 -080017import os
kjellandera013a022016-11-14 05:54:22 -080018import sys
kjellandera013a022016-11-14 05:54:22 -080019
Jeremy Leconte81635f32022-03-29 12:32:14 +020020_SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
21_SRC_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR))
22sys.path.insert(0, _SRC_DIR)
kjellandera013a022016-11-14 05:54:22 -080023
Jeremy Leconte81635f32022-03-29 12:32:14 +020024from tools.mb import mb
kjellandera013a022016-11-14 05:54:22 -080025
26
Jeremy Leconte145ff4c2022-03-28 11:32:20 +020027def _get_executable(target, platform):
28 executable_prefix = '.\\' if platform == 'win32' else './'
29 executable_suffix = '.exe' if platform == 'win32' else ''
30 return executable_prefix + target + executable_suffix
31
32
kjellandera013a022016-11-14 05:54:22 -080033def main(args):
Jeremy Leconte81635f32022-03-29 12:32:14 +020034 mbw = WebRTCMetaBuildWrapper()
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010035 return mbw.Main(args)
kjellandera013a022016-11-14 05:54:22 -080036
37
Jeremy Leconte81635f32022-03-29 12:32:14 +020038class WebRTCMetaBuildWrapper(mb.MetaBuildWrapper):
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010039 def __init__(self):
Jeremy Leconte81635f32022-03-29 12:32:14 +020040 super(WebRTCMetaBuildWrapper, self).__init__()
41 # Make sure default_config and default_isolate_map are attributes of the
42 # parent class before changing their values.
43 # pylint: disable=access-member-before-definition
44 assert self.default_config
45 assert self.default_isolate_map
46 self.default_config = os.path.join(_SCRIPT_DIR, 'mb_config.pyl')
47 self.default_isolate_map = os.path.join(_SCRIPT_DIR, 'gn_isolate_map.pyl')
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010048
49 def GetSwarmingCommand(self, target, vals):
50 isolate_map = self.ReadIsolateMap()
51 test_type = isolate_map[target]['type']
52
53 is_android = 'target_os="android"' in vals['gn_args']
54 is_linux = self.platform.startswith('linux') and not is_android
Jeremy Leconted15f3e12022-02-18 10:16:32 +010055 is_ios = 'target_os="ios"' in vals['gn_args']
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010056
57 if test_type == 'nontest':
58 self.WriteFailureAndRaise('We should not be isolating %s.' % target,
59 output_path=None)
60 if test_type not in ('console_test_launcher', 'windowed_test_launcher',
61 'non_parallel_console_test_launcher', 'raw',
62 'additional_compile_target', 'junit_test', 'script'):
63 self.WriteFailureAndRaise('No command line for '
64 '%s found (test type %s).' %
65 (target, test_type),
66 output_path=None)
67
68 cmdline = []
69 extra_files = [
Mirko Bonadei5d9ae862022-01-27 20:18:16 +010070 '../../.vpython3',
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010071 '../../testing/test_env.py',
72 ]
Mirko Bonadei5d9ae862022-01-27 20:18:16 +010073 vpython_exe = 'vpython3'
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010074
Jeremy Leconte145ff4c2022-03-28 11:32:20 +020075 if isolate_map[target].get('script'):
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010076 cmdline += [
77 vpython_exe,
78 '../../' + self.ToSrcRelPath(isolate_map[target]['script'])
79 ]
80 elif is_android:
81 cmdline += [
82 vpython_exe, '../../build/android/test_wrapper/logdog_wrapper.py',
83 '--target', target, '--logdog-bin-cmd', '../../bin/logdog_butler',
84 '--logcat-output-file', '${ISOLATED_OUTDIR}/logcats',
85 '--store-tombstones'
86 ]
Jeremy Leconted15f3e12022-02-18 10:16:32 +010087 elif is_ios:
88 cmdline += [
89 vpython_exe, '../../tools_webrtc/flags_compatibility.py',
90 'bin/run_%s' % target, '--out-dir', '${ISOLATED_OUTDIR}'
91 ]
92 extra_files.append('../../tools_webrtc/flags_compatibility.py')
Jeremy Leconte145ff4c2022-03-28 11:32:20 +020093 elif test_type == 'raw':
94 cmdline += [vpython_exe, '../../tools_webrtc/flags_compatibility.py']
95 extra_files.append('../../tools_webrtc/flags_compatibility.py')
96 cmdline.append(_get_executable(target, self.platform))
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010097 else:
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010098 if isolate_map[target].get('use_webcam', False):
99 cmdline += [
100 vpython_exe, '../../tools_webrtc/ensure_webcam_is_running.py'
101 ]
102 extra_files.append('../../tools_webrtc/ensure_webcam_is_running.py')
103
104 # is_linux uses use_ozone and x11 by default.
105 use_x11 = is_linux
106
107 xvfb = use_x11 and test_type == 'windowed_test_launcher'
108 if xvfb:
109 cmdline += [vpython_exe, '../../testing/xvfb.py']
110 extra_files.append('../../testing/xvfb.py')
111 else:
112 cmdline += [vpython_exe, '../../testing/test_env.py']
113
Jeremy Leconte145ff4c2022-03-28 11:32:20 +0200114 extra_files += [
115 '../../third_party/gtest-parallel/gtest-parallel',
116 '../../third_party/gtest-parallel/gtest_parallel.py',
117 '../../tools_webrtc/gtest-parallel-wrapper.py',
118 ]
119 sep = '\\' if self.platform == 'win32' else '/'
120 output_dir = '${ISOLATED_OUTDIR}' + sep + 'test_logs'
121 timeout = isolate_map[target].get('timeout', 900)
122 cmdline += [
123 '../../tools_webrtc/gtest-parallel-wrapper.py',
124 '--output_dir=%s' % output_dir,
125 '--gtest_color=no',
126 # We tell gtest-parallel to interrupt the test after 900
127 # seconds, so it can exit cleanly and report results,
128 # instead of being interrupted by swarming and not
129 # reporting anything.
130 '--timeout=%s' % timeout,
131 ]
132 if test_type == 'non_parallel_console_test_launcher':
133 # Still use the gtest-parallel-wrapper.py script since we
134 # need it to run tests on swarming, but don't execute tests
135 # in parallel.
136 cmdline.append('--workers=1')
Jeremy Lecontef22c78b2021-12-07 19:49:48 +0100137
138 asan = 'is_asan=true' in vals['gn_args']
139 lsan = 'is_lsan=true' in vals['gn_args']
140 msan = 'is_msan=true' in vals['gn_args']
141 tsan = 'is_tsan=true' in vals['gn_args']
142 sanitizer = asan or lsan or msan or tsan
Jeremy Leconte145ff4c2022-03-28 11:32:20 +0200143 if not sanitizer:
Jeremy Lecontef22c78b2021-12-07 19:49:48 +0100144 # Retry would hide most sanitizers detections.
145 cmdline.append('--retry_failed=3')
146
Jeremy Leconte145ff4c2022-03-28 11:32:20 +0200147 cmdline.append(_get_executable(target, self.platform))
Jeremy Lecontef22c78b2021-12-07 19:49:48 +0100148
149 cmdline.extend([
150 '--asan=%d' % asan,
151 '--lsan=%d' % lsan,
152 '--msan=%d' % msan,
153 '--tsan=%d' % tsan,
154 ])
155
156 cmdline += isolate_map[target].get('args', [])
157
158 return cmdline, extra_files
159
kjellandera013a022016-11-14 05:54:22 -0800160if __name__ == '__main__':
Jeremy Lecontef22c78b2021-12-07 19:49:48 +0100161 sys.exit(main(sys.argv[1:]))