diff options
author | David Pursell <dpursell@google.com> | 2016-04-22 14:23:16 -0700 |
---|---|---|
committer | David Pursell <dpursell@google.com> | 2016-04-25 10:17:15 -0700 |
commit | 6b0a22211dfbfe3eb7336314df5d3a3abfcf816a (patch) | |
tree | fb1ea71e587a43c9fd1969bd0c7407f9e140a0cb | |
parent | 427fe79f429b3651d97a6aacd7cb1d5e625a5123 (diff) | |
download | bdk-6b0a22211dfbfe3eb7336314df5d3a3abfcf816a.tar.gz |
bdk: remove legacy REMAINDER parsing.
There were a few old brunch/BDKv1 commands that still manually added a
REMAINDER arg rather than using the new parsing features. This CL moves
them over to the new parsing and removes manual '--' checking.
Bug: 28182026
Test: python lib/test_runner.py
Test: Checked several legacy commands to make sure arguments parsed
the same before and after this CL:
$ gdbclient.py
$ gdbclient.py -x foo bar
$ m -j81
$ mm -j81
$ brunch product build -- -j81
Change-Id: Idb5ad19fe502d16dbfc311dd5c5b0644c82ecbda
-rw-r--r-- | cli/lib/commands/product/build.py | 11 | ||||
-rw-r--r-- | cli/lib/commands/product/gdb.py | 14 | ||||
-rw-r--r-- | cli/lib/commands/product/provision.py | 7 | ||||
-rw-r--r-- | cli/lib/commands/product/tool.py | 6 | ||||
-rw-r--r-- | cli/lib/core/tool.py | 5 |
5 files changed, 15 insertions, 28 deletions
diff --git a/cli/lib/commands/product/build.py b/cli/lib/commands/product/build.py index aad3c3b..9151252 100644 --- a/cli/lib/commands/product/build.py +++ b/cli/lib/commands/product/build.py @@ -16,7 +16,7 @@ """Builds a product.""" -import argparse + import os from bsp import manifest @@ -26,9 +26,12 @@ from core import config from core import tool from core import util + class Build(clicommand.Command): """Build a product project from the current directory.""" + remainder_arg = ('make_args', 'Arguments to pass through to make.') + @staticmethod def Args(parser): parser.add_argument('-s', '--submodule', action='store_true', @@ -42,8 +45,6 @@ class Build(clicommand.Command): choices=['eng', 'userdebug', 'user'], help='Override the configured type of build to ' 'perform.') - parser.add_argument('make_args', nargs=argparse.REMAINDER, - help='Arguments to pass through to make.') def Run(self, args): sdk_path = util.GetBDKPath() @@ -74,10 +75,6 @@ class Build(clicommand.Command): if not args.buildtype: args.buildtype = 'userdebug' - # Don't pass along the first '--' since it was meant for argparse. - if args.make_args.count('--'): - args.make_args.remove('--') - envcmd = 'make' make = tool.BrunchToolWrapper(store, args.product_path, 'make') diff --git a/cli/lib/commands/product/gdb.py b/cli/lib/commands/product/gdb.py index 877749b..e7e226a 100644 --- a/cli/lib/commands/product/gdb.py +++ b/cli/lib/commands/product/gdb.py @@ -16,7 +16,7 @@ """Wraps gdbclient.py to work for out-of-tree builds.""" -import argparse + import os import shutil import signal @@ -27,16 +27,17 @@ from core import config from core import tool from core import util + class Gdb(clicommand.Command): """Run gdbclient.py for a given product.""" + remainder_arg = ('args', 'Arguments to pass through to gdbclient.py') + @staticmethod def Args(parser): parser.add_argument('-p', '--product_path', default=util.GetProductDir(), help='Path to the root of the product') - parser.add_argument('args', nargs=argparse.REMAINDER, - help='Arguments to pass through to gdbclient.py') def LinkToSymbols(self, out_dir, device): """Creates a symlink to the symbols directory. @@ -70,13 +71,6 @@ class Gdb(clicommand.Command): print constants.MSG_NO_PRODUCT_PATH return 1 - # We have to add '--' in product_templates to prevent argparse from - # trying to slurp up arguments meant for gdbclient.py, but we need to - # remove it now or else gdbclient.py will also treat it as a signal to - # clump the remaining args. - if args.args and args.args[0] == '--': - args.args.pop(0) - store = config.ProductFileStore(args.product_path) adb = tool.BrunchHostToolWrapper(store, args.product_path, 'adb') diff --git a/cli/lib/commands/product/provision.py b/cli/lib/commands/product/provision.py index c6a29e5..6da7f49 100644 --- a/cli/lib/commands/product/provision.py +++ b/cli/lib/commands/product/provision.py @@ -16,7 +16,7 @@ """Wraps provision-device.""" -import argparse + import os from bsp import manifest @@ -26,9 +26,12 @@ from core import config from core import tool from core import util + class Provision(clicommand.Command): """Run provision-device for a given product.""" + remainder_arg = ('args', 'Arguments to pass through to the tool') + @staticmethod def Args(parser): parser.add_argument('-p', '--product_path', @@ -38,8 +41,6 @@ class Provision(clicommand.Command): # Need to specifically handle -s argument parser.add_argument('-s', metavar='<specific device>', default=None, help='Provision a specific device') - parser.add_argument('args', nargs=argparse.REMAINDER, - help='Arguments to pass through to the tool') def Run(self, args): if args.product_path is None: diff --git a/cli/lib/commands/product/tool.py b/cli/lib/commands/product/tool.py index 58c12ff..64b51e8 100644 --- a/cli/lib/commands/product/tool.py +++ b/cli/lib/commands/product/tool.py @@ -17,7 +17,6 @@ """Wraps the per-product built host tool.""" -import argparse import pprint from cli import clicommand @@ -29,8 +28,11 @@ from core import util class Tool(clicommand.Command): """Run a host tool for a given product.""" + _TOOL_ENV_CMD = 'env' + remainder_arg = ('args', 'Arguments to pass through to the tool') + @staticmethod def Args(parser): parser.add_argument('tool', @@ -39,8 +41,6 @@ class Tool(clicommand.Command): parser.add_argument('-p', '--product_path', default=util.GetProductDir(), help='Path to the root of the product') - parser.add_argument('args', nargs=argparse.REMAINDER, - help='Arguments to pass through to the tool') def Run(self, args): if args.product_path is None: diff --git a/cli/lib/core/tool.py b/cli/lib/core/tool.py index ab4db82..575236c 100644 --- a/cli/lib/core/tool.py +++ b/cli/lib/core/tool.py @@ -52,7 +52,6 @@ class ToolWrapper(object): The advantages of this over using subprocess directly are: * Properly sets the execution working directory with set_cwd(). - * Strips '--' argument if given. * Restricts passthrough environment to a safe set of defaults. * Handles signal return codes properly. * Helper function to set common environment variables. @@ -149,10 +148,6 @@ class ToolWrapper(object): (out, err): The output to stdout and stderr of the called tool. Will both be None if piped=False. """ - # Remove -- passthrough indicator from arg_array. - if arg_array and arg_array[0] == '--': - arg_array = arg_array[1:] - # Make sure PWD is accurate on CWD change. if self._cwd: self.environment['PWD'] = os.path.abspath(self._cwd) |