diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-05-14 10:18:18 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-16 22:31:51 +0100 |
commit | 1bab18f26fe162cc2f577944f02ec3a2d4f01702 (patch) | |
tree | 9944dd608f797c5552e83d744e0bdcc22ba61139 /scripts | |
parent | 18114bb8a6074368922351b6cd229f21385d2901 (diff) | |
download | poky-1bab18f26fe162cc2f577944f02ec3a2d4f01702.tar.gz |
devtool: fix build env command execution error handling
If we execute an external command, we ought to prepare for the
possibility that it can fail and handle the failure appropriately. We
can especially expect this to happen when running bitbake in this
scenario. Ensure we return the appropriate exit code to the calling
process.
Fixes [YOCTO #7757].
(From OE-Core rev: 98a716d79bfc5434a5b42d3ca683eab3eea30a41)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/devtool/__init__.py | 9 | ||||
-rw-r--r-- | scripts/lib/devtool/standard.py | 22 |
2 files changed, 24 insertions, 7 deletions
diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py index 88665124d1..5a06c78b57 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py | |||
@@ -44,13 +44,14 @@ def exec_build_env_command(init_path, builddir, cmd, watch=False, **options): | |||
44 | if watch: | 44 | if watch: |
45 | if sys.stdout.isatty(): | 45 | if sys.stdout.isatty(): |
46 | # Fool bitbake into thinking it's outputting to a terminal (because it is, indirectly) | 46 | # Fool bitbake into thinking it's outputting to a terminal (because it is, indirectly) |
47 | cmd = 'script -q -c "%s" /dev/null' % cmd | 47 | cmd = 'script -e -q -c "%s" /dev/null' % cmd |
48 | return exec_watch('%s%s' % (init_prefix, cmd), **options) | 48 | return exec_watch('%s%s' % (init_prefix, cmd), **options) |
49 | else: | 49 | else: |
50 | return bb.process.run('%s%s' % (init_prefix, cmd), **options) | 50 | return bb.process.run('%s%s' % (init_prefix, cmd), **options) |
51 | 51 | ||
52 | def exec_watch(cmd, **options): | 52 | def exec_watch(cmd, **options): |
53 | """Run program with stdout shown on sys.stdout""" | 53 | """Run program with stdout shown on sys.stdout""" |
54 | import bb | ||
54 | if isinstance(cmd, basestring) and not "shell" in options: | 55 | if isinstance(cmd, basestring) and not "shell" in options: |
55 | options["shell"] = True | 56 | options["shell"] = True |
56 | 57 | ||
@@ -67,7 +68,11 @@ def exec_watch(cmd, **options): | |||
67 | buf += out | 68 | buf += out |
68 | elif out == '' and process.poll() != None: | 69 | elif out == '' and process.poll() != None: |
69 | break | 70 | break |
70 | return buf | 71 | |
72 | if process.returncode != 0: | ||
73 | raise bb.process.ExecutionError(cmd, process.returncode, buf, None) | ||
74 | |||
75 | return buf, None | ||
71 | 76 | ||
72 | def setup_tinfoil(): | 77 | def setup_tinfoil(): |
73 | """Initialize tinfoil api from bitbake""" | 78 | """Initialize tinfoil api from bitbake""" |
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py index 2f8b194c5f..61c0df9b11 100644 --- a/scripts/lib/devtool/standard.py +++ b/scripts/lib/devtool/standard.py | |||
@@ -97,8 +97,12 @@ def add(args, config, basepath, workspace): | |||
97 | source = srctree | 97 | source = srctree |
98 | if args.version: | 98 | if args.version: |
99 | extracmdopts += ' -V %s' % args.version | 99 | extracmdopts += ' -V %s' % args.version |
100 | stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts)) | 100 | try: |
101 | logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) | 101 | stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts)) |
102 | logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) | ||
103 | except bb.process.ExecutionError as e: | ||
104 | logger.error('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) | ||
105 | return 1 | ||
102 | 106 | ||
103 | _add_md5(config, args.recipename, recipefile) | 107 | _add_md5(config, args.recipename, recipefile) |
104 | 108 | ||
@@ -688,7 +692,7 @@ def status(args, config, basepath, workspace): | |||
688 | 692 | ||
689 | def reset(args, config, basepath, workspace): | 693 | def reset(args, config, basepath, workspace): |
690 | """Entry point for the devtool 'reset' subcommand""" | 694 | """Entry point for the devtool 'reset' subcommand""" |
691 | import bb.utils | 695 | import bb |
692 | if args.recipename: | 696 | if args.recipename: |
693 | if args.all: | 697 | if args.all: |
694 | logger.error("Recipe cannot be specified if -a/--all is used") | 698 | logger.error("Recipe cannot be specified if -a/--all is used") |
@@ -708,7 +712,11 @@ def reset(args, config, basepath, workspace): | |||
708 | for pn in recipes: | 712 | for pn in recipes: |
709 | if not args.no_clean: | 713 | if not args.no_clean: |
710 | logger.info('Cleaning sysroot for recipe %s...' % pn) | 714 | logger.info('Cleaning sysroot for recipe %s...' % pn) |
711 | exec_build_env_command(config.init_path, basepath, 'bitbake -c clean %s' % pn) | 715 | try: |
716 | exec_build_env_command(config.init_path, basepath, 'bitbake -c clean %s' % pn) | ||
717 | except bb.process.ExecutionError as e: | ||
718 | logger.error('Command \'%s\' failed, output:\n%s\nIf you wish, you may specify -n/--no-clean to skip running this command when resetting' % (e.command, e.stdout)) | ||
719 | return 1 | ||
712 | 720 | ||
713 | _check_preserve(config, pn) | 721 | _check_preserve(config, pn) |
714 | 722 | ||
@@ -735,7 +743,11 @@ def build(args, config, basepath, workspace): | |||
735 | logger.error("no recipe named %s in your workspace" % args.recipename) | 743 | logger.error("no recipe named %s in your workspace" % args.recipename) |
736 | return -1 | 744 | return -1 |
737 | build_task = config.get('Build', 'build_task', 'populate_sysroot') | 745 | build_task = config.get('Build', 'build_task', 'populate_sysroot') |
738 | exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) | 746 | try: |
747 | exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) | ||
748 | except bb.process.ExecutionError as e: | ||
749 | # We've already seen the output since watch=True, so just ensure we return something to the user | ||
750 | return e.exitcode | ||
739 | 751 | ||
740 | return 0 | 752 | return 0 |
741 | 753 | ||