Commit c0bc087b authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

[tools] Port: Add recursive and quiet flags to mb lookup.

This ports: https://crrev.com/c/1576022

Bug: chromium:958870
Change-Id: Id187f5af80823fe58e38f1365baebabfc6587316
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1594556Reviewed-by: 's avatarTamer Tas <tmrts@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61266}
parent 077a1658
......@@ -167,6 +167,12 @@ class MetaBuildWrapper(object):
help='look up the command for a given config or '
'builder')
AddCommonOptions(subp)
subp.add_argument('--quiet', default=False, action='store_true',
help='Print out just the arguments, '
'do not emulate the output of the gen subcommand.')
subp.add_argument('--recursive', default=False, action='store_true',
help='Lookup arguments from imported files, '
'implies --quiet')
subp.set_defaults(func=self.CmdLookup)
subp = subps.add_parser(
......@@ -307,12 +313,15 @@ class MetaBuildWrapper(object):
def CmdLookup(self):
vals = self.Lookup()
cmd = self.GNCmd('gen', '_path_')
gn_args = self.GNArgs(vals)
self.Print('\nWriting """\\\n%s""" to _path_/args.gn.\n' % gn_args)
env = None
gn_args = self.GNArgs(vals, expand_imports=self.args.recursive)
if self.args.quiet or self.args.recursive:
self.Print(gn_args, end='')
else:
cmd = self.GNCmd('gen', '_path_')
self.Print('\nWriting """\\\n%s""" to _path_/args.gn.\n' % gn_args)
env = None
self.PrintCmd(cmd, env)
self.PrintCmd(cmd, env)
return 0
def CmdRun(self):
......@@ -852,7 +861,7 @@ class MetaBuildWrapper(object):
return [gn_path, subcommand, path] + list(args)
def GNArgs(self, vals):
def GNArgs(self, vals, expand_imports=False):
if vals['cros_passthrough']:
if not 'GN_ARGS' in os.environ:
raise MBErr('MB is expecting GN_ARGS to be in the environment')
......@@ -874,15 +883,24 @@ class MetaBuildWrapper(object):
if android_version_name:
gn_args += ' android_default_version_name="%s"' % android_version_name
args_gn_lines = []
parsed_gn_args = {}
args_file = vals.get('args_file', None)
if args_file:
if expand_imports:
content = self.ReadFile(self.ToAbsPath(args_file))
parsed_gn_args = gn_helpers.FromGNArgs(content)
else:
args_gn_lines.append('import("%s")' % args_file)
# 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
# the last instance of each arg is listed.
gn_args = gn_helpers.ToGNString(gn_helpers.FromGNArgs(gn_args))
parsed_gn_args.update(gn_helpers.FromGNArgs(gn_args))
args_gn_lines.append(gn_helpers.ToGNString(parsed_gn_args))
args_file = vals.get('args_file', None)
if args_file:
gn_args = ('import("%s")\n' % vals['args_file']) + gn_args
return gn_args
return '\n'.join(args_gn_lines)
def ToAbsPath(self, build_path, *comps):
return self.PathJoin(self.chromium_src_dir,
......
......@@ -549,7 +549,18 @@ class UnitTest(unittest.TestCase):
'//out/Default', 'base_unittests'], mbw=mbw, ret=0)
def test_lookup(self):
self.check(['lookup', '-c', 'debug_goma'], ret=0)
self.check(['lookup', '-c', 'debug_goma'], ret=0,
out=('\n'
'Writing """\\\n'
'is_debug = true\n'
'use_goma = true\n'
'""" to _path_/args.gn.\n\n'
'/fake_src/buildtools/linux64/gn gen _path_\n'))
def test_quiet_lookup(self):
self.check(['lookup', '-c', 'debug_goma', '--quiet'], ret=0,
out=('is_debug = true\n'
'use_goma = true\n'))
def test_lookup_goma_dir_expansion(self):
self.check(['lookup', '-c', 'rel_bot', '-g', '/foo'], ret=0,
......@@ -597,6 +608,19 @@ class UnitTest(unittest.TestCase):
'--phase', 'phase_2'], ret=0)
self.assertIn('phase = 2', mbw.out)
def test_recursive_lookup(self):
files = {
'/fake_src/build/args/fake.gn': (
'enable_doom_melon = true\n'
'enable_antidoom_banana = true\n'
)
}
self.check(['lookup', '-m', 'fake_master', '-b', 'fake_args_file',
'--recursive'], files=files, ret=0,
out=('enable_antidoom_banana = true\n'
'enable_doom_melon = true\n'
'use_goma = true\n'))
def test_validate(self):
mbw = self.fake_mbw()
self.check(['validate'], mbw=mbw, ret=0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment