summaryrefslogtreecommitdiffstats
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-10 23:00:42 +0100
commitefd3b0ee305e7372e736262fd2ab2bcc983b1b15 (patch)
tree4d1a374dcb58bb2c5dced73f2bf48fce7ca6e479 /scripts
parentf81a532dd65ba5148b7072231ed85361dbad7a2c (diff)
downloadpoky-efd3b0ee305e7372e736262fd2ab2bcc983b1b15.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. (From OE-Core rev: b6c72c0d169473e2626938be2ee59f850624612e) 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 @@
4# Released under the MIT license (see COPYING.MIT) 4# Released under the MIT license (see COPYING.MIT)
5 5
6import os 6import os
7import subprocess
7from enum import Enum 8from enum import Enum
8 9
9class LayerType(Enum): 10class LayerType(Enum):
@@ -199,8 +200,20 @@ def add_layer(bblayersconf, layer, layers, logger):
199 200
200 return True 201 return True
201 202
203def check_command(error_msg, cmd):
204 '''
205 Run a command under a shell, capture stdout and stderr in a single stream,
206 throw an error when command returns non-zero exit code. Returns the output.
207 '''
208
209 p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
210 output, _ = p.communicate()
211 if p.returncode:
212 msg = "%s\nCommand: %s\nOutput:\n%s" % (error_msg, cmd, output.decode('utf-8'))
213 raise RuntimeError(msg)
214 return output
215
202def get_signatures(builddir, failsafe=False): 216def get_signatures(builddir, failsafe=False):
203 import subprocess
204 import re 217 import re
205 218
206 # some recipes needs to be excluded like meta-world-pkgdata 219 # some recipes needs to be excluded like meta-world-pkgdata
@@ -214,12 +227,8 @@ def get_signatures(builddir, failsafe=False):
214 if failsafe: 227 if failsafe:
215 cmd += '-k ' 228 cmd += '-k '
216 cmd += '-S none world' 229 cmd += '-S none world'
217 p = subprocess.Popen(cmd, shell=True, 230 check_command('Generating signatures failed. This might be due to some parse error and/or general layer incompatibilities.',
218 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 231 cmd)
219 output, _ = p.communicate()
220 if p.returncode:
221 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'))
222 raise RuntimeError(msg)
223 sigs_file = os.path.join(builddir, 'locked-sigs.inc') 232 sigs_file = os.path.join(builddir, 'locked-sigs.inc')
224 233
225 sig_regex = re.compile("^(?P<task>.*:.*):(?P<hash>.*) .$") 234 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 @@
2# Released under the MIT license (see COPYING.MIT) 2# Released under the MIT license (see COPYING.MIT)
3 3
4import os 4import os
5import subprocess
6import unittest 5import unittest
7from compatlayer import get_signatures, LayerType 6from compatlayer import get_signatures, LayerType, check_command
8from compatlayer.case import OECompatLayerTestCase 7from compatlayer.case import OECompatLayerTestCase
9 8
10class CommonCompatLayer(OECompatLayerTestCase): 9class CommonCompatLayer(OECompatLayerTestCase):
@@ -20,26 +19,12 @@ class CommonCompatLayer(OECompatLayerTestCase):
20 msg="Layer contains README file but is empty.") 19 msg="Layer contains README file but is empty.")
21 20
22 def test_parse(self): 21 def test_parse(self):
23 try: 22 check_command('Layer %s failed to parse.' % self.tc.layer['name'],
24 output = subprocess.check_output('bitbake -p', shell=True, 23 'bitbake -p')
25 stderr=subprocess.PIPE)
26 except subprocess.CalledProcessError as e:
27 import traceback
28 exc = traceback.format_exc()
29 msg = 'Layer %s failed to parse.\n%s\n%s\n' % (self.tc.layer['name'],
30 exc, e.output.decode('utf-8'))
31 raise RuntimeError(msg)
32 24
33 def test_show_environment(self): 25 def test_show_environment(self):
34 try: 26 check_command('Layer %s failed to show environment.' % self.tc.layer['name'],
35 output = subprocess.check_output('bitbake -e', shell=True, 27 'bitbake -e')
36 stderr=subprocess.PIPE)
37 except subprocess.CalledProcessError as e:
38 import traceback
39 exc = traceback.format_exc()
40 msg = 'Layer %s failed to show environment.\n%s\n%s\n' % \
41 (self.tc.layer['name'], exc, e.output.decode('utf-8'))
42 raise RuntimeError(msg)
43 28
44 def test_signatures(self): 29 def test_signatures(self):
45 if self.tc.layer['type'] == LayerType.SOFTWARE: 30 if self.tc.layer['type'] == LayerType.SOFTWARE: