aboutsummaryrefslogtreecommitdiffstats
path: root/tools/python/install-wrap
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-06-11 09:36:23 +0100
committerKeir Fraser <keir.fraser@citrix.com>2008-06-11 09:36:23 +0100
commit9f88f46834abd8bac0605f59c39b0e6ea51b1dfa (patch)
tree72f9a6db129e3a9997b69de7aa4ae7e6fac1c243 /tools/python/install-wrap
parentba65563c1bbad1d353c2493f65f41e6d62e6a2a0 (diff)
downloadxen-9f88f46834abd8bac0605f59c39b0e6ea51b1dfa.tar.gz
xen-9f88f46834abd8bac0605f59c39b0e6ea51b1dfa.tar.bz2
xen-9f88f46834abd8bac0605f59c39b0e6ea51b1dfa.zip
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.) Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/python/install-wrap')
-rwxr-xr-xtools/python/install-wrap44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/python/install-wrap b/tools/python/install-wrap
new file mode 100755
index 0000000000..29db25d1a7
--- /dev/null
+++ b/tools/python/install-wrap
@@ -0,0 +1,44 @@
+#! /usr/bin/env bash
+# usage:
+# .../install-wrap $(PYTHON_PATH) install <options-to-install> <src>... <dest>
+# where
+# PYTHON_PATH is what to put after #! and may be `/usr/bin/env python'
+#
+# Used via $(INSTALL_PYTHON_PROG) in Rules.mk; PYTHON_PATH comes from
+# .../get-path alongside this script
+
+set -e
+if [ $# -lt 2 ]; then echo >&2 "${0##*/}: too few arguments"; exit 1; fi
+pythonpath="$1"; shift
+
+install=("$1"); shift
+srcs=()
+
+while [ $# != 0 ]; do
+ case "$1" in
+ -|--) install=("${install[@]}" "$1"); shift; break ;;
+ -*) install=("${install[@]}" "$1"); shift ;;
+ *) break ;;
+ esac
+done
+while [ $# -gt 1 ]; do
+ srcs=("${srcs[@]}" "$1"); shift
+done
+dest="$1"; shift
+
+destf="$dest"
+for srcf in "${srcs[@]}"; do
+ if test -d "$dest"; then
+ destf="$dest/${srcf%%*/}";
+ fi
+ org="$(sed -n '2q; /^#! *\/usr\/bin\/env python *$/p' $srcf)"
+ if [ "x$org" = x ]; then
+ "${install[@]}" "$srcf" "$destf"
+ continue
+ fi
+ tmpf="$destf.tmp"
+ "${install[@]}" "$srcf" "$tmpf"
+ printf >"$tmpf" "#!%s\n" "$pythonpath"
+ sed -e 1d "$srcf" >>"$tmpf"
+ mv -f "$tmpf" "$destf"
+done