blob: 915a5b83edeeb17ef8785c314c66afbfd6b184fb [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 Leconteac5cf782022-03-31 11:55:01 +020027def _GetExecutable(target, platform):
Jeremy Leconte145ff4c2022-03-28 11:32:20 +020028 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 Leconteac5cf782022-03-31 11:55:01 +020040 super().__init__()
Jeremy Leconte81635f32022-03-29 12:32:14 +020041 # 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')
Jeremy Lecontef5fd25c2022-04-11 15:09:20 +020047 self.default_isolate_map = os.path.join(_SRC_DIR, 'infra', 'specs',
48 'gn_isolate_map.pyl')
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010049
50 def GetSwarmingCommand(self, target, vals):
51 isolate_map = self.ReadIsolateMap()
52 test_type = isolate_map[target]['type']
53
54 is_android = 'target_os="android"' in vals['gn_args']
55 is_linux = self.platform.startswith('linux') and not is_android
Jeremy Leconted15f3e12022-02-18 10:16:32 +010056 is_ios = 'target_os="ios"' in vals['gn_args']
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010057
58 if test_type == 'nontest':
59 self.WriteFailureAndRaise('We should not be isolating %s.' % target,
60 output_path=None)
61 if test_type not in ('console_test_launcher', 'windowed_test_launcher',
62 'non_parallel_console_test_launcher', 'raw',
63 'additional_compile_target', 'junit_test', 'script'):
64 self.WriteFailureAndRaise('No command line for '
65 '%s found (test type %s).' %
66 (target, test_type),
67 output_path=None)
68
69 cmdline = []
70 extra_files = [
Mirko Bonadei5d9ae862022-01-27 20:18:16 +010071 '../../.vpython3',
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010072 '../../testing/test_env.py',
73 ]
Mirko Bonadei5d9ae862022-01-27 20:18:16 +010074 vpython_exe = 'vpython3'
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010075
Jeremy Leconte145ff4c2022-03-28 11:32:20 +020076 if isolate_map[target].get('script'):
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010077 cmdline += [
78 vpython_exe,
79 '../../' + self.ToSrcRelPath(isolate_map[target]['script'])
80 ]
81 elif is_android:
82 cmdline += [
83 vpython_exe, '../../build/android/test_wrapper/logdog_wrapper.py',
84 '--target', target, '--logdog-bin-cmd', '../../bin/logdog_butler',
85 '--logcat-output-file', '${ISOLATED_OUTDIR}/logcats',
86 '--store-tombstones'
87 ]
Jeremy Leconted15f3e12022-02-18 10:16:32 +010088 elif is_ios:
89 cmdline += [
90 vpython_exe, '../../tools_webrtc/flags_compatibility.py',
Jeremy Leconte424cc652022-04-12 12:03:28 +020091 'bin/run_%s' % target
Jeremy Leconted15f3e12022-02-18 10:16:32 +010092 ]
93 extra_files.append('../../tools_webrtc/flags_compatibility.py')
Jeremy Leconte145ff4c2022-03-28 11:32:20 +020094 elif test_type == 'raw':
95 cmdline += [vpython_exe, '../../tools_webrtc/flags_compatibility.py']
96 extra_files.append('../../tools_webrtc/flags_compatibility.py')
Jeremy Leconteac5cf782022-03-31 11:55:01 +020097 cmdline.append(_GetExecutable(target, self.platform))
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010098 else:
Jeremy Lecontef22c78b2021-12-07 19:49:48 +010099 if isolate_map[target].get('use_webcam', False):
100 cmdline += [
101 vpython_exe, '../../tools_webrtc/ensure_webcam_is_running.py'
102 ]
103 extra_files.append('../../tools_webrtc/ensure_webcam_is_running.py')
104
105 # is_linux uses use_ozone and x11 by default.
106 use_x11 = is_linux
107
108 xvfb = use_x11 and test_type == 'windowed_test_launcher'
109 if xvfb:
110 cmdline += [vpython_exe, '../../testing/xvfb.py']
111 extra_files.append('../../testing/xvfb.py')
112 else:
113 cmdline += [vpython_exe, '../../testing/test_env.py']
114
Jeremy Leconte145ff4c2022-03-28 11:32:20 +0200115 extra_files += [
116 '../../third_party/gtest-parallel/gtest-parallel',
117 '../../third_party/gtest-parallel/gtest_parallel.py',
118 '../../tools_webrtc/gtest-parallel-wrapper.py',
119 ]
Jeremy Lecontee2881612022-04-19 14:03:35 +0200120 output_dir = '${ISOLATED_OUTDIR}/test_logs'
Jeremy Leconte145ff4c2022-03-28 11:32:20 +0200121 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 Leconteac5cf782022-03-31 11:55:01 +0200147 cmdline.append(_GetExecutable(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:]))