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>
This commit is contained in:
parent
f81a532dd6
commit
efd3b0ee30
|
@ -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>.*) .$")
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue