Commit 6c51c7d3 authored by machenbach's avatar machenbach Committed by Commit bot

[gn] Add generic subcommands and provide list command

This prepares using mb as a library and not as a sub
process. It is used like that in the new list command that
shows available configurations.

Also added more robust checks of user inputs, better hints
and better docu.

BUG=chromium:625791
NOTRY=true

Review-Url: https://codereview.chromium.org/2300333002
Cr-Commit-Position: refs/heads/master@{#39136}
parent 17e9e2f4
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
'arm64.debug': 'default_debug_arm64', 'arm64.debug': 'default_debug_arm64',
'arm64.optdebug': 'default_optdebug_arm64', 'arm64.optdebug': 'default_optdebug_arm64',
'arm64.release': 'default_release_arm64', 'arm64.release': 'default_release_arm64',
'ia32.debug': 'default_debug_x86',
'ia32.optdebug': 'default_optdebug_x86',
'ia32.release': 'default_release_x86',
'x64.debug': 'default_debug_x64', 'x64.debug': 'default_debug_x64',
'x64.optdebug': 'default_optdebug_x64', 'x64.optdebug': 'default_optdebug_x64',
'x64.release': 'default_release_x64', 'x64.release': 'default_release_x64',
'x86.debug': 'default_debug_x86',
'x86.optdebug': 'default_optdebug_x86',
'x86.release': 'default_release_x86',
}, },
'client.dart.fyi': { 'client.dart.fyi': {
......
...@@ -6,31 +6,35 @@ ...@@ -6,31 +6,35 @@
"""Script to generate V8's gn arguments based on common developer defaults """Script to generate V8's gn arguments based on common developer defaults
or builder configurations. or builder configurations.
Goma is used by default if a goma folder is detected. The compiler proxy is Goma is used by default if detected. The compiler proxy is assumed to run.
assumed to run.
This script can be added to the PATH and be used on other v8 checkouts than This script can be added to the PATH and be used on other checkouts. It always
the including one. It always runs for the checkout that nests the CWD. runs for the checkout nesting the CWD.
Configurations of this script live in infra/mb/mb_config.pyl. Configurations of this script live in infra/mb/mb_config.pyl.
Available actions are: {gen,list}. Omitting the action defaults to "gen".
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Examples: Examples:
# Generate the x64.release config in out.gn/x64.release. # Generate the ia32.release config in out.gn/ia32.release.
v8gen.py x64.release v8gen.py ia32.release
# Generate into out.gn/foo and disable goma auto-detect. # Generate into out.gn/foo without goma auto-detect.
v8gen.py -b x64.release foo --no-goma v8gen.py gen -b ia32.release foo --no-goma
# Pass additional gn arguments after -- (don't use spaces within gn args). # Pass additional gn arguments after -- (don't use spaces within gn args).
v8gen.py x64.optdebug -- v8_enable_slow_dchecks=true v8gen.py ia32.optdebug -- v8_enable_slow_dchecks=true
# Generate gn arguments of 'V8 Linux64 - builder' from 'client.v8'. To switch # Generate gn arguments of 'V8 Linux64 - builder' from 'client.v8'. To switch
# off goma usage here, the args.gn file must be edited manually. # off goma usage here, the args.gn file must be edited manually.
v8gen.py -m client.v8 -b 'V8 Linux64 - builder' v8gen.py -m client.v8 -b 'V8 Linux64 - builder'
# Show available configurations.
v8gen.py list
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
""" """
...@@ -40,9 +44,15 @@ import re ...@@ -40,9 +44,15 @@ import re
import subprocess import subprocess
import sys import sys
CONFIG = os.path.join('infra', 'mb', 'mb_config.pyl')
GOMA_DEFAULT = os.path.join(os.path.expanduser("~"), 'goma') GOMA_DEFAULT = os.path.join(os.path.expanduser("~"), 'goma')
OUT_DIR = 'out.gn' OUT_DIR = 'out.gn'
TOOLS_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(TOOLS_PATH, 'mb'))
import mb
def _sanitize_nonalpha(text): def _sanitize_nonalpha(text):
return re.sub(r'[^a-zA-Z0-9.]', '_', text) return re.sub(r'[^a-zA-Z0-9.]', '_', text)
...@@ -57,30 +67,40 @@ class GenerateGnArgs(object): ...@@ -57,30 +67,40 @@ class GenerateGnArgs(object):
self._gn_args = args[index + 1:] self._gn_args = args[index + 1:]
def _parse_arguments(self, args): def _parse_arguments(self, args):
parser = argparse.ArgumentParser( self.parser = argparse.ArgumentParser(
description=__doc__, description=__doc__,
formatter_class=argparse.RawTextHelpFormatter, formatter_class=argparse.RawTextHelpFormatter,
) )
parser.add_argument(
def add_common_options(p):
p.add_argument(
'-m', '--master', default='developer_default',
help='config group or master from mb_config.pyl - default: '
'developer_default')
p.add_argument(
'-v', '--verbosity', action='count',
help='print wrapped commands (use -vv to print output of wrapped '
'commands)')
subps = self.parser.add_subparsers()
# Command: gen.
gen_cmd = subps.add_parser(
'gen', help='generate a new set of build files (default)')
gen_cmd.set_defaults(func=self.cmd_gen)
add_common_options(gen_cmd)
gen_cmd.add_argument(
'outdir', nargs='?', 'outdir', nargs='?',
help='optional gn output directory') help='optional gn output directory')
parser.add_argument( gen_cmd.add_argument(
'-b', '--builder', '-b', '--builder',
help='build configuration or builder name from mb_config.pyl, e.g. ' help='build configuration or builder name from mb_config.pyl, e.g. '
'x64.release') 'x64.release')
parser.add_argument( gen_cmd.add_argument(
'-m', '--master', default='developer_default',
help='config group or master from mb_config.pyl - default: '
'developer_default')
parser.add_argument(
'-p', '--pedantic', action='store_true', '-p', '--pedantic', action='store_true',
help='run gn over command-line gn args to catch errors early') help='run gn over command-line gn args to catch errors early')
parser.add_argument(
'-v', '--verbosity', action='count',
help='print wrapped commands (use -vv to print output of wrapped '
'commands)')
goma = parser.add_mutually_exclusive_group() goma = gen_cmd.add_mutually_exclusive_group()
goma.add_argument( goma.add_argument(
'-g' , '--goma', '-g' , '--goma',
action='store_true', default=None, dest='goma', action='store_true', default=None, dest='goma',
...@@ -91,27 +111,83 @@ class GenerateGnArgs(object): ...@@ -91,27 +111,83 @@ class GenerateGnArgs(object):
help='don\'t use goma auto detection - goma might still be used if ' help='don\'t use goma auto detection - goma might still be used if '
'specified as a gn arg') 'specified as a gn arg')
options = parser.parse_args(args) # Command: list.
list_cmd = subps.add_parser(
'list', help='list available configurations')
list_cmd.set_defaults(func=self.cmd_list)
add_common_options(list_cmd)
if not options.outdir and not options.builder: # Default to "gen" unless global help is requested.
parser.error('please specify either an output directory or ' if not args or args[0] not in subps.choices.keys() + ['-h', '--help']:
'a builder/config name (-b), e.g. x64.release') args = ['gen'] + args
if not options.outdir: return self.parser.parse_args(args)
def cmd_gen(self):
if not self._options.outdir and not self._options.builder:
self.parser.error('please specify either an output directory or '
'a builder/config name (-b), e.g. x64.release')
if not self._options.outdir:
# Derive output directory from builder name. # Derive output directory from builder name.
options.outdir = _sanitize_nonalpha(options.builder) self._options.outdir = _sanitize_nonalpha(self._options.builder)
else: else:
# Also, if this should work on windows, we might need to use \ where # Also, if this should work on windows, we might need to use \ where
# outdir is used as path, while using / if it's used in a gn context. # outdir is used as path, while using / if it's used in a gn context.
if options.outdir.startswith('/'): if self._options.outdir.startswith('/'):
parser.error( self.parser.error(
'only output directories relative to %s are supported' % OUT_DIR) 'only output directories relative to %s are supported' % OUT_DIR)
if not options.builder: if not self._options.builder:
# Derive builder from output directory. # Derive builder from output directory.
options.builder = options.outdir self._options.builder = self._options.outdir
# Check for builder/config in mb config.
if self._options.builder not in self._mbw.masters[self._options.master]:
print '%s does not exist in %s for %s' % (
self._options.builder, CONFIG, self._options.master)
return 1
# TODO(machenbach): Check if the requested configurations has switched to
# gn at all.
# The directories are separated with slashes in a gn context (platform
# independent).
gn_outdir = '/'.join([OUT_DIR, self._options.outdir])
# Call MB to generate the basic configuration.
self._call_cmd([
sys.executable,
'-u', os.path.join('tools', 'mb', 'mb.py'),
'gen',
'-f', CONFIG,
'-m', self._options.master,
'-b', self._options.builder,
gn_outdir,
])
# Handle extra gn arguments.
gn_args_path = os.path.join(OUT_DIR, self._options.outdir, 'args.gn')
# Append command-line args.
modified = self._append_gn_args(
'command-line', gn_args_path, '\n'.join(self._gn_args))
return options # Append goma args.
# TODO(machenbach): We currently can't remove existing goma args from the
# original config. E.g. to build like a bot that uses goma, but switch
# goma off.
modified |= self._append_gn_args(
'goma', gn_args_path, self._goma_args)
# Regenerate ninja files to check for errors in the additional gn args.
if modified and self._options.pedantic:
self._call_cmd(['gn', 'gen', gn_outdir])
return 0
def cmd_list(self):
print '\n'.join(sorted(self._mbw.masters[self._options.master]))
return 0
def verbose_print_1(self, text): def verbose_print_1(self, text):
if self._options.verbosity >= 1: if self._options.verbosity >= 1:
...@@ -199,39 +275,21 @@ class GenerateGnArgs(object): ...@@ -199,39 +275,21 @@ class GenerateGnArgs(object):
self.verbose_print_1('cd ' + workdir) self.verbose_print_1('cd ' + workdir)
os.chdir(workdir) os.chdir(workdir)
# The directories are separated with slashes in a gn context (platform # Initialize MB as a library.
# independent). self._mbw = mb.MetaBuildWrapper()
gn_outdir = '/'.join([OUT_DIR, self._options.outdir])
# Call MB to generate the basic configuration. # TODO(machenbach): Factor out common methods independent of mb arguments.
self._call_cmd([ self._mbw.ParseArgs(['lookup', '-f', CONFIG])
sys.executable, self._mbw.ReadConfigFile()
'-u', os.path.join('tools', 'mb', 'mb.py'),
'gen',
'-f', os.path.join('infra', 'mb', 'mb_config.pyl'),
'-m', self._options.master,
'-b', self._options.builder,
gn_outdir,
])
# Handle extra gn arguments. if not self._options.master in self._mbw.masters:
gn_args_path = os.path.join(OUT_DIR, self._options.outdir, 'args.gn') print '%s not found in %s\n' % (self._options.master, CONFIG)
print 'Choose one of:\n%s\n' % (
'\n'.join(sorted(self._mbw.masters.keys())))
return 1
# Append command-line args. return self._options.func()
modified = self._append_gn_args(
'command-line', gn_args_path, '\n'.join(self._gn_args))
# Append goma args.
# TODO(machenbach): We currently can't remove existing goma args from the
# original config. E.g. to build like a bot that uses goma, but switch
# goma off.
modified |= self._append_gn_args(
'goma', gn_args_path, self._goma_args)
# Regenerate ninja files to check for errors in the additional gn args.
if modified and self._options.pedantic:
self._call_cmd(['gn', 'gen', gn_outdir])
return 0
if __name__ == "__main__": if __name__ == "__main__":
gen = GenerateGnArgs(sys.argv[1:]) gen = GenerateGnArgs(sys.argv[1:])
......
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