Skip to contentSkip to conversation

Have `make install' write the Python version number in the #!

PATCH New Ian Jackson 1 participant 1 message Jun 10, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Have `make install' write the Python version number in the #!

The Xen tools contain a number of Python extensions written in C. The C API to Python, used by these extensions, is not stable from one version of Python to the next.

Our build system uses whatever version of Python is the default on the build system at that time to build these extensions. However, the actual scripts such as `xm' use #!/usr/bin/env python which uses whichever version of Python is the default on the deployment system at the time of invocation.

If for any reason these two versions of Python are not the same (eg, because the system is built on one computer and executed on another, or because the system's gains a more recent Python installation alongside the original which changes the previous default), warnings and failures occur.

In this patch I arrange for Python scripts to be installed via a special wrapper around install', which determines the build-time Python version and path and then writes that into the #! line at the point of make install' (or `make dist'). (It can also be overridden by setting PYTHON_PATH.)

tools/Rules.mk +6 -0
diff -r 7a0f1bf86516 tools/Rules.mk
@@ -35,6 +35,12 @@ CFLAGS-$(CONFIG_X86_32) += $(call cc-opt
 CFLAGS-$(CONFIG_X86_32) += $(call cc-option,$(CC),-mno-tls-direct-seg-refs)
 CFLAGS += $(CFLAGS-y)
 
+ifeq ($(PYTHON_PATH),)
+ # use this construction rather than ?= so we can have := which runs it once
+ PYTHON_PATH := $(shell $(XEN_ROOT)/tools/python/get-path)
+endif
+INSTALL_PYTHON_PROG=$(XEN_ROOT)/tools/python/install-wrap "$(PYTHON_PATH)" $(INSTALL_PROG)
+
 # Require GCC v3.4+ (to avoid issues with alignment constraints in Xen headers)
 check-$(CONFIG_X86) = $(call cc-ver-check,CC,0x030400,\
                         "Xen requires at least gcc-3.4")
tools/misc/Makefile +2 -2
diff -r 7a0f1bf86516 tools/misc/Makefile
@@ -32,8 +32,8 @@ install: build
 install: build
 	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
 	$(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
-	$(INSTALL_PROG) $(INSTALL_BIN) $(DESTDIR)$(BINDIR)
-	$(INSTALL_PROG) $(INSTALL_SBIN) $(DESTDIR)$(SBINDIR)
+	$(INSTALL_PYTHON_PROG) $(INSTALL_BIN) $(DESTDIR)$(BINDIR)
+	$(INSTALL_PYTHON_PROG) $(INSTALL_SBIN) $(DESTDIR)$(SBINDIR)
 	set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d install-recurse; done
 
 .PHONY: clean
tools/python/get-path new file +22 -0
diff -r 7a0f1bf86516 tools/python/get-path
@@ -0,0 +1,22 @@
+#! /usr/bin/env bash
+set -e
+
+check () {
+	set +e
+	p=`type -p python$v`
+	r=$?
+	set -e
+	if [ $r = 0 ]; then
+		echo >&2 "${0##*/}: will use #!$p for python programs"
+		printf "%s\n" "$p"
+		exit 0
+	fi
+}
+
+v="$(python -V 2>&1)"
+v="${v#* }"
+check
+v="${v%.*}"
+check
+echo >&2 'python version not determined, will us env to find python at runtime'
+printf "/usr/bin/env python\n"
tools/python/install-wrap new file +44 -0

44 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel