scripts/runqemu: raise an error when bitbake was not found
PATCH 1/3 scripts/runqemu: raise an error when bitbake was not found
From: Richard Grünert <[email protected]>
Running 'scrupts/runqemu' without bitbake in PATH causes the following error:
```
Traceback (most recent call last):
File "/home/rg/temp_stuff/oe_2/./scripts/runqemu", line 1807, in main
config.check_args()
~~~~~~~~~~~~~~~~~^^
File "/home/rg/temp_stuff/oe_2/./scripts/runqemu", line 624, in check_args
s = re.search('^DEPLOY_DIR_IMAGE="(.*)"', self.bitbake_e, re.M)
File "/usr/lib/python3.13/re/__init__.py", line 177, in search
return _compile(pattern, flags).search(string)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
```This patch adds a more helpful error message to inform the user that bitbake was not found, e.g. because oe-init-build-env was not sourced.
This is an example of the new error message after the patch:
``` runqemu - ERROR - In order for this script to dynamically infer paths kernels or filesystem images, you either need bitbake in your PATH or to source oe-init-build-env before running this script. Dynamic path inference can be avoided by passing a *.qemuboot.conf to runqemu, i.e. `runqemu /path/to/my-image-name.qemuboot.conf` Bitbake is needed to run 'bitbake -e', but it is not found in PATH. Please source the bitbake build environment. ```
(From OE-Core rev: c9744f2d294f5baa8c4c9c795eb73d269f943b0c)
--- scripts/runqemu | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/runqemu +4 -3
@@ -1714,9 +1714,6 @@ to your build configuration. self.cleaned = True def run_bitbake_env(self, mach=None, target=''): - bitbake = shutil.which('bitbake') - if not bitbake: - return if not mach: mach = self.get('MACHINE')
@@ -1733,6 +1730,10 @@ to your build configuration. else: cmd = 'bitbake -e %s %s' % (multiconfig, target) + bitbake = shutil.which('bitbake') + if not bitbake: + raise OEPathError("Bitbake is needed to run '%s', but it is not found in PATH. Please source the bitbake build environment." % cmd.strip()) + logger.info('Running %s...' % cmd) try: return subprocess.check_output(cmd, shell=True).decode('utf-8')
Signature · 1 line
2.39.5
PATCH 2/3 runqemu: ensure that bitbake environment is either returned, or an exception is raised
From: Alexander Kanavin <[email protected]>
This eliminates the other remaining code path where environment getter returns 'nothing'. This and the previous patch were tested in a-full, and no errors occurred [1], which means the code paths that make use of the function returning nothing are never actually executed and can be cleaned up (in the following patch).
The rationale is that if environment getter cannot obtain the environment, it should report that and not sweep the issue under the carpet; it's up to the caller to handle that situation, or make pre-emptive checks that avoid calling the environment getter when it is bound to fail.
[1] https://lists.openembedded.org/g/openembedded-core/message/223651
--- scripts/runqemu | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
scripts/runqemu +1 -5
@@ -1745,11 +1745,7 @@ to your build configuration. cmd = 'MACHINE=%s bitbake -e %s %s' % (mach, multiconfig, target) else: cmd = 'bitbake -e %s %s' % (multiconfig, target) - try: - return subprocess.check_output(cmd, shell=True).decode('utf-8') - except subprocess.CalledProcessError as err: - logger.warning("Couldn't run '%s' to gather environment information, giving up with 'bitbake -e':\n%s" % (cmd, err.output.decode('utf-8'))) - return '' + return subprocess.check_output(cmd, shell=True).decode('utf-8') def load_bitbake_env(self, mach=None, target=None):
Signature · 1 line
2.39.5
PATCH 3/3 scripts/runqemu: remove the code block that works around the missing bitbake environment
In reply to Alexander KanavinFrom: Alexander Kanavin <[email protected]>
As confirmed by the previous patch this code path is never taken and can be removed.
--- scripts/runqemu | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-)
scripts/runqemu +6 -28
@@ -1007,34 +1007,12 @@ to your build configuration. if not self.bitbake_e: self.load_bitbake_env() - if self.bitbake_e: - native_vars = ['STAGING_DIR_NATIVE'] - for nv in native_vars: - s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M) - if s and s.group(1) != self.get(nv): - logger.info('Overriding conf file setting of %s to %s from Bitbake environment' % (nv, s.group(1))) - self.set(nv, s.group(1)) - else: - # when we're invoked from a running bitbake instance we won't - # be able to call `bitbake -e`, then try: - # - get OE_TMPDIR from environment and guess paths based on it - # - get OECORE_NATIVE_SYSROOT from environment (for sdk) - tmpdir = self.get('OE_TMPDIR') - oecore_native_sysroot = self.get('OECORE_NATIVE_SYSROOT') - if tmpdir: - logger.info('Setting STAGING_DIR_NATIVE and STAGING_BINDIR_NATIVE relative to OE_TMPDIR (%s)' % tmpdir) - hostos, _, _, _, machine = os.uname() - buildsys = '%s-%s' % (machine, hostos.lower()) - staging_dir_native = '%s/sysroots/%s' % (tmpdir, buildsys) - self.set('STAGING_DIR_NATIVE', staging_dir_native) - elif oecore_native_sysroot: - logger.info('Setting STAGING_DIR_NATIVE to OECORE_NATIVE_SYSROOT (%s)' % oecore_native_sysroot) - self.set('STAGING_DIR_NATIVE', oecore_native_sysroot) - if self.get('STAGING_DIR_NATIVE'): - # we have to assume that STAGING_BINDIR_NATIVE is at usr/bin - staging_bindir_native = '%s/usr/bin' % self.get('STAGING_DIR_NATIVE') - logger.info('Setting STAGING_BINDIR_NATIVE to %s' % staging_bindir_native) - self.set('STAGING_BINDIR_NATIVE', '%s/usr/bin' % self.get('STAGING_DIR_NATIVE')) + native_vars = ['STAGING_DIR_NATIVE'] + for nv in native_vars: + s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M) + if s and s.group(1) != self.get(nv): + logger.info('Overriding conf file setting of %s to %s from Bitbake environment' % (nv, s.group(1))) + self.set(nv, s.group(1)) def print_config(self): logoutput = ['Continuing with the following parameters:']
Signature · 1 line
2.39.5