aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2017-04-05 15:36:04 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-08 22:48:04 +0100
commitb6c72c0d169473e2626938be2ee59f850624612e (patch)
tree8cb765b96c81710d1132e2290ad5437f2f5ab2bd /scripts
parent1da641661bb5963fcbd7ac2c20bc997c3eae6f18 (diff)
downloadopenembedded-core-contrib-b6c72c0d169473e2626938be2ee59f850624612e.tar.gz
yocto-compat-layer: fix also other command invocations
In commit 5b9ac62ab535d, one place was fixed where a command was invoked such that failures caused double stack traces and stderr was lost. The same problem also occurs elsewhere, triggered for example by a layer with parsing problems. Now a new utility method is used instead of repeating the code. Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/compatlayer/__init__.py23
-rw-r--r--scripts/lib/compatlayer/cases/common.py25
2 files changed, 21 insertions, 27 deletions
diff --git a/scripts/lib/compatlayer/__init__.py b/scripts/lib/compatlayer/__init__.py
index 86f86eb657..9eb862dc6b 100644
--- a/scripts/lib/compatlayer/__init__.py
+++ b/scripts/lib/compatlayer/__init__.py
@@ -4,6 +4,7 @@
# Released under the MIT license (see COPYING.MIT)
import os
+import subprocess
from enum import Enum
class LayerType(Enum):
@@ -199,8 +200,20 @@ def add_layer(bblayersconf, layer, layers, logger):
return True
+def check_command(error_msg, cmd):
+ '''
+ Run a command under a shell, capture stdout and stderr in a single stream,
+ throw an error when command returns non-zero exit code. Returns the output.
+ '''
+
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ output, _ = p.communicate()
+ if p.returncode:
+ msg = "%s\nCommand: %s\nOutput:\n%s" % (error_msg, cmd, output.decode('utf-8'))
+ raise RuntimeError(msg)
+ return output
+
def get_signatures(builddir, failsafe=False):
- import subprocess
import re
# some recipes needs to be excluded like meta-world-pkgdata
@@ -214,12 +227,8 @@ def get_signatures(builddir, failsafe=False):
if failsafe:
cmd += '-k '
cmd += '-S none world'
- p = subprocess.Popen(cmd, shell=True,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- output, _ = p.communicate()
- if p.returncode:
- msg = "Generating signatures failed. This might be due to some parse error and/or general layer incompatibilities.\nCommand: %s\nOutput:\n%s" % (cmd, output.decode('utf-8'))
- raise RuntimeError(msg)
+ check_command('Generating signatures failed. This might be due to some parse error and/or general layer incompatibilities.',
+ cmd)
sigs_file = os.path.join(builddir, 'locked-sigs.inc')
sig_regex = re.compile("^(?P<task>.*:.*):(?P<hash>.*) .$")
diff --git a/scripts/lib/compatlayer/cases/common.py b/scripts/lib/compatlayer/cases/common.py
index 4d328ec1f1..9cc682e2c1 100644
--- a/scripts/lib/compatlayer/cases/common.py
+++ b/scripts/lib/compatlayer/cases/common.py
@@ -2,9 +2,8 @@
# Released under the MIT license (see COPYING.MIT)
import os
-import subprocess
import unittest
-from compatlayer import get_signatures, LayerType
+from compatlayer import get_signatures, LayerType, check_command
from compatlayer.case import OECompatLayerTestCase
class CommonCompatLayer(OECompatLayerTestCase):
@@ -20,26 +19,12 @@ class CommonCompatLayer(OECompatLayerTestCase):
msg="Layer contains README file but is empty.")
def test_parse(self):
- try:
- output = subprocess.check_output('bitbake -p', shell=True,
- stderr=subprocess.PIPE)
- except subprocess.CalledProcessError as e:
- import traceback
- exc = traceback.format_exc()
- msg = 'Layer %s failed to parse.\n%s\n%s\n' % (self.tc.layer['name'],
- exc, e.output.decode('utf-8'))
- raise RuntimeError(msg)
+ check_command('Layer %s failed to parse.' % self.tc.layer['name'],
+ 'bitbake -p')
def test_show_environment(self):
- try:
- output = subprocess.check_output('bitbake -e', shell=True,
- stderr=subprocess.PIPE)
- except subprocess.CalledProcessError as e:
- import traceback
- exc = traceback.format_exc()
- msg = 'Layer %s failed to show environment.\n%s\n%s\n' % \
- (self.tc.layer['name'], exc, e.output.decode('utf-8'))
- raise RuntimeError(msg)
+ check_command('Layer %s failed to show environment.' % self.tc.layer['name'],
+ 'bitbake -e')
def test_signatures(self):
if self.tc.layer['type'] == LayerType.SOFTWARE: