diff mbox series

waf: Improve version parsing to avoid failing on warnings

Message ID 20240229095935.478575-1-yoann.congal@smile.fr
State Accepted, archived
Commit 643b799a0c11d82907dd82991c19b003fe20a8b0
Headers show
Series waf: Improve version parsing to avoid failing on warnings | expand

Commit Message

Yoann Congal Feb. 29, 2024, 9:59 a.m. UTC
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

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 meta/classes-recipe/waf.bbclass | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/waf.bbclass b/meta/classes-recipe/waf.bbclass
index 70bf3be8fd..01707c8e2c 100644
--- a/meta/classes-recipe/waf.bbclass
+++ b/meta/classes-recipe/waf.bbclass
@@ -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)