diff options
Diffstat (limited to 'scripts/lib/compatlayer')
-rw-r--r-- | scripts/lib/compatlayer/__init__.py | 23 | ||||
-rw-r--r-- | scripts/lib/compatlayer/cases/common.py | 25 |
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 | ||
6 | import os | 6 | import os |
7 | import subprocess | ||
7 | from enum import Enum | 8 | from enum import Enum |
8 | 9 | ||
9 | class LayerType(Enum): | 10 | class LayerType(Enum): |
@@ -199,8 +200,20 @@ def add_layer(bblayersconf, layer, layers, logger): | |||
199 | 200 | ||
200 | return True | 201 | return True |
201 | 202 | ||
203 | def 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 | |||
202 | def get_signatures(builddir, failsafe=False): | 216 | def 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 | ||
4 | import os | 4 | import os |
5 | import subprocess | ||
6 | import unittest | 5 | import unittest |
7 | from compatlayer import get_signatures, LayerType | 6 | from compatlayer import get_signatures, LayerType, check_command |
8 | from compatlayer.case import OECompatLayerTestCase | 7 | from compatlayer.case import OECompatLayerTestCase |
9 | 8 | ||
10 | class CommonCompatLayer(OECompatLayerTestCase): | 9 | class 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: |