Commit b6cee043 authored by Garrett Beaty's avatar Garrett Beaty Committed by Commit Bot

Add recursive and quiet flags to mb lookup.

Change-Id: Ica0e38196c37e00e2503b8674323b64ce6490554
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1576022
Commit-Queue: Garrett Beaty <gbeaty@chromium.org>
Auto-Submit: Garrett Beaty <gbeaty@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652900}
parent 45f012f3
...@@ -173,6 +173,12 @@ class MetaBuildWrapper(object): ...@@ -173,6 +173,12 @@ class MetaBuildWrapper(object):
help='look up the command for a given config or ' help='look up the command for a given config or '
'builder') 'builder')
AddCommonOptions(subp) 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.set_defaults(func=self.CmdLookup)
subp = subps.add_parser( subp = subps.add_parser(
...@@ -330,12 +336,15 @@ class MetaBuildWrapper(object): ...@@ -330,12 +336,15 @@ class MetaBuildWrapper(object):
def CmdLookup(self): def CmdLookup(self):
vals = self.Lookup() vals = self.Lookup()
cmd = self.GNCmd('gen', '_path_') gn_args = self.GNArgs(vals, expand_imports=self.args.recursive)
gn_args = self.GNArgs(vals) if self.args.quiet or self.args.recursive:
self.Print('\nWriting """\\\n%s""" to _path_/args.gn.\n' % gn_args) self.Print(gn_args, end='')
env = None 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 return 0
def CmdRun(self): def CmdRun(self):
...@@ -1087,7 +1096,7 @@ class MetaBuildWrapper(object): ...@@ -1087,7 +1096,7 @@ class MetaBuildWrapper(object):
return [gn_path, subcommand, path] + list(args) return [gn_path, subcommand, path] + list(args)
def GNArgs(self, vals): def GNArgs(self, vals, expand_imports=False):
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')
...@@ -1111,26 +1120,34 @@ class MetaBuildWrapper(object): ...@@ -1111,26 +1120,34 @@ class MetaBuildWrapper(object):
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 args_gn_lines = []
# of key-value pairs, and de-dup the keys if need be so that only parsed_gn_args = {}
# the last instance of each arg is listed.
gn_args = gn_helpers.ToGNString(gn_helpers.FromGNArgs(gn_args))
# If we're using the Simple Chrome SDK, add a comment at the top that # If we're using the Simple Chrome SDK, add a comment at the top that
# points to the doc. This must happen after the gn_helpers.ToGNString() # points to the doc. This must happen after the gn_helpers.ToGNString()
# call above since gn_helpers strips comments. # call above since gn_helpers strips comments.
if vals['cros_passthrough']: if vals['cros_passthrough']:
simplechrome_comment = [ args_gn_lines.extend([
'# These args are generated via the Simple Chrome SDK. See the link', '# These args are generated via the Simple Chrome SDK. See the link',
'# below for more details:', '# below for more details:',
'# https://chromium.googlesource.com/chromiumos/docs/+/master/simple_chrome_workflow.md', # pylint: disable=line-too-long '# https://chromium.googlesource.com/chromiumos/docs/+/master/simple_chrome_workflow.md', # pylint: disable=line-too-long
] ])
gn_args = '%s\n%s' % ('\n'.join(simplechrome_comment), gn_args)
args_file = vals.get('args_file', None) args_file = vals.get('args_file', None)
if args_file: if args_file:
gn_args = ('import("%s")\n' % vals['args_file']) + gn_args if expand_imports:
return gn_args 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.
parsed_gn_args.update(gn_helpers.FromGNArgs(gn_args))
args_gn_lines.append(gn_helpers.ToGNString(parsed_gn_args))
return '\n'.join(args_gn_lines)
def GetIsolateCommand(self, target, vals): def GetIsolateCommand(self, target, vals):
isolate_map = self.ReadIsolateMap() isolate_map = self.ReadIsolateMap()
......
...@@ -657,7 +657,18 @@ class UnitTest(unittest.TestCase): ...@@ -657,7 +657,18 @@ class UnitTest(unittest.TestCase):
'//out/Default', 'base_unittests'], mbw=mbw, ret=0) '//out/Default', 'base_unittests'], mbw=mbw, ret=0)
def test_lookup(self): 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): def test_lookup_goma_dir_expansion(self):
self.check(['lookup', '-c', 'rel_bot', '-g', '/foo'], ret=0, self.check(['lookup', '-c', 'rel_bot', '-g', '/foo'], ret=0,
...@@ -711,6 +722,19 @@ class UnitTest(unittest.TestCase): ...@@ -711,6 +722,19 @@ class UnitTest(unittest.TestCase):
'--phase', 'phase_2'], ret=0) '--phase', 'phase_2'], ret=0)
self.assertIn('phase = 2', mbw.out) 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): def test_validate(self):
mbw = self.fake_mbw() mbw = self.fake_mbw()
self.check(['validate'], mbw=mbw, ret=0) 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