Skip to contentSkip to conversation

configure: Insist on a Python 2, not Python 3

PATCH Applied Peter Maydell 2 participants 2 messages Apr 12, 2012 – Apr 13, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: Insist on a Python 2, not Python 3

Our Python scripts require Python 2 and will fail on Python 3, eg:
File "/home/petmay01/linaro/qemu-from-laptop/qemu/scripts/qapi-commands.py", line 378
except getopt.GetoptError, err:
^
SyntaxError: invalid syntax

Add a check to configure that Python is not a Python 3, so we can fail with a comprehensible error rather than an obscure one.

---
 configure |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
configure +8 -0
index e05f34b..1d5ab07 100755
@@ -1242,6 +1242,14 @@ if ! has $python; then
   exit 1
 fi
 
+# Note that if the Python conditional here evaluates True we will exit
+# with status 1 which is a shell 'false' value.
+if ! "$python" -c 'import sys; sys.exit(sys.version_info[0] >= 3)'; then
+  echo "Python 2 required but '$python' is version 3 or better."
+  echo "Use --python=/path/to/python to specify a Python 2."
+  exit 1
+fi
+
 if test -z "$target_list" ; then
     target_list="$default_target_list"
 else
Signature · 1 line
1.7.1
#1 lore raw
Quoted 6 lines · Peter Maydell

Our Python scripts require Python 2 and will fail on Python 3, eg:
File "/home/petmay01/linaro/qemu-from-laptop/qemu/scripts/qapi-commands.py", line 378
except getopt.GetoptError, err:
^
SyntaxError: invalid syntax

Quoted 8 lines

Add a check to configure that Python is not a Python 3, so we can fail with a comprehensible error rather than an obscure one.

---
 configure |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan