diff options
author | Martin Erik Werner <martinerikwerner.aac@gmail.com> | 2023-10-05 15:40:36 +0200 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2023-10-06 09:53:38 +1100 |
commit | 0d150705102f86be0f675b969ee0aadfdb50b3b3 (patch) | |
tree | c1283971ab9548814e5d77ae4d17c3c6c35d1618 | |
parent | fix typo and logic issue when libbsd checking is enforced by the user code (diff) | |
download | rtems_waf-0d150705102f86be0f675b969ee0aadfdb50b3b3.tar.bz2 |
Avoid StopIteration exception for non-rtems .pc
_arch_from_arch_bsp() and _bsp_from_arch_bsp() has overly optimistic
assumptions that the argument must contain a '-'-separated field which
starts with "rtems". These functions are intended to find the target
triplet or the bsp parts of strings like "sparc-gaisler-rtems5-leon3"
and "arm-rtems6-xilinx_zynq_zc702"
But _find_installed_arch_bsps() may call _arch_from_arch_bsp() with the
name (without file extension) of any file which ends with ".pc",
including for example "expat". This triggers a StopIteration exception
when trying to find the next field after the "rtems" field, since no
"rtems" field exists to start with.
Rework these function to remove the preconditions, so that they return
None if no "rtems" field exist or if no field exists before or after the
"rtems" field.
It could be argued. based on their name, that calling these functions
with something that is not a triplet-bsp string is incorrect to start
with, but attempting to address that is not done here.
-rw-r--r-- | rtems.py | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -859,15 +859,17 @@ def _check_arch_bsps(req, config, path, archs, version): def _arch_from_arch_bsp(arch_bsp): fields = arch_bsp.split('-') - rtems_field_index = next(i for i, field in enumerate(fields) if field.startswith('rtems')) - return '-'.join(fields[:(rtems_field_index + 1)]) - + for i, field in enumerate(fields): + if field.startswith('rtems') and fields[:(i + 1)] is not None: + return '-'.join(fields[:(i + 1)]) + return None def _bsp_from_arch_bsp(arch_bsp): fields = arch_bsp.split('-') - rtems_field_index = next(i for i, field in enumerate(fields) if field.startswith('rtems')) - return '-'.join(fields[(rtems_field_index + 1):]) - + for i, field in enumerate(fields): + if field.startswith('rtems') and fields[(i + 1):] is not None: + return '-'.join(fields[(i + 1):]) + return None def _pkgconfig_path(path): return os.path.join(path, 'lib', 'pkgconfig') |