waf: Improve version parsing to avoid failing on warnings

waf uses an inline tar file extracted by the tarfile module. The tarfile
module may print a warning when used with default 'filter' argument[0].

When called to get the version, the first time after unpack, the output
may look like:
  # output from lower modules (e.g: warnings from tarfile, ...)
  waf X.Y.Z ...

This patch makes the version parsing more precise by looking at the
first line matching "waf ".

[0]: https://docs.python.org/3.12/library/tarfile.html#extraction-filters

(From OE-Core rev: 643b799a0c11d82907dd82991c19b003fe20a8b0)

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Yoann Congal 2024-02-29 10:59:36 +01:00 committed by Richard Purdie
parent deef6a87b5
commit 140edb96aa

View File

@ -54,11 +54,21 @@ python waf_preconfigure() {
wafbin = os.path.join(subsrcdir, 'waf')
try:
result = subprocess.check_output([python, wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
version = result.decode('utf-8').split()[1]
if not bb.utils.is_semver(version):
# Output looks like:
# # output from lower modules (e.g. warnings, ...)
# waf X.Y.Z ...
# So, look for the line starting with "waf "
version = None
for line in result.decode('utf-8').split("\n"):
if line.startswith("waf "):
version = line.split()[1]
break
if not version or not bb.utils.is_semver(version):
bb.warn("Unable to parse \"waf --version\" output. Assuming waf version without bindir/libdir support.")
bb.warn("waf·--version·output = \n%s" % result.decode('utf-8'))
elif bb.utils.vercmp_string_op(version, "1.8.7", ">="):
bb.note("waf version is high enough to add --bindir and --libdir")
d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}")
except subprocess.CalledProcessError as e:
bb.warn("Unable to execute waf --version, exit code %d. Assuming waf version without bindir/libdir support." % e.returncode)