[Spice-commits] 2 commits - autogen.sh configure.ac m4/ax_python_module.m4 m4/spice-deps.m4 python_modules/codegen.py spice_codegen.py

Christophe Fergau teuf at kemper.freedesktop.org
Thu Apr 23 01:33:31 PDT 2015


 autogen.sh                |    2 -
 configure.ac              |    2 +
 m4/ax_python_module.m4    |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 m4/spice-deps.m4          |   19 +++++++++++++++++
 python_modules/codegen.py |    6 ++---
 spice_codegen.py          |    6 ++---
 6 files changed, 77 insertions(+), 7 deletions(-)

New commits:
commit b216f66f108b14b67b8cb2f9a3d2caee0ec8e0fd
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue Apr 14 16:08:43 2015 +0200

    codegen: Use six.PY3 rather than six.PY2
    
    Older versions of python-six (at least 1.3.0) defined six.PY3 but not
    six.PY2. six.PY2 is only used twice in straightforward tests so it's
    easy to use six.PY3 instead.

diff --git a/python_modules/codegen.py b/python_modules/codegen.py
index 55f513b..f324498 100644
--- a/python_modules/codegen.py
+++ b/python_modules/codegen.py
@@ -121,10 +121,10 @@ class CodeWriter:
 
     def write(self, s):
         # Ensure its a unicode string
-        if six.PY2:
-            s = unicode(s)
-        else:
+        if six.PY3:
             s = str(s)
+        else:
+            s = unicode(s)
 
         if len(s) == 0:
             return
diff --git a/spice_codegen.py b/spice_codegen.py
index 16ad478..84790af 100755
--- a/spice_codegen.py
+++ b/spice_codegen.py
@@ -265,10 +265,10 @@ if options.keep_identical_file:
         pass
 
 f = open(dest_file, 'wb')
-if six.PY2:
-    f.write(content)
-else:
+if six.PY3:
     f.write(bytes(content, 'UTF-8'))
+else:
+    f.write(content)
 f.close()
 
 six.print_("Wrote %s" % dest_file)
commit 838ec7d87b5311843a7214fe946471fadd5d8908
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 13 13:05:44 2015 +0200

    configure.ac: Check for needed python modules for git builds
    
    After the patch adding support for python 3 to the code generator,
    python-six is required when building from git. Since I got 2 different
    reports of SPICE build failures right after introducing it, it's
    probably better to check for the needed python modules from configure,
    and exit with an error if they are missing.
    This commit adds a --enable-python-checks configure flag for that
    though, since we only want to do that when building from git. It assumes
    that people running from git will be running autogen.sh, while people
    building from tarballs will run configure.

diff --git a/autogen.sh b/autogen.sh
index e4ada55..0a69542 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -15,5 +15,5 @@ autoreconf --verbose --force --install
 
 cd "$olddir"
 if [ -z "$NOCONFIGURE" ]; then
-    "$srcdir"/configure --enable-maintainer-mode ${1+"$@"}
+    "$srcdir"/configure --enable-maintainer-mode --enable-python-checks ${1+"$@"}
 fi
diff --git a/configure.ac b/configure.ac
index 73102c0..3a8c0e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,8 @@ AC_CONFIG_SUBDIRS([spice-protocol])
 PROTOCOL_CFLAGS='-I ${top_srcdir}/spice-protocol'
 AC_SUBST(PROTOCOL_CFLAGS)
 
+SPICE_CHECK_PYTHON_MODULES()
+
 SPICE_CHECK_PIXMAN(SPICE_COMMON)
 SPICE_CHECK_SMARTCARD(SPICE_COMMON)
 SPICE_CHECK_CELT051(SPICE_COMMON)
diff --git a/m4/ax_python_module.m4 b/m4/ax_python_module.m4
new file mode 100644
index 0000000..3afc404
--- /dev/null
+++ b/m4/ax_python_module.m4
@@ -0,0 +1,49 @@
+# ===========================================================================
+#     http://www.gnu.org/software/autoconf-archive/ax_python_module.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_PYTHON_MODULE(modname[, fatal])
+#
+# DESCRIPTION
+#
+#   Checks for Python module.
+#
+#   If fatal is non-empty then absence of a module will trigger an error.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Andrew Collier
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 6
+
+AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE])
+AC_DEFUN([AX_PYTHON_MODULE],[
+    if test -z $PYTHON;
+    then
+        PYTHON="python"
+    fi
+    PYTHON_NAME=`basename $PYTHON`
+    AC_MSG_CHECKING($PYTHON_NAME module: $1)
+	$PYTHON -c "import $1" 2>/dev/null
+	if test $? -eq 0;
+	then
+		AC_MSG_RESULT(yes)
+		eval AS_TR_CPP(HAVE_PYMOD_$1)=yes
+	else
+		AC_MSG_RESULT(no)
+		eval AS_TR_CPP(HAVE_PYMOD_$1)=no
+		#
+		if test -n "$2"
+		then
+			AC_MSG_ERROR(failed to find required module $1)
+			exit 1
+		fi
+	fi
+])
diff --git a/m4/spice-deps.m4 b/m4/spice-deps.m4
index 2477dbc..600dd98 100644
--- a/m4/spice-deps.m4
+++ b/m4/spice-deps.m4
@@ -154,3 +154,22 @@ AC_DEFUN([SPICE_CHECK_GLIB2], [
     AS_VAR_APPEND([$1_CFLAGS], [" $GLIB2_CFLAGS"])
     AS_VAR_APPEND([$1_LIBS], [" $GLIB2_LIBS"])
 ])
+
+# SPICE_CHECK_PYTHON_MODULES()
+# --------------------------
+# Adds a --enable-python-checks configure flags as well as checks for the
+# availability of the python modules needed by the python scripts generating
+# C code from spice.proto. These checks are not needed when building from
+# tarballs so they are disabled by default.
+#---------------------------
+AC_DEFUN([SPICE_CHECK_PYTHON_MODULES], [
+    AC_ARG_ENABLE([python-checks],
+        AS_HELP_STRING([--enable-python-checks=@<:@yes/no@:>@],
+                       [Enable checks for Python modules needed to build from git @<:@default=no@:>@]),
+                       [],
+                       [enable_python_checks="no"])
+    if test "x$enable_python_checks" != "xno"; then
+        AX_PYTHON_MODULE([six], [1])
+        AX_PYTHON_MODULE([pyparsing], [1])
+    fi
+])


More information about the Spice-commits mailing list