Fix mb.py presubmit.

Basically switch the indentation from 2 spaces to 4 spaces.

Bug: webrtc:13413
Change-Id: Iaafdec12715b2e9bfcb0743cf53b960fdf7f371a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238380
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#35381}
This commit is contained in:
Jeremy Leconte
2021-11-18 16:12:35 +01:00
committed by WebRTC LUCI CQ
parent 9a478b527d
commit 6d2be9251a

View File

@ -48,7 +48,8 @@ class MetaBuildWrapper(object):
def __init__(self): def __init__(self):
self.src_dir = SRC_DIR self.src_dir = SRC_DIR
self.default_config = os.path.join(SCRIPT_DIR, 'mb_config.pyl') self.default_config = os.path.join(SCRIPT_DIR, 'mb_config.pyl')
self.default_isolate_map = os.path.join(SCRIPT_DIR, 'gn_isolate_map.pyl') self.default_isolate_map = os.path.join(
SCRIPT_DIR, 'gn_isolate_map.pyl')
self.executable = sys.executable self.executable = sys.executable
self.platform = sys.platform self.platform = sys.platform
self.sep = os.sep self.sep = os.sep
@ -97,8 +98,8 @@ class MetaBuildWrapper(object):
help='path to isolate map file ' help='path to isolate map file '
'(default is %(default)s)') '(default is %(default)s)')
subp.add_argument('-r', '--realm', default='webrtc:try', subp.add_argument('-r', '--realm', default='webrtc:try',
help='optional LUCI realm to use (for ' help='optional LUCI realm to use (for example '
'example when triggering tasks on Swarming)') 'when triggering tasks on Swarming)')
subp.add_argument('-g', '--goma-dir', subp.add_argument('-g', '--goma-dir',
help='path to goma directory') help='path to goma directory')
subp.add_argument('--android-version-code', subp.add_argument('--android-version-code',
@ -106,8 +107,8 @@ class MetaBuildWrapper(object):
subp.add_argument('--android-version-name', subp.add_argument('--android-version-name',
help='Sets GN arg android_default_version_name') help='Sets GN arg android_default_version_name')
subp.add_argument('-n', '--dryrun', action='store_true', subp.add_argument('-n', '--dryrun', action='store_true',
help='Do a dry run (i.e., do nothing, just print ' help='Do a dry run (i.e., do nothing, just '
'the commands that will run)') 'print the commands that will run)')
subp.add_argument('-v', '--verbose', action='store_true', subp.add_argument('-v', '--verbose', action='store_true',
help='verbose logging') help='verbose logging')
@ -115,17 +116,18 @@ class MetaBuildWrapper(object):
subps = parser.add_subparsers() subps = parser.add_subparsers()
subp = subps.add_parser('analyze', subp = subps.add_parser('analyze',
help='analyze whether changes to a set of files ' help='analyze whether changes to a set of '
'will cause a set of binaries to be rebuilt.') 'files will cause a set of binaries '
'to be rebuilt.')
AddCommonOptions(subp) AddCommonOptions(subp)
subp.add_argument('path', nargs=1, subp.add_argument('path', nargs=1,
help='path build was generated into.') help='path build was generated into.')
subp.add_argument('input_path', nargs=1, subp.add_argument('input_path', nargs=1,
help='path to a file containing the input arguments ' help='path to a file containing the input '
'as a JSON object.') 'arguments as a JSON object.')
subp.add_argument('output_path', nargs=1, subp.add_argument('output_path', nargs=1,
help='path to a file containing the output arguments ' help='path to a file containing the output '
'as a JSON object.') 'arguments as a JSON object.')
subp.add_argument('--json-output', subp.add_argument('--json-output',
help='Write errors to json.output') help='Write errors to json.output')
subp.set_defaults(func=self.CmdAnalyze) subp.set_defaults(func=self.CmdAnalyze)
@ -163,12 +165,12 @@ class MetaBuildWrapper(object):
subp.set_defaults(func=self.CmdIsolate) subp.set_defaults(func=self.CmdIsolate)
subp = subps.add_parser('lookup', subp = subps.add_parser('lookup',
help='look up the command for a given config or ' help='look up the command for a given config '
'builder') 'or builder')
AddCommonOptions(subp) AddCommonOptions(subp)
subp.add_argument('--quiet', default=False, action='store_true', subp.add_argument('--quiet', default=False, action='store_true',
help='Print out just the arguments, ' help='Print out just the arguments, do '
'do not emulate the output of the gen subcommand.') 'not emulate the output of the gen subcommand.')
subp.set_defaults(func=self.CmdLookup) subp.set_defaults(func=self.CmdLookup)
subp = subps.add_parser( subp = subps.add_parser(
@ -179,8 +181,8 @@ class MetaBuildWrapper(object):
subp.description = ( subp.description = (
'Build, isolate, and run the given binary with the command line\n' 'Build, isolate, and run the given binary with the command line\n'
'listed in the isolate. You may pass extra arguments after the\n' 'listed in the isolate. You may pass extra arguments after the\n'
'target; use "--" if the extra arguments need to include switches.\n' 'target; use "--" if the extra arguments need to include switches.'
'\n' '\n\n'
'Examples:\n' 'Examples:\n'
'\n' '\n'
' % tools/mb/mb.py run -m chromium.linux -b "Linux Builder" \\\n' ' % tools/mb/mb.py run -m chromium.linux -b "Linux Builder" \\\n'
@ -205,15 +207,15 @@ class MetaBuildWrapper(object):
'//out/Default.')) '//out/Default.'))
subp.add_argument('-s', '--swarmed', action='store_true', subp.add_argument('-s', '--swarmed', action='store_true',
help='Run under swarming') help='Run under swarming')
subp.add_argument('-d', '--dimension', default=[], action='append', nargs=2, subp.add_argument('-d', '--dimension', default=[], action='append',
dest='dimensions', metavar='FOO bar', nargs=2, dest='dimensions', metavar='FOO bar',
help='dimension to filter on') help='dimension to filter on')
subp.add_argument('target', nargs=1, subp.add_argument('target', nargs=1,
help='ninja target to build and run') help='ninja target to build and run')
subp.add_argument('extra_args', nargs='*', subp.add_argument('extra_args', nargs='*',
help=('extra args to pass to the isolate to run. Use ' help=('extra args to pass to the isolate to run. '
'"--" as the first arg if you need to pass ' 'Use "--" as the first arg if you need to '
'switches')) 'pass switches'))
subp.set_defaults(func=self.CmdRun) subp.set_defaults(func=self.CmdRun)
subp = subps.add_parser('validate', subp = subps.add_parser('validate',
@ -375,7 +377,8 @@ class MetaBuildWrapper(object):
archive_hashes = json.loads(self.ReadFile(archive_json_path)) archive_hashes = json.loads(self.ReadFile(archive_json_path))
except Exception: except Exception:
self.Print( self.Print(
'Failed to read JSON file "%s"' % archive_json_path, file=sys.stderr) 'Failed to read JSON file "%s"' %
archive_json_path, file=sys.stderr)
return 1 return 1
try: try:
cas_digest = archive_hashes[target] cas_digest = archive_hashes[target]
@ -478,15 +481,15 @@ class MetaBuildWrapper(object):
for config, mixins in self.configs.items(): for config, mixins in self.configs.items():
for mixin in mixins: for mixin in mixins:
if not mixin in self.mixins: if not mixin in self.mixins:
errs.append('Unknown mixin "%s" referenced by config "%s".' % errs.append('Unknown mixin "%s" referenced by config "%s".'
(mixin, config)) % (mixin, config))
referenced_mixins.add(mixin) referenced_mixins.add(mixin)
for mixin in self.mixins: for mixin in self.mixins:
for sub_mixin in self.mixins[mixin].get('mixins', []): for sub_mixin in self.mixins[mixin].get('mixins', []):
if not sub_mixin in self.mixins: if not sub_mixin in self.mixins:
errs.append('Unknown mixin "%s" referenced by mixin "%s".' % errs.append('Unknown mixin "%s" referenced by mixin "%s".'
(sub_mixin, mixin)) % (sub_mixin, mixin))
referenced_mixins.add(sub_mixin) referenced_mixins.add(sub_mixin)
# Check that every mixin defined is actually referenced somewhere. # Check that every mixin defined is actually referenced somewhere.
@ -495,8 +498,8 @@ class MetaBuildWrapper(object):
errs.append('Unreferenced mixin "%s".' % mixin) errs.append('Unreferenced mixin "%s".' % mixin)
if errs: if errs:
raise MBErr(('mb config file %s has problems:' % self.args.config_file) + raise MBErr(('mb config file %s has problems:' %
'\n ' + '\n '.join(errs)) self.args.config_file) + '\n ' + '\n '.join(errs))
if print_ok: if print_ok:
self.Print('mb config file %s looks ok.' % self.args.config_file) self.Print('mb config file %s looks ok.' % self.args.config_file)
@ -508,17 +511,17 @@ class MetaBuildWrapper(object):
vals = self.DefaultVals() vals = self.DefaultVals()
if self.args.builder or self.args.builder_group or self.args.config: if self.args.builder or self.args.builder_group or self.args.config:
vals = self.Lookup() vals = self.Lookup()
# Re-run gn gen in order to ensure the config is consistent with the # Re-run gn gen in order to ensure the config is consistent with
# build dir. # the build dir.
self.RunGNGen(vals) self.RunGNGen(vals)
return vals return vals
toolchain_path = self.PathJoin(self.ToAbsPath(build_dir), toolchain_path = self.PathJoin(self.ToAbsPath(build_dir),
'toolchain.ninja') 'toolchain.ninja')
if not self.Exists(toolchain_path): if not self.Exists(toolchain_path):
self.Print('Must either specify a path to an existing GN build dir ' self.Print('Must either specify a path to an existing GN build '
'or pass in a -m/-b pair or a -c flag to specify the ' 'dir or pass in a -m/-b pair or a -c flag to specify '
'configuration') 'the configuration')
return {} return {}
vals['gn_args'] = self.GNArgsFromDir(build_dir) vals['gn_args'] = self.GNArgsFromDir(build_dir)
@ -580,8 +583,8 @@ class MetaBuildWrapper(object):
def ConfigFromArgs(self): def ConfigFromArgs(self):
if self.args.config: if self.args.config:
if self.args.builder_group or self.args.builder: if self.args.builder_group or self.args.builder:
raise MBErr('Can not specific both -c/--config and -m/--builder-group ' raise MBErr('Can not specific both -c/--config and '
'or -b/--builder') '-m/--builder-group or -b/--builder')
return self.args.config return self.args.config
@ -593,12 +596,16 @@ class MetaBuildWrapper(object):
raise MBErr('Master name "%s" not found in "%s"' % raise MBErr('Master name "%s" not found in "%s"' %
(self.args.builder_group, self.args.config_file)) (self.args.builder_group, self.args.config_file))
if not self.args.builder in self.builder_groups[self.args.builder_group]: if (not self.args.builder in
self.builder_groups[self.args.builder_group]):
raise MBErr( raise MBErr(
'Builder name "%s" not found under builder_groups[%s] in "%s"' % 'Builder name "%s" not found under builder_groups[%s] in "%s"'
(self.args.builder, self.args.builder_group, self.args.config_file)) % (self.args.builder, self.args.builder_group,
self.args.config_file))
config = self.builder_groups[self.args.builder_group][self.args.builder] config = (
self.builder_groups[self.args.builder_group][self.args.builder]
)
if isinstance(config, dict): if isinstance(config, dict):
if self.args.phase is None: if self.args.phase is None:
raise MBErr('Must specify a build --phase for %s on %s' % raise MBErr('Must specify a build --phase for %s on %s' %
@ -606,7 +613,8 @@ class MetaBuildWrapper(object):
phase = str(self.args.phase) phase = str(self.args.phase)
if phase not in config: if phase not in config:
raise MBErr('Phase %s doesn\'t exist for %s on %s' % raise MBErr('Phase %s doesn\'t exist for %s on %s' %
(phase, self.args.builder, self.args.builder_group)) (phase, self.args.builder,
self.args.builder_group))
return config[phase] return config[phase]
if self.args.phase is not None: if self.args.phase is not None:
@ -666,8 +674,8 @@ class MetaBuildWrapper(object):
if getattr(self.args, 'swarming_targets_file', None): if getattr(self.args, 'swarming_targets_file', None):
# We need GN to generate the list of runtime dependencies for # We need GN to generate the list of runtime dependencies for
# the compile targets listed (one per line) in the file so # the compile targets listed (one per line) in the file so
# we can run them via swarming. We use gn_isolate_map.pyl to convert # we can run them via swarming. We use gn_isolate_map.pyl to
# the compile targets to the matching GN labels. # convert the compile targets to the matching GN labels.
path = self.args.swarming_targets_file path = self.args.swarming_targets_file
if not self.Exists(path): if not self.Exists(path):
self.WriteFailureAndRaise('"%s" does not exist' % path, self.WriteFailureAndRaise('"%s" does not exist' % path,
@ -676,7 +684,8 @@ class MetaBuildWrapper(object):
swarming_targets = set(contents.splitlines()) swarming_targets = set(contents.splitlines())
isolate_map = self.ReadIsolateMap() isolate_map = self.ReadIsolateMap()
err, labels = self.MapTargetsToLabels(isolate_map, swarming_targets) err, labels = self.MapTargetsToLabels(
isolate_map, swarming_targets)
if err: if err:
raise MBErr(err) raise MBErr(err)
@ -690,16 +699,18 @@ class MetaBuildWrapper(object):
# write errors to json.output # write errors to json.output
self.WriteJSON({'output': output}, self.args.json_output) self.WriteJSON({'output': output}, self.args.json_output)
# If `gn gen` failed, we should exit early rather than trying to # If `gn gen` failed, we should exit early rather than trying to
# generate isolates. Run() will have already logged any error output. # generate isolates. Run() will have already logged any error
# output.
self.Print('GN gen failed: %d' % ret) self.Print('GN gen failed: %d' % ret)
return ret return ret
android = 'target_os="android"' in vals['gn_args'] android = 'target_os="android"' in vals['gn_args']
for target in swarming_targets: for target in swarming_targets:
if android: if android:
# Android targets may be either android_apk or executable. The former # Android targets may be either android_apk or executable. The
# will result in runtime_deps associated with the stamp file, while the # former will result in runtime_deps associated with the stamp
# latter will result in runtime_deps associated with the executable. # file, while the latter will result in runtime_deps associated
# with the executable.
label = isolate_map[target]['label'] label = isolate_map[target]['label']
runtime_deps_targets = [ runtime_deps_targets = [
target + '.runtime_deps', target + '.runtime_deps',
@ -820,7 +831,8 @@ class MetaBuildWrapper(object):
if isolate_map[stripped_target]['type'] == 'unknown': if isolate_map[stripped_target]['type'] == 'unknown':
err += ('test target "%s" type is unknown\n' % target) err += ('test target "%s" type is unknown\n' % target)
else: else:
labels.append(isolate_map[stripped_target]['label'] + suffix) labels.append(
isolate_map[stripped_target]['label'] + suffix)
else: else:
err += ('target "%s" not found in ' err += ('target "%s" not found in '
'//testing/buildbot/gn_isolate_map.pyl\n' % target) '//testing/buildbot/gn_isolate_map.pyl\n' % target)
@ -838,15 +850,14 @@ class MetaBuildWrapper(object):
gn_path = self.PathJoin(self.src_dir, 'buildtools', subdir, exe) gn_path = self.PathJoin(self.src_dir, 'buildtools', subdir, exe)
return [gn_path, subcommand, path] + list(args) return [gn_path, subcommand, path] + list(args)
def GNArgs(self, vals): def GNArgs(self, vals):
if vals['cros_passthrough']: if vals['cros_passthrough']:
if not 'GN_ARGS' in os.environ: if not 'GN_ARGS' in os.environ:
raise MBErr('MB is expecting GN_ARGS to be in the environment') raise MBErr('MB is expecting GN_ARGS to be in the environment')
gn_args = os.environ['GN_ARGS'] gn_args = os.environ['GN_ARGS']
if not re.search('target_os.*=.*"chromeos"', gn_args): if not re.search('target_os.*=.*"chromeos"', gn_args):
raise MBErr('GN_ARGS is missing target_os = "chromeos": (GN_ARGS=%s)' % raise MBErr('GN_ARGS is missing target_os = "chromeos": '
gn_args) '(GN_ARGS=%s)' % gn_args)
else: else:
gn_args = vals['gn_args'] gn_args = vals['gn_args']
@ -855,11 +866,13 @@ class MetaBuildWrapper(object):
android_version_code = self.args.android_version_code android_version_code = self.args.android_version_code
if android_version_code: if android_version_code:
gn_args += ' android_default_version_code="%s"' % android_version_code gn_args += (' android_default_version_code="%s"' %
android_version_code)
android_version_name = self.args.android_version_name android_version_name = self.args.android_version_name
if android_version_name: if android_version_name:
gn_args += ' android_default_version_name="%s"' % android_version_name gn_args += (' android_default_version_name="%s"' %
android_version_name)
# Canonicalize the arg string into a sorted, newline-separated list # Canonicalize the arg string into a sorted, newline-separated list
# of key-value pairs, and de-dup the keys if need be so that only # of key-value pairs, and de-dup the keys if need be so that only
@ -879,12 +892,14 @@ class MetaBuildWrapper(object):
is_linux = self.platform.startswith('linux') and not is_android is_linux = self.platform.startswith('linux') and not is_android
if test_type == 'nontest': if test_type == 'nontest':
self.WriteFailureAndRaise('We should not be isolating %s.' % target, self.WriteFailureAndRaise('We should not be isolating %s.' %
output_path=None) target, output_path=None)
if test_type not in ('console_test_launcher', 'windowed_test_launcher', if test_type not in ('console_test_launcher', 'windowed_test_launcher',
'non_parallel_console_test_launcher', 'raw', 'non_parallel_console_test_launcher', 'raw',
'additional_compile_target', 'junit_test', 'script'): 'additional_compile_target', 'junit_test',
self.WriteFailureAndRaise('No command line for %s found (test type %s).' 'script'):
self.WriteFailureAndRaise('No command line for '
'%s found (test type %s).'
% (target, test_type), output_path=None) % (target, test_type), output_path=None)
cmdline = [] cmdline = []
@ -895,7 +910,8 @@ class MetaBuildWrapper(object):
must_retry = False must_retry = False
if test_type == 'script': if test_type == 'script':
cmdline += ['../../' + self.ToSrcRelPath(isolate_map[target]['script'])] cmdline += ['../../' +
self.ToSrcRelPath(isolate_map[target]['script'])]
elif is_android: elif is_android:
cmdline += ['../../build/android/test_wrapper/logdog_wrapper.py', cmdline += ['../../build/android/test_wrapper/logdog_wrapper.py',
'--target', target, '--target', target,
@ -908,8 +924,10 @@ class MetaBuildWrapper(object):
extra_files.append('../../tools_webrtc/flags_compatibility.py') extra_files.append('../../tools_webrtc/flags_compatibility.py')
if isolate_map[target].get('use_webcam', False): if isolate_map[target].get('use_webcam', False):
cmdline.append('../../tools_webrtc/ensure_webcam_is_running.py') cmdline.append(
extra_files.append('../../tools_webrtc/ensure_webcam_is_running.py') '../../tools_webrtc/ensure_webcam_is_running.py')
extra_files.append(
'../../tools_webrtc/ensure_webcam_is_running.py')
# is_linux uses use_ozone and x11 by default. # is_linux uses use_ozone and x11 by default.
use_x11 = is_linux use_x11 = is_linux
@ -934,14 +952,16 @@ class MetaBuildWrapper(object):
'../../tools_webrtc/gtest-parallel-wrapper.py', '../../tools_webrtc/gtest-parallel-wrapper.py',
'--output_dir=%s' % output_dir, '--output_dir=%s' % output_dir,
'--gtest_color=no', '--gtest_color=no',
# We tell gtest-parallel to interrupt the test after 900 seconds, # We tell gtest-parallel to interrupt the test after 900
# so it can exit cleanly and report results, instead of being # seconds, so it can exit cleanly and report results,
# interrupted by swarming and not reporting anything. # instead of being interrupted by swarming and not
# reporting anything.
'--timeout=%s' % timeout, '--timeout=%s' % timeout,
] ]
if test_type == 'non_parallel_console_test_launcher': if test_type == 'non_parallel_console_test_launcher':
# Still use the gtest-parallel-wrapper.py script since we need it to # Still use the gtest-parallel-wrapper.py script since we
# run tests on swarming, but don't execute tests in parallel. # need it to run tests on swarming, but don't execute tests
# in parallel.
cmdline.append('--workers=1') cmdline.append('--workers=1')
must_retry = True must_retry = True
@ -1003,12 +1023,12 @@ class MetaBuildWrapper(object):
self.PrintJSON(inp) self.PrintJSON(inp)
self.Print() self.Print()
# This shouldn't normally happen, but could due to unusual race
# This shouldn't normally happen, but could due to unusual race conditions, # conditions, like a try job that gets scheduled before a patch
# like a try job that gets scheduled before a patch lands but runs after # lands but runs after the patch has landed.
# the patch has landed.
if not inp['files']: if not inp['files']:
self.Print('Warning: No files modified in patch, bailing out early.') self.Print(
'Warning: No files modified in patch, bailing out early.')
self.WriteJSON({ self.WriteJSON({
'status': 'No dependency', 'status': 'No dependency',
'compile_targets': [], 'compile_targets': [],
@ -1017,7 +1037,8 @@ class MetaBuildWrapper(object):
return 0 return 0
gn_inp = {} gn_inp = {}
gn_inp['files'] = ['//' + f for f in inp['files'] if not f.startswith('//')] gn_inp['files'] = ['//' + f for f in inp['files']
if not f.startswith('//')]
isolate_map = self.ReadIsolateMap() isolate_map = self.ReadIsolateMap()
err, gn_inp['additional_compile_targets'] = self.MapTargetsToLabels( err, gn_inp['additional_compile_targets'] = self.MapTargetsToLabels(
@ -1035,7 +1056,8 @@ class MetaBuildWrapper(object):
try: try:
self.WriteJSON(gn_inp, gn_input_path) self.WriteJSON(gn_inp, gn_input_path)
cmd = self.GNCmd('analyze', build_path, gn_input_path, gn_output_path) cmd = self.GNCmd('analyze', build_path,
gn_input_path, gn_output_path)
ret, output, _ = self.Run(cmd, force_verbose=True) ret, output, _ = self.Run(cmd, force_verbose=True)
if ret: if ret:
if self.args.json_output: if self.args.json_output:
@ -1047,8 +1069,8 @@ class MetaBuildWrapper(object):
try: try:
gn_outp = json.loads(gn_outp_str) gn_outp = json.loads(gn_outp_str)
except Exception as e: except Exception as e:
self.Print("Failed to parse the JSON string GN returned: %s\n%s" self.Print("Failed to parse the JSON string GN "
% (repr(gn_outp_str), str(e))) "returned: %s\n%s" % (repr(gn_outp_str), str(e)))
raise raise
outp = {} outp = {}
@ -1063,10 +1085,14 @@ class MetaBuildWrapper(object):
outp['compile_targets'] = ['all'] outp['compile_targets'] = ['all']
else: else:
outp['compile_targets'] = [ outp['compile_targets'] = [
label.replace('//', '') for label in gn_outp['compile_targets']] label.replace('//', '')
for label in gn_outp['compile_targets']
]
if 'test_targets' in gn_outp: if 'test_targets' in gn_outp:
outp['test_targets'] = [ outp['test_targets'] = [
labels_to_targets[label] for label in gn_outp['test_targets']] labels_to_targets[label]
for label in gn_outp['test_targets']
]
if self.args.verbose: if self.args.verbose:
self.Print() self.Print()
@ -1088,18 +1114,19 @@ class MetaBuildWrapper(object):
path = self.args.input_path[0] path = self.args.input_path[0]
output_path = self.args.output_path[0] output_path = self.args.output_path[0]
if not self.Exists(path): if not self.Exists(path):
self.WriteFailureAndRaise('"%s" does not exist' % path, output_path) self.WriteFailureAndRaise(
'"%s" does not exist' % path, output_path)
try: try:
inp = json.loads(self.ReadFile(path)) inp = json.loads(self.ReadFile(path))
except Exception as e: except Exception as e:
self.WriteFailureAndRaise('Failed to read JSON input from "%s": %s' % self.WriteFailureAndRaise('Failed to read JSON input from "%s": %s'
(path, e), output_path) % (path, e), output_path)
for k in required_keys: for k in required_keys:
if not k in inp: if not k in inp:
self.WriteFailureAndRaise('input file is missing a "%s" key' % k, self.WriteFailureAndRaise('input file is missing a "%s" key' %
output_path) k, output_path)
return inp return inp
@ -1110,7 +1137,8 @@ class MetaBuildWrapper(object):
def WriteJSON(self, obj, path, force_verbose=False): def WriteJSON(self, obj, path, force_verbose=False):
try: try:
self.WriteFile(path, json.dumps(obj, indent=2, sort_keys=True) + '\n', self.WriteFile(path,
json.dumps(obj, indent=2, sort_keys=True) + '\n',
force_verbose=force_verbose) force_verbose=force_verbose)
except Exception as e: except Exception as e:
raise MBErr('Error %s writing to the output path "%s"' % raise MBErr('Error %s writing to the output path "%s"' %
@ -1145,7 +1173,8 @@ class MetaBuildWrapper(object):
if self.args.jobs: if self.args.jobs:
ninja_cmd.extend(['-j', '%d' % self.args.jobs]) ninja_cmd.extend(['-j', '%d' % self.args.jobs])
ninja_cmd.append(target) ninja_cmd.append(target)
ret, _, _ = self.Run(ninja_cmd, force_verbose=False, buffer_output=False) ret, _, _ = self.Run(
ninja_cmd, force_verbose=False, buffer_output=False)
return ret return ret
def Run(self, cmd, env=None, force_verbose=True, buffer_output=True): def Run(self, cmd, env=None, force_verbose=True, buffer_output=True):
@ -1168,7 +1197,8 @@ class MetaBuildWrapper(object):
def Call(self, cmd, env=None, buffer_output=True): def Call(self, cmd, env=None, buffer_output=True):
if buffer_output: if buffer_output:
p = subprocess.Popen(cmd, shell=False, cwd=self.src_dir, p = subprocess.Popen(cmd, shell=False, cwd=self.src_dir,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env) env=env)
out, err = p.communicate() out, err = p.communicate()
else: else:
@ -1227,9 +1257,9 @@ class MetaBuildWrapper(object):
if self.platform == 'win32': if self.platform == 'win32':
# In other places in chromium, we often have to retry this command # In other places in chromium, we often have to retry this command
# because we're worried about other processes still holding on to # because we're worried about other processes still holding on to
# file handles, but when MB is invoked, it will be early enough in the # file handles, but when MB is invoked, it will be early enough in
# build that their should be no other processes to interfere. We # the build that their should be no other processes to interfere.
# can change this if need be. # We can change this if need be.
self.Run(['cmd.exe', '/c', 'rmdir', '/q', '/s', abs_path]) self.Run(['cmd.exe', '/c', 'rmdir', '/q', '/s', abs_path])
else: else:
shutil.rmtree(abs_path, ignore_errors=True) shutil.rmtree(abs_path, ignore_errors=True)