Make tools_webrtc/mb inherit from tools/mb.

Bug: webrtc:13867
Change-Id: I33e998d260454d16120b09fedecf0c25d2654611
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256809
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#36347}
This commit is contained in:
Jeremy Leconte
2022-03-28 08:44:07 +02:00
committed by WebRTC LUCI CQ
parent 4aabf0ff5c
commit 7a324b977c
3 changed files with 85 additions and 1213 deletions

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,9 @@
# The builders should be sorted by the order they appear in the /builders # The builders should be sorted by the order they appear in the /builders
# page on the buildbots, *not* alphabetically. # page on the buildbots, *not* alphabetically.
'builder_groups': { 'builder_groups': {
# This is required because WebRTC mb.py overwrites the default configs
# and Chromium's mb.py checks the default config contains 'chromium'.
'chromium': {},
'client.webrtc': { 'client.webrtc': {
# iOS # iOS
'iOS64 Debug': 'ios_debug_bot_arm64', 'iOS64 Debug': 'ios_debug_bot_arm64',

View File

@ -19,16 +19,20 @@ import sys
import tempfile import tempfile
import unittest import unittest
import mb _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
_SRC_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR))
sys.path.insert(0, _SRC_DIR)
from tools_webrtc.mb import mb
class FakeMBW(mb.MetaBuildWrapper): class FakeMBW(mb.WebRTCMetaBuildWrapper):
def __init__(self, win32=False): def __init__(self, win32=False):
super(FakeMBW, self).__init__() super(FakeMBW, self).__init__()
# Override vars for test portability. # Override vars for test portability.
if win32: if win32:
self.src_dir = 'c:\\fake_src' self.chromium_src_dir = 'c:\\fake_src'
self.default_config = 'c:\\fake_src\\tools_webrtc\\mb\\mb_config.pyl' self.default_config = 'c:\\fake_src\\tools_webrtc\\mb\\mb_config.pyl'
self.default_isolate_map = ('c:\\fake_src\\testing\\buildbot\\' self.default_isolate_map = ('c:\\fake_src\\testing\\buildbot\\'
'gn_isolate_map.pyl') 'gn_isolate_map.pyl')
@ -37,7 +41,7 @@ class FakeMBW(mb.MetaBuildWrapper):
self.sep = '\\' self.sep = '\\'
self.cwd = 'c:\\fake_src\\out\\Default' self.cwd = 'c:\\fake_src\\out\\Default'
else: else:
self.src_dir = '/fake_src' self.chromium_src_dir = '/fake_src'
self.default_config = '/fake_src/tools_webrtc/mb/mb_config.pyl' self.default_config = '/fake_src/tools_webrtc/mb/mb_config.pyl'
self.default_isolate_map = '/fake_src/testing/buildbot/gn_isolate_map.pyl' self.default_isolate_map = '/fake_src/testing/buildbot/gn_isolate_map.pyl'
self.executable = '/usr/bin/vpython3' self.executable = '/usr/bin/vpython3'
@ -59,7 +63,15 @@ class FakeMBW(mb.MetaBuildWrapper):
def Exists(self, path): def Exists(self, path):
abs_path = self._AbsPath(path) abs_path = self._AbsPath(path)
return self.files.get(abs_path) is not None or abs_path in self.dirs return (self.files.get(abs_path) is not None or abs_path in self.dirs)
def ListDir(self, path):
dir_contents = []
for f in list(self.files.keys()) + list(self.dirs):
head, _ = os.path.split(f)
if head == path:
dir_contents.append(f)
return dir_contents
def MaybeMakeDirectory(self, path): def MaybeMakeDirectory(self, path):
abpath = self._AbsPath(path) abpath = self._AbsPath(path)
@ -69,7 +81,10 @@ class FakeMBW(mb.MetaBuildWrapper):
return self.sep.join(comps) return self.sep.join(comps)
def ReadFile(self, path): def ReadFile(self, path):
return self.files[self._AbsPath(path)] try:
return self.files[self._AbsPath(path)]
except KeyError:
raise IOError('%s not found' % path)
def WriteFile(self, path, contents, force_verbose=False): def WriteFile(self, path, contents, force_verbose=False):
if self.args.dryrun or self.args.verbose or force_verbose: if self.args.dryrun or self.args.verbose or force_verbose:
@ -77,7 +92,10 @@ class FakeMBW(mb.MetaBuildWrapper):
abpath = self._AbsPath(path) abpath = self._AbsPath(path)
self.files[abpath] = contents self.files[abpath] = contents
def Call(self, cmd, env=None, buffer_output=True): def Call(self, cmd, env=None, buffer_output=True, stdin=None):
del env
del buffer_output
del stdin
self.calls.append(cmd) self.calls.append(cmd)
if self.cmds: if self.cmds:
return self.cmds.pop(0) return self.cmds.pop(0)
@ -97,17 +115,20 @@ class FakeMBW(mb.MetaBuildWrapper):
self.dirs.add(tmp_dir) self.dirs.add(tmp_dir)
return tmp_dir return tmp_dir
def TempFile(self): def TempFile(self, mode='w'):
del mode
return FakeFile(self.files) return FakeFile(self.files)
def RemoveFile(self, path): def RemoveFile(self, path):
abpath = self._AbsPath(path) abpath = self._AbsPath(path)
self.files[abpath] = None self.files[abpath] = None
def RemoveDirectory(self, path): def RemoveDirectory(self, abs_path):
abpath = self._AbsPath(path) # Normalize the passed-in path to handle different working directories
self.rmdirs.append(abpath) # used during unit testing.
files_to_delete = [f for f in self.files if f.startswith(abpath)] abs_path = self._AbsPath(abs_path)
self.rmdirs.append(abs_path)
files_to_delete = [f for f in self.files if f.startswith(abs_path)]
for f in files_to_delete: for f in files_to_delete:
self.files[f] = None self.files[f] = None
@ -140,19 +161,30 @@ TEST_CONFIG = """\
'fake_group': { 'fake_group': {
'fake_builder': 'rel_bot', 'fake_builder': 'rel_bot',
'fake_debug_builder': 'debug_goma', 'fake_debug_builder': 'debug_goma',
'fake_args_bot': '//build/args/bots/fake_group/fake_args_bot.gn', 'fake_args_bot': 'fake_args_bot',
'fake_multi_phase': { 'phase_1': 'phase_1', 'phase_2': 'phase_2'}, 'fake_multi_phase': { 'phase_1': 'phase_1', 'phase_2': 'phase_2'},
'fake_android_bot': 'android_bot', 'fake_android_bot': 'android_bot',
'fake_args_file': 'args_file_goma',
'fake_ios_error': 'ios_error',
}, },
}, },
'configs': { 'configs': {
'args_file_goma': ['fake_args_bot', 'goma'],
'fake_args_bot': ['fake_args_bot'],
'rel_bot': ['rel', 'goma', 'fake_feature1'], 'rel_bot': ['rel', 'goma', 'fake_feature1'],
'debug_goma': ['debug', 'goma'], 'debug_goma': ['debug', 'goma'],
'phase_1': ['phase_1'], 'phase_1': ['rel', 'phase_1'],
'phase_2': ['phase_2'], 'phase_2': ['rel', 'phase_2'],
'android_bot': ['android'], 'android_bot': ['android'],
'ios_error': ['error'],
}, },
'mixins': { 'mixins': {
'error': {
'gn_args': 'error',
},
'fake_args_bot': {
'args_file': '//build/args/bots/fake_group/fake_args_bot.gn',
},
'fake_feature1': { 'fake_feature1': {
'gn_args': 'enable_doom_melon=true', 'gn_args': 'enable_doom_melon=true',
}, },
@ -166,13 +198,13 @@ TEST_CONFIG = """\
'gn_args': 'phase=2', 'gn_args': 'phase=2',
}, },
'rel': { 'rel': {
'gn_args': 'is_debug=false', 'gn_args': 'is_debug=false dcheck_always_on=false',
}, },
'debug': { 'debug': {
'gn_args': 'is_debug=true', 'gn_args': 'is_debug=true',
}, },
'android': { 'android': {
'gn_args': 'target_os="android"', 'gn_args': 'target_os="android" dcheck_always_on=false',
} }
}, },
} }
@ -193,10 +225,23 @@ class UnitTest(unittest.TestCase):
}''') }''')
mbw.files.setdefault( mbw.files.setdefault(
mbw.ToAbsPath('//build/args/bots/fake_group/fake_args_bot.gn'), mbw.ToAbsPath('//build/args/bots/fake_group/fake_args_bot.gn'),
'is_debug = false\n') 'is_debug = false\ndcheck_always_on=false\n')
mbw.files.setdefault(mbw.ToAbsPath('//tools/mb/rts_banned_suites.json'),
'{}')
if files: if files:
for path, contents in list(files.items()): for path, contents in list(files.items()):
mbw.files[path] = contents mbw.files[path] = contents
if path.endswith('.runtime_deps'):
def fake_call(cmd, env=None, buffer_output=True, stdin=None):
del cmd
del env
del buffer_output
del stdin
mbw.files[path] = contents
return 0, '', ''
mbw.Call = fake_call
return mbw return mbw
def check(self, def check(self,
@ -330,7 +375,7 @@ class UnitTest(unittest.TestCase):
'/fake_src/testing/buildbot/gn_isolate_map.pyl': '/fake_src/testing/buildbot/gn_isolate_map.pyl':
("{'base_unittests': {" ("{'base_unittests': {"
" 'label': '//base:base_unittests'," " 'label': '//base:base_unittests',"
" 'type': 'additional_compile_target'," " 'type': 'console_test_launcher',"
"}}\n"), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': '/fake_src/out/Default/base_unittests.runtime_deps':
("base_unittests\n"), ("base_unittests\n"),
@ -461,7 +506,7 @@ class UnitTest(unittest.TestCase):
" 'type': 'script'," " 'type': 'script',"
" 'script': '//base/base_unittests_script.py'," " 'script': '//base/base_unittests_script.py',"
"}}\n"), "}}\n"),
'/fake_src/out/Default/base_unittests.runtime_deps': '/fake_src/out/Default/base_unittests_script.runtime_deps':
("base_unittests\n" ("base_unittests\n"
"base_unittests_script.py\n"), "base_unittests_script.py\n"),
} }
@ -803,7 +848,7 @@ class UnitTest(unittest.TestCase):
ret=0) ret=0)
# test running isolate on an existing build_dir # test running isolate on an existing build_dir
files['/fake_src/out/Default/args.gn'] = 'is_debug = True\n' files['/fake_src/out/Default/args.gn'] = 'is_debug = true\n'
self.check(['isolate', '//out/Default', 'base_unittests'], self.check(['isolate', '//out/Default', 'base_unittests'],
files=files, files=files,
ret=0) ret=0)
@ -827,6 +872,7 @@ class UnitTest(unittest.TestCase):
ret=0) ret=0)
def test_run_swarmed(self): def test_run_swarmed(self):
# pylint: disable=attribute-defined-outside-init
files = { files = {
'/fake_src/testing/buildbot/gn_isolate_map.pyl': '/fake_src/testing/buildbot/gn_isolate_map.pyl':
("{'base_unittests': {" ("{'base_unittests': {"
@ -885,6 +931,7 @@ class UnitTest(unittest.TestCase):
ret=0, ret=0,
out=('\n' out=('\n'
'Writing """\\\n' 'Writing """\\\n'
'dcheck_always_on = false\n'
'enable_doom_melon = true\n' 'enable_doom_melon = true\n'
'goma_dir = "/foo"\n' 'goma_dir = "/foo"\n'
'is_debug = false\n' 'is_debug = false\n'