Christoffer Jansson | 4e8a773 | 2022-02-08 09:01:12 +0100 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
| 2 | |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 3 | # 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 Prypin | b708e93 | 2018-03-18 17:34:20 +0100 | [diff] [blame] | 11 | """MB - the Meta-Build wrapper around GN. |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 12 | |
Oleh Prypin | b708e93 | 2018-03-18 17:34:20 +0100 | [diff] [blame] | 13 | MB is a wrapper script for GN that can be used to generate build files |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 14 | for sets of canned configurations and analyze them. |
| 15 | """ |
| 16 | |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 17 | import os |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 18 | import sys |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 19 | |
Jeremy Leconte | 81635f3 | 2022-03-29 12:32:14 +0200 | [diff] [blame^] | 20 | _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 21 | _SRC_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR)) |
| 22 | sys.path.insert(0, _SRC_DIR) |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 23 | |
Jeremy Leconte | 81635f3 | 2022-03-29 12:32:14 +0200 | [diff] [blame^] | 24 | from tools.mb import mb |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 25 | |
| 26 | |
Jeremy Leconte | 145ff4c | 2022-03-28 11:32:20 +0200 | [diff] [blame] | 27 | def _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 | |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 33 | def main(args): |
Jeremy Leconte | 81635f3 | 2022-03-29 12:32:14 +0200 | [diff] [blame^] | 34 | mbw = WebRTCMetaBuildWrapper() |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 35 | return mbw.Main(args) |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 36 | |
| 37 | |
Jeremy Leconte | 81635f3 | 2022-03-29 12:32:14 +0200 | [diff] [blame^] | 38 | class WebRTCMetaBuildWrapper(mb.MetaBuildWrapper): |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 39 | def __init__(self): |
Jeremy Leconte | 81635f3 | 2022-03-29 12:32:14 +0200 | [diff] [blame^] | 40 | 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 Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 48 | |
| 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 Leconte | d15f3e1 | 2022-02-18 10:16:32 +0100 | [diff] [blame] | 55 | is_ios = 'target_os="ios"' in vals['gn_args'] |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 56 | |
| 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 Bonadei | 5d9ae86 | 2022-01-27 20:18:16 +0100 | [diff] [blame] | 70 | '../../.vpython3', |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 71 | '../../testing/test_env.py', |
| 72 | ] |
Mirko Bonadei | 5d9ae86 | 2022-01-27 20:18:16 +0100 | [diff] [blame] | 73 | vpython_exe = 'vpython3' |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 74 | |
Jeremy Leconte | 145ff4c | 2022-03-28 11:32:20 +0200 | [diff] [blame] | 75 | if isolate_map[target].get('script'): |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 76 | 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 Leconte | d15f3e1 | 2022-02-18 10:16:32 +0100 | [diff] [blame] | 87 | 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 Leconte | 145ff4c | 2022-03-28 11:32:20 +0200 | [diff] [blame] | 93 | 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 Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 97 | else: |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 98 | 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 Leconte | 145ff4c | 2022-03-28 11:32:20 +0200 | [diff] [blame] | 114 | 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 Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 137 | |
| 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 Leconte | 145ff4c | 2022-03-28 11:32:20 +0200 | [diff] [blame] | 143 | if not sanitizer: |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 144 | # Retry would hide most sanitizers detections. |
| 145 | cmdline.append('--retry_failed=3') |
| 146 | |
Jeremy Leconte | 145ff4c | 2022-03-28 11:32:20 +0200 | [diff] [blame] | 147 | cmdline.append(_get_executable(target, self.platform)) |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 148 | |
| 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 | |
kjellander | a013a02 | 2016-11-14 05:54:22 -0800 | [diff] [blame] | 160 | if __name__ == '__main__': |
Jeremy Leconte | f22c78b | 2021-12-07 19:49:48 +0100 | [diff] [blame] | 161 | sys.exit(main(sys.argv[1:])) |