Skip to contentSkip to conversation

waf: explicitly run waf under Python 3

PATCH In review Ross Burton 4 participants 8 messages Oct 14, 2020 – Oct 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 waf: explicitly run waf under Python 3

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All wscripts that needed Python 2 would have been fixed by now.

---
 meta/classes/waf.bbclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
meta/classes/waf.bbclass +4 -4
index 309f625a40..df6d4d53e8 100644
@@ -42,7 +42,7 @@ python waf_preconfigure() {
     subsrcdir = d.getVar('S')
     wafbin = os.path.join(subsrcdir, 'waf')
     try:
-        result = subprocess.check_output([wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
+        result = subprocess.check_output(['python3', wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
         version = result.decode('utf-8').split()[1]
         if StrictVersion(version) >= StrictVersion("1.8.7"):
             d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}")
@@ -55,16 +55,16 @@ python waf_preconfigure() {
 do_configure[prefuncs] += "waf_preconfigure"
 
 waf_do_configure() {
-	(cd ${S} && ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
+	(cd ${S} && python3 ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
 }
 
 do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
 waf_do_compile()  {
-	(cd ${S} && ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
+	(cd ${S} && python3 ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
 }
 
 waf_do_install() {
-	(cd ${S} && ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
+	(cd ${S} && python3 ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
 }
 
 EXPORT_FUNCTIONS do_configure do_compile do_install
Signature · 1 line
2.25.1
#1 lore raw
Quoted 17 lines · Ross Burton

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All wscripts that needed Python 2 would have been fixed by now.

---
 meta/classes/waf.bbclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
meta/classes/waf.bbclass +0 -0
index 309f625a40..df6d4d53e8 100644

meta/classes/waf.bbclass python waf_preconfigure() { · line 48

Quoted 8 lines
meta/classes/waf.bbclass +1 -1
@@ -42,7 +42,7 @@ python waf_preconfigure() {
     subsrcdir = d.getVar('S')
     wafbin = os.path.join(subsrcdir, 'waf')
     try:
-        result = subprocess.check_output([wafbin, '--version'],
 cwd=subsrcdir, stderr=subprocess.STDOUT)
+        result = subprocess.check_output(['python3', wafbin,
 '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
 

This will break our internal usage... We still use waf 1 which runs under python 2 only :(, although we are working on transitioning

         version = result.decode('utf-8').split()[1]
Quoted 36 lines
         if StrictVersion(version) >= StrictVersion("1.8.7"):
             d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir}

--libdir=${libdir}")

meta/classes/waf.bbclass +2 -2
@@ -55,16 +55,16 @@ python waf_preconfigure() {
 do_configure[prefuncs] += "waf_preconfigure"
 
 waf_do_configure() {
-       (cd ${S} && ./waf configure -o ${B} --prefix=${prefix}
 ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
+       (cd ${S} && python3 ./waf configure -o ${B} --prefix=${prefix}
 ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
 }
 
 do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
 waf_do_compile()  {
-       (cd ${S} && ./waf build ${@oe.utils.parallel_make_argument(d,
 '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
+       (cd ${S} && python3 ./waf build
 ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)}
 ${EXTRA_OEWAF_BUILD})
 }
 

waf_do_install() {

meta/classes/waf.bbclass +1 -1
-       (cd ${S} && ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
+       (cd ${S} && python3 ./waf install --destdir=${D}

${EXTRA_OEWAF_INSTALL})
}

EXPORT_FUNCTIONS do_configure do_compile do_install
--
2.25.1

#2 lore raw
Quoted 17 lines · Joshua Watt
Quoted 13 lines · Ross Burton

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All wscripts that needed Python 2 would have been fixed by now.

---
 meta/classes/waf.bbclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 13 lines

meta/classes/waf.bbclass python waf_preconfigure() { · line 45

Quoted 10 lines
meta/classes/waf.bbclass +1 -1
index 309f625a40..df6d4d53e8 100644
@@ -42,7 +42,7 @@ python waf_preconfigure() {
     subsrcdir = d.getVar('S')
     wafbin = os.path.join(subsrcdir, 'waf')
     try:
-        result = subprocess.check_output([wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
+        result = subprocess.check_output(['python3', wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)

This will break our internal usage... We still use waf 1 which runs under python 2 only :(, although we are working on transitioning

this is for master and we have already said goodbye to python2 in oe-core. perhaps reverse patching waf in your app might be an option ?

Quoted 33 lines
Quoted 30 lines
meta/classes/waf.bbclass +3 -4
         version = result.decode('utf-8').split()[1]
         if StrictVersion(version) >= StrictVersion("1.8.7"):
             d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}")
@@ -55,16 +55,16 @@ python waf_preconfigure() {
 do_configure[prefuncs] += "waf_preconfigure"
 
 waf_do_configure() {
-       (cd ${S} && ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
+       (cd ${S} && python3 ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
 }
 
 do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
 waf_do_compile()  {
-       (cd ${S} && ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
+       (cd ${S} && python3 ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
 }
 
 waf_do_install() {
-       (cd ${S} && ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
+       (cd ${S} && python3 ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
 }
 
 EXPORT_FUNCTIONS do_configure do_compile do_install
--

2.25.1

#3 lore raw
Quoted 28 lines · Khem Raj
Quoted 15 lines · Joshua Watt
Quoted 12 lines · Ross Burton

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All wscripts that needed Python 2 would have been fixed by now.

---
  meta/classes/waf.bbclass | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 12 lines

meta/classes/waf.bbclass python waf_preconfigure() { · line 45

Quoted 10 lines
meta/classes/waf.bbclass +1 -1
index 309f625a40..df6d4d53e8 100644
@@ -42,7 +42,7 @@ python waf_preconfigure() {
      subsrcdir = d.getVar('S')
      wafbin = os.path.join(subsrcdir, 'waf')
      try:
-        result = subprocess.check_output([wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
+        result = subprocess.check_output(['python3', wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)

This will break our internal usage... We still use waf 1 which runs under python 2 only :(, although we are working on transitioning

Quoted 2 lines

this is for master and we have already said goodbye to python2 in oe-core. perhaps reverse patching waf in your app might be an option ?

a.k.a. upgrading to waf 2 :)

Can we deal with it by importing either pythonnative or python3native in the recipes along with waf.bbclass, e.g.

    inherit waf pythonnative # waf 1

or

    inherit waf python3native # waf 2

Then you get the interpreter than matches the waf in your repo.

I do appreciate that oe-core has dumped python 2 support (and we should have *ages* ago also)... but I also don't really want a fire drill when most of our applications no longer build on 3.2, especially we can just inherit python3native as shown.

Quoted 32 lines
Quoted 32 lines
Quoted 30 lines
meta/classes/waf.bbclass +3 -4
          version = result.decode('utf-8').split()[1]
          if StrictVersion(version) >= StrictVersion("1.8.7"):
              d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}")
@@ -55,16 +55,16 @@ python waf_preconfigure() {
  do_configure[prefuncs] += "waf_preconfigure"
 
  waf_do_configure() {
-       (cd ${S} && ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
+       (cd ${S} && python3 ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
  }
 
  do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
  waf_do_compile()  {
-       (cd ${S} && ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
+       (cd ${S} && python3 ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
  }
 
  waf_do_install() {
-       (cd ${S} && ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
+       (cd ${S} && python3 ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
  }
 
  EXPORT_FUNCTIONS do_configure do_compile do_install
--

2.25.1

#4 lore raw
Quoted 43 lines · Joshua Watt
Quoted 1 line · Khem Raj

On Wed, Oct 14, 2020 at 5:41 AM Joshua Watt <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines · Ross Burton
Quoted 5 lines

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All

wscripts

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

that needed Python 2 would have been fixed by now.

---
  meta/classes/waf.bbclass | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 9 lines
Quoted 9 lines

meta/classes/waf.bbclass python waf_preconfigure() { · line 45

Quoted 9 lines
meta/classes/waf.bbclass +0 -1
index 309f625a40..df6d4d53e8 100644
@@ -42,7 +42,7 @@ python waf_preconfigure() {
      subsrcdir = d.getVar('S')
      wafbin = os.path.join(subsrcdir, 'waf')
      try:
-        result = subprocess.check_output([wafbin, '--version'],

cwd=subsrcdir, stderr=subprocess.STDOUT)

Quoted 1 line
Quoted 1 line

meta/classes/waf.bbclass python waf_preconfigure() { · line 45

Quoted 1 line
meta/classes/waf.bbclass +1 -0
+        result = subprocess.check_output(['python3', wafbin,

'--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)

Quoted 2 lines
Quoted 2 lines

This will break our internal usage... We still use waf 1 which runs

under python 2 only :(, although we are working on transitioning

Quoted 2 lines

this is for master and we have already said goodbye to python2 in oe-core. perhaps reverse patching waf in your app might be an option ?

a.k.a. upgrading to waf 2 :)

Can we deal with it by importing either pythonnative or python3native in the recipes along with waf.bbclass, e.g.

Quoted 7 lines

inherit waf pythonnative # waf 1

or

inherit waf python3native # waf 2

Then you get the interpreter than matches the waf in your repo.

This is going to be a large set of recipes I would imagine and perhaps not worth it for supporting old version of waf which is not used in any packages on open layers it will aggravate serialization of waf recipes due to python native dependency on the other hand there are recipes in meta-Oe which need this change where patches are pending

Quoted 47 lines

I do appreciate that oe-core has dumped python 2 support (and we should have *ages* ago also)... but I also don't really want a fire drill when most of our applications no longer build on 3.2, especially we can just inherit python3native as shown.

Quoted 4 lines
Quoted 4 lines

meta/classes/waf.bbclass python waf_preconfigure() {

Quoted 4 lines
meta/classes/waf.bbclass +0 -0
          version = result.decode('utf-8').split()[1]
          if StrictVersion(version) >= StrictVersion("1.8.7"):
              d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir}

--libdir=${libdir}")

Quoted 5 lines
Quoted 5 lines

meta/classes/waf.bbclass python waf_preconfigure() { · line 58

Quoted 5 lines
meta/classes/waf.bbclass +0 -1
@@ -55,16 +55,16 @@ python waf_preconfigure() {
  do_configure[prefuncs] += "waf_preconfigure"
 
  waf_do_configure() {
-       (cd ${S} && ./waf configure -o ${B} --prefix=${prefix}

${WAF_EXTRA_CONF} ${EXTRA_OECONF})

Quoted 1 line
Quoted 1 line

meta/classes/waf.bbclass python waf_preconfigure() { · line 58

Quoted 1 line
meta/classes/waf.bbclass +1 -0
+       (cd ${S} && python3 ./waf configure -o ${B} --prefix=${prefix}

${WAF_EXTRA_CONF} ${EXTRA_OECONF})

Quoted 5 lines
Quoted 5 lines

meta/classes/waf.bbclass python waf_preconfigure() {

Quoted 5 lines
meta/classes/waf.bbclass +0 -1
  }
 
  do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
  waf_do_compile()  {
-       (cd ${S} && ./waf build ${@oe.utils.parallel_make_argument(d,

'-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})

Quoted 1 line
Quoted 1 line

meta/classes/waf.bbclass python waf_preconfigure() { · line 63

Quoted 1 line
meta/classes/waf.bbclass +1 -0
+       (cd ${S} && python3 ./waf build

${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})

Quoted 4 lines
Quoted 4 lines

meta/classes/waf.bbclass python waf_preconfigure() {

Quoted 4 lines
meta/classes/waf.bbclass +0 -1
  }
 
  waf_do_install() {
-       (cd ${S} && ./waf install --destdir=${D}

${EXTRA_OEWAF_INSTALL})

Quoted 1 line
Quoted 1 line

meta/classes/waf.bbclass python waf_preconfigure() { · line 67

Quoted 1 line
meta/classes/waf.bbclass +1 -0
+       (cd ${S} && python3 ./waf install --destdir=${D}

${EXTRA_OEWAF_INSTALL})

Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
meta/classes/waf.bbclass +0 -1
  }
 
  EXPORT_FUNCTIONS do_configure do_compile do_install
--

2.25.1

#5 lore raw
In reply to Joshua Watt
Quoted 15 lines · Joshua Watt
Quoted 12 lines · Ross Burton

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All wscripts that needed Python 2 would have been fixed by now.

---
 meta/classes/waf.bbclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 12 lines

meta/classes/waf.bbclass python waf_preconfigure() { · line 45

Quoted 10 lines
meta/classes/waf.bbclass +1 -1
index 309f625a40..df6d4d53e8 100644
@@ -42,7 +42,7 @@ python waf_preconfigure() {
     subsrcdir = d.getVar('S')
     wafbin = os.path.join(subsrcdir, 'waf')
     try:
-        result = subprocess.check_output([wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
+        result = subprocess.check_output(['python3', wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)

This will break our internal usage... We still use waf 1 which runs under python 2 only :(, although we are working on transitioning

Might I suggest this is parameterised as something like:

WAFPYTHON = "python3"

then OE-Core can continue on and improve but people with legacy can handle it better?

Cheers,

Richard

#6 lore raw
Quoted 30 lines · Richard Purdie
Quoted 15 lines · Joshua Watt
Quoted 12 lines · Ross Burton

We don't assume Python 2 is on the host and don't expose an unversioned python in HOSTTOOLS, but waf uses the unversion python binary.

Typically this is solved by patching waf (see the glmark2 recipe) but this can be solved centrally by invoking python3 directly. All wscripts that needed Python 2 would have been fixed by now.

---
 meta/classes/waf.bbclass | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 12 lines

meta/classes/waf.bbclass python waf_preconfigure() { · line 45

Quoted 10 lines
meta/classes/waf.bbclass +1 -1
index 309f625a40..df6d4d53e8 100644
@@ -42,7 +42,7 @@ python waf_preconfigure() {
     subsrcdir = d.getVar('S')
     wafbin = os.path.join(subsrcdir, 'waf')
     try:
-        result = subprocess.check_output([wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
+        result = subprocess.check_output(['python3', wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)

This will break our internal usage... We still use waf 1 which runs under python 2 only :(, although we are working on transitioning

Quoted 6 lines

Might I suggest this is parameterised as something like:

WAFPYTHON = "python3"

then OE-Core can continue on and improve but people with legacy can handle it better?

That would be fine with me

Quoted 5 lines

Cheers,

Richard

#7 lore raw
In reply to Richard Purdie
Quoted 6 lines · Richard Purdie

Might I suggest this is parameterised as something like:

WAFPYTHON = "python3"

then OE-Core can continue on and improve but people with legacy can handle it better?

This was the patch I originally had months ago ;)

v2 incoming.

Ross