* [PATCH flasher 1/4] Convert build script to argparse
@ 2013-06-14 19:52 Stephen Warren
[not found] ` <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2013-06-14 19:52 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Future patches will add some options. This will be easier with argparse.
Unfortunately, argparse doesn't support a default sub-command. Hence, the
shortcut "./build" for "./build build" is no longer supported. There are
ways to work around this by treating the command name as an optional
argument rather than sub-commands. However, this limits future
flexibility, since the fake sub-commands won't be able to accept sub
command- specific options.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
README-developer.txt | 2 +-
build | 51 ++++++++++++++++++++++++---------------------------
2 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/README-developer.txt b/README-developer.txt
index 89fcd2c..d59ec07 100644
--- a/README-developer.txt
+++ b/README-developer.txt
@@ -84,7 +84,7 @@ script assumes a value of arm-linux-gnueabi-.
cd to the scripts sub-directory (i.e. the directory containing this README),
and execute:
-./build
+./build build
Flashing Devices
================
diff --git a/build b/build
index 2a3bf7e..d14231f 100755
--- a/build
+++ b/build
@@ -20,6 +20,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+import argparse
import multiprocessing
import os
import shutil
@@ -172,32 +173,28 @@ def cmd_help():
for cmd in sorted(cmdmap.keys()):
print ' ', cmd
-def cmd_help_error_exit():
- print 'ERROR:',
- cmd_help()
- sys.exit(1)
-
-cmdmap = {
- '-h': cmd_help,
- '--help': cmd_help,
- 'help': cmd_help,
- 'help-error-exit': cmd_help_error_exit,
- 'build-uboots': cmd_build_uboots,
- 'build-bcts-imgs': cmd_build_bcts_imgs,
- 'build-configs': cmd_build_configs,
- 'build': cmd_build,
-}
+parser = argparse.ArgumentParser(description='Build U-Boot, BCT, and flash ' +
+ 'images for Tegra boards.')
+
+subparsers = parser.add_subparsers()
+
+parser_list_configs = subparsers.add_parser('build-uboots',
+ help='Build U-Boot binaries')
+parser_list_configs.set_defaults(func = cmd_build_uboots)
+
+parser_list_configs = subparsers.add_parser('build-bcts-imgs',
+ help='Build BCT and flash images')
+parser_list_configs.set_defaults(func = cmd_build_bcts_imgs)
+
+parser_list_configs = subparsers.add_parser('build-configs',
+ help='Build config files')
+parser_list_configs.set_defaults(func = cmd_build_configs)
+
+parser_list_configs = subparsers.add_parser('build',
+ help='Build everything')
+parser_list_configs.set_defaults(func = cmd_build)
if __name__ == '__main__':
- app = sys.argv.pop(0)
- if len(sys.argv) == 0:
- cmdname = 'build'
- elif len(sys.argv) == 1:
- cmdname = sys.argv.pop(0)
- else:
- cmdname = 'help-error-exit'
- if not cmdmap.has_key(cmdname):
- cmdname = 'help-error-exit'
- load_configs('configs')
- cmd = cmdmap[cmdname]
- cmd()
+ args = parser.parse_args()
+ load_configs(os.path.join(scripts_dir, 'configs'))
+ args.func()
--
1.8.1.5
^ permalink raw reply related [flat|nested] 5+ messages in thread[parent not found: <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>]
* [PATCH flasher 2/4] build: implement --socs, --boards options [not found] ` <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> @ 2013-06-14 19:52 ` Stephen Warren 2013-06-14 19:52 ` [PATCH flasher 3/4] build: restrict cmd_build_configs() to enabled objects Stephen Warren ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: Stephen Warren @ 2013-06-14 19:52 UTC (permalink / raw) To: swarren-3lzwWm7+Weoh9ZMKESR00Q Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> This will restrict the build process to a subset of SoCs or boards, which can be useful if you want to: ./build --boards seaboard build ./tegra-uboot-flasher exec seaboard ... in order to iterate testing on a single board at a time. Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> --- build | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/build b/build index d14231f..924ac88 100755 --- a/build +++ b/build @@ -102,6 +102,28 @@ def all_enabled_boardnames(): seen[boardname] = True yield boardname +def user_restrict_socs(enabled_socs): + enabled_socs = enabled_socs.split(',') + for socname in socs.keys(): + if not socname in enabled_socs: + socs[socname]['disabled'] = True + +def user_restrict_boards(enabled_boards): + enabled_boards = enabled_boards.split(',') + for boardname in boards.keys(): + if not boardname in enabled_boards: + boards[boardname]['disabled'] = True + +def restrict_boards(): + for board in boards.values(): + if socs[board['soc']].has_key('disabled'): + board['disabled'] = True + +def restrict_configs(): + for config in configs.values(): + if boards[config['board']].has_key('disabled'): + config['disabled'] = True + def dtb_filename(config): extra = configs[config]['dtbfn-extra'] boardname = configs[config]['board'] @@ -176,6 +198,11 @@ def cmd_help(): parser = argparse.ArgumentParser(description='Build U-Boot, BCT, and flash ' + 'images for Tegra boards.') +parser.add_argument('--socs', type=str, + help='Restrict the build to a (comma-separated) list of SoCs.') +parser.add_argument('--boards', type=str, + help='Restrict the build to a (comma-separated) list of boards.') + subparsers = parser.add_subparsers() parser_list_configs = subparsers.add_parser('build-uboots', @@ -197,4 +224,10 @@ parser_list_configs.set_defaults(func = cmd_build) if __name__ == '__main__': args = parser.parse_args() load_configs(os.path.join(scripts_dir, 'configs')) + if args.socs: + user_restrict_socs(args.socs) + if args.boards: + user_restrict_boards(args.boards) + restrict_boards() + restrict_configs() args.func() -- 1.8.1.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH flasher 3/4] build: restrict cmd_build_configs() to enabled objects [not found] ` <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> 2013-06-14 19:52 ` [PATCH flasher 2/4] build: implement --socs, --boards options Stephen Warren @ 2013-06-14 19:52 ` Stephen Warren 2013-06-14 19:52 ` [PATCH flasher 4/4] flasher: fix assignment of default data_dir Stephen Warren 2013-06-17 16:54 ` [PATCH flasher 1/4] Convert build script to argparse Stephen Warren 3 siblings, 0 replies; 5+ messages in thread From: Stephen Warren @ 2013-06-14 19:52 UTC (permalink / raw) To: swarren-3lzwWm7+Weoh9ZMKESR00Q Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> Only install enabled SoC/board/config files in _out/configs. This may be useful if you want to create a _out directory containing a limited set of binaries; this way, only the relevant limited set of config files are installed too. Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> --- build | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/build b/build index 924ac88..8f86d32 100755 --- a/build +++ b/build @@ -183,7 +183,26 @@ def cmd_build_bcts_imgs(): build_bct_img_one_board(boardname) def cmd_build_configs(): - run(scripts_dir, 'cp -rp configs ' + out_dir) + mkdir(os.path.join(out_dir, 'configs')) + boardnames = {} + for configname in all_enabled_confignames(): + fn = configname + '.config' + src = os.path.join(scripts_dir, 'configs', fn) + dst = os.path.join(out_dir, 'configs', fn) + cp(src, dst) + boardnames[configs[configname]['board']] = True + socnames = {} + for boardname in boardnames: + fn = boardname + '.board' + src = os.path.join(scripts_dir, 'configs', fn) + dst = os.path.join(out_dir, 'configs', fn) + cp(src, dst) + socnames[boards[boardname]['soc']] = True + for socname in socnames: + fn = socname + '.soc' + src = os.path.join(scripts_dir, 'configs', fn) + dst = os.path.join(out_dir, 'configs', fn) + cp(src, dst) def cmd_build(): cmd_build_uboots() -- 1.8.1.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH flasher 4/4] flasher: fix assignment of default data_dir [not found] ` <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> 2013-06-14 19:52 ` [PATCH flasher 2/4] build: implement --socs, --boards options Stephen Warren 2013-06-14 19:52 ` [PATCH flasher 3/4] build: restrict cmd_build_configs() to enabled objects Stephen Warren @ 2013-06-14 19:52 ` Stephen Warren 2013-06-17 16:54 ` [PATCH flasher 1/4] Convert build script to argparse Stephen Warren 3 siblings, 0 replies; 5+ messages in thread From: Stephen Warren @ 2013-06-14 19:52 UTC (permalink / raw) To: swarren-3lzwWm7+Weoh9ZMKESR00Q Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> The default value was being assigned to a global rather than a field in the argparser result. Reported-by: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> --- tegra-uboot-flasher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher index ac727a0..f1abe54 100755 --- a/tegra-uboot-flasher +++ b/tegra-uboot-flasher @@ -294,7 +294,7 @@ if not args.data_dir and not args.force_no_out_dir: if args.debug: print 'Detected build tree; using ' + out_data_dir + ' as data dir' args.data_dir = out_data_dir if not args.data_dir: - data_dir = '/usr/share/tegra_uboot_flasher' + args.data_dir = '/usr/share/tegra_uboot_flasher' load_configs(os.path.join(args.data_dir, 'configs')) -- 1.8.1.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH flasher 1/4] Convert build script to argparse [not found] ` <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> ` (2 preceding siblings ...) 2013-06-14 19:52 ` [PATCH flasher 4/4] flasher: fix assignment of default data_dir Stephen Warren @ 2013-06-17 16:54 ` Stephen Warren 3 siblings, 0 replies; 5+ messages in thread From: Stephen Warren @ 2013-06-17 16:54 UTC (permalink / raw) To: Stephen Warren; +Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren On 06/14/2013 01:52 PM, Stephen Warren wrote: > From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org> > > Future patches will add some options. This will be easier with argparse. > > Unfortunately, argparse doesn't support a default sub-command. Hence, the > shortcut "./build" for "./build build" is no longer supported. There are > ways to work around this by treating the command name as an optional > argument rather than sub-commands. However, this limits future > flexibility, since the fake sub-commands won't be able to accept sub > command- specific options. The series is applied. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-06-17 16:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-14 19:52 [PATCH flasher 1/4] Convert build script to argparse Stephen Warren
[not found] ` <1371239544-26165-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-06-14 19:52 ` [PATCH flasher 2/4] build: implement --socs, --boards options Stephen Warren
2013-06-14 19:52 ` [PATCH flasher 3/4] build: restrict cmd_build_configs() to enabled objects Stephen Warren
2013-06-14 19:52 ` [PATCH flasher 4/4] flasher: fix assignment of default data_dir Stephen Warren
2013-06-17 16:54 ` [PATCH flasher 1/4] Convert build script to argparse Stephen Warren
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox