in builder/main.py [0:0]
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--dry-run', action='store_true',
help="Don't run the build, just print the commands that would run")
parser.add_argument('-p', '--project', action='store',
type=str, help="Project to work on")
parser.add_argument('--config', type=str, default='RelWithDebInfo',
help='The native code configuration to build with')
parser.add_argument('--dump-config', action='store_true',
help="Print the config in use before running a build")
parser.add_argument('--spec', type=str)
parser.add_argument('--build-dir', type=str,
help='Directory to work in', default='.')
parser.add_argument('-b', '--branch', help='Branch to build from')
parser.add_argument('--compiler', type=str,
help="The compiler to use for this build")
parser.add_argument('--target', type=str, help="The target to cross-compile for (e.g. android-armv7, linux-x86, linux-aarch64)",
default='{}-{}'.format(current_os(), current_arch()),
choices=data.PLATFORMS.keys())
parser.add_argument('--variant', type=str, help="Build variant to use instead of default")
# hand parse command and spec from within the args given
command = None
spec = None
argv = sys.argv[1:]
# eat command and optionally spec
if argv and not argv[0].startswith('-'):
command = argv.pop(0)
if len(argv) >= 1 and not argv[0].startswith('-'):
spec = argv.pop(0)
if not command:
if '-h' in argv or '--help' in argv:
parser.print_help()
else:
print('No command provided, should be [build|inspect|<action-name>]')
sys.exit(1)
# parse the args we know, put the rest in args.args for others to parse
args, extra = parser.parse_known_args(argv)
args.args = extra
args.command = command
args.spec = args.spec if args.spec else spec
# Backwards compat for `builder run $action`
if args.command == 'run':
args.command = args.spec
args.spec = None
# pull out any k=v pairs
config_vars = []
for arg in args.args.copy():
m = re.match(r'(\+?)([A-Za-z_0-9]+)=(.+)', arg)
if m:
config_vars.append((m.group(1), m.group(2), m.group(3)))
args.args.remove(arg)
args.cli_config = {'variables': {}}
for plus, key, val in config_vars:
if key in data.KEYS:
val = coerce_arg(val)
if isinstance(data.KEYS[key], list):
# Treat list entries from CLI as '!' overrides, unless first entry starts with '+'
if key not in args.cli_config and not plus:
key = '!' + key
prev = args.cli_config.get(key, [])
args.cli_config[key] = prev + [val]
else:
# not a list
args.cli_config[key] = val
else:
# unknown keys are treated as variables
args.cli_config['variables'][key] = val
# normalize target
if args.target:
args.target = normalize_target(args.target)
if args.spec:
spec = BuildSpec(spec=args.spec, target=args.target)
if args.compiler or args.target:
compiler, version = ('default', 'default')
if args.compiler:
if '-' in args.compiler:
compiler, version = args.compiler.split('-')
else:
compiler = args.compiler
spec = str(spec) if spec else None
spec = BuildSpec(compiler=compiler,
compiler_version=version, target=args.target, spec=spec)
if not spec:
spec = default_spec()
return args, spec