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-06-28 09:44:15 +0100 |
commit | b317d79fb7a058582f587e24463a1b67f38aec37 (patch) | |
tree | 041e4abb9457434f56df91f4e58a19eb80a158e2 /scripts/lib | |
parent | 8c9551a7a32036ac1f0bfba0b3f3dc24d006483e (diff) | |
download | poky-b317d79fb7a058582f587e24463a1b67f38aec37.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 master rev: 98a716d79bfc5434a5b42d3ca683eab3eea30a41)
(From OE-Core rev: 2791fe9236f7173e6b998cf9b40fe238566ed8ee)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-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 78ae0aabc8..4c0d5397dc 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py | |||
@@ -43,12 +43,13 @@ def exec_build_env_command(init_path, builddir, cmd, watch=False, **options): | |||
43 | if watch: | 43 | if watch: |
44 | if sys.stdout.isatty(): | 44 | if sys.stdout.isatty(): |
45 | # Fool bitbake into thinking it's outputting to a terminal (because it is, indirectly) | 45 | # Fool bitbake into thinking it's outputting to a terminal (because it is, indirectly) |
46 | cmd = 'script -q -c "%s" /dev/null' % cmd | 46 | cmd = 'script -e -q -c "%s" /dev/null' % cmd |
47 | return exec_watch('%s%s' % (init_prefix, cmd), **options) | 47 | return exec_watch('%s%s' % (init_prefix, cmd), **options) |
48 | else: | 48 | else: |
49 | return bb.process.run('%s%s' % (init_prefix, cmd), **options) | 49 | return bb.process.run('%s%s' % (init_prefix, cmd), **options) |
50 | 50 | ||
51 | def exec_watch(cmd, **options): | 51 | def exec_watch(cmd, **options): |
52 | import bb | ||
52 | if isinstance(cmd, basestring) and not "shell" in options: | 53 | if isinstance(cmd, basestring) and not "shell" in options: |
53 | options["shell"] = True | 54 | options["shell"] = True |
54 | 55 | ||
@@ -65,7 +66,11 @@ def exec_watch(cmd, **options): | |||
65 | buf += out | 66 | buf += out |
66 | elif out == '' and process.poll() != None: | 67 | elif out == '' and process.poll() != None: |
67 | break | 68 | break |
68 | return buf | 69 | |
70 | if process.returncode != 0: | ||
71 | raise bb.process.ExecutionError(cmd, process.returncode, buf, None) | ||
72 | |||
73 | return buf, None | ||
69 | 74 | ||
70 | def setup_tinfoil(): | 75 | def setup_tinfoil(): |
71 | import scriptpath | 76 | import scriptpath |
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py index 4dc175d117..d9b5d15279 100644 --- a/scripts/lib/devtool/standard.py +++ b/scripts/lib/devtool/standard.py | |||
@@ -64,8 +64,12 @@ def add(args, config, basepath, workspace): | |||
64 | color = 'always' | 64 | color = 'always' |
65 | else: | 65 | else: |
66 | color = args.color | 66 | color = args.color |
67 | stdout, stderr = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s %s' % (color, recipefile, srctree)) | 67 | try: |
68 | logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) | 68 | stdout, stderr = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s"' % (color, recipefile, srctree)) |
69 | logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) | ||
70 | except bb.process.ExecutionError as e: | ||
71 | logger.error('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) | ||
72 | return 1 | ||
69 | 73 | ||
70 | _add_md5(config, args.recipename, recipefile) | 74 | _add_md5(config, args.recipename, recipefile) |
71 | 75 | ||
@@ -610,7 +614,7 @@ def status(args, config, basepath, workspace): | |||
610 | 614 | ||
611 | 615 | ||
612 | def reset(args, config, basepath, workspace): | 616 | def reset(args, config, basepath, workspace): |
613 | import bb.utils | 617 | import bb |
614 | if args.recipename: | 618 | if args.recipename: |
615 | if args.all: | 619 | if args.all: |
616 | logger.error("Recipe cannot be specified if -a/--all is used") | 620 | logger.error("Recipe cannot be specified if -a/--all is used") |
@@ -630,7 +634,11 @@ def reset(args, config, basepath, workspace): | |||
630 | for pn in recipes: | 634 | for pn in recipes: |
631 | if not args.no_clean: | 635 | if not args.no_clean: |
632 | logger.info('Cleaning sysroot for recipe %s...' % pn) | 636 | logger.info('Cleaning sysroot for recipe %s...' % pn) |
633 | exec_build_env_command(config.init_path, basepath, 'bitbake -c clean %s' % pn) | 637 | try: |
638 | exec_build_env_command(config.init_path, basepath, 'bitbake -c clean %s' % pn) | ||
639 | except bb.process.ExecutionError as e: | ||
640 | 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)) | ||
641 | return 1 | ||
634 | 642 | ||
635 | _check_preserve(config, pn) | 643 | _check_preserve(config, pn) |
636 | 644 | ||
@@ -656,7 +664,11 @@ def build(args, config, basepath, workspace): | |||
656 | logger.error("no recipe named %s in your workspace" % args.recipename) | 664 | logger.error("no recipe named %s in your workspace" % args.recipename) |
657 | return -1 | 665 | return -1 |
658 | build_task = config.get('Build', 'build_task', 'populate_sysroot') | 666 | build_task = config.get('Build', 'build_task', 'populate_sysroot') |
659 | exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) | 667 | try: |
668 | exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) | ||
669 | except bb.process.ExecutionError as e: | ||
670 | # We've already seen the output since watch=True, so just ensure we return something to the user | ||
671 | return e.exitcode | ||
660 | 672 | ||
661 | return 0 | 673 | return 0 |
662 | 674 | ||