ia64/xen-unstable

view tools/python/install-wrap @ 17830:b8fa4a11f715

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>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 11 09:36:23 2008 +0100 (2008-06-11)
parents
children
line source
1 #! /usr/bin/env bash
2 # usage:
3 # .../install-wrap $(PYTHON_PATH) install <options-to-install> <src>... <dest>
4 # where
5 # PYTHON_PATH is what to put after #! and may be `/usr/bin/env python'
6 #
7 # Used via $(INSTALL_PYTHON_PROG) in Rules.mk; PYTHON_PATH comes from
8 # .../get-path alongside this script
10 set -e
11 if [ $# -lt 2 ]; then echo >&2 "${0##*/}: too few arguments"; exit 1; fi
12 pythonpath="$1"; shift
14 install=("$1"); shift
15 srcs=()
17 while [ $# != 0 ]; do
18 case "$1" in
19 -|--) install=("${install[@]}" "$1"); shift; break ;;
20 -*) install=("${install[@]}" "$1"); shift ;;
21 *) break ;;
22 esac
23 done
24 while [ $# -gt 1 ]; do
25 srcs=("${srcs[@]}" "$1"); shift
26 done
27 dest="$1"; shift
29 destf="$dest"
30 for srcf in "${srcs[@]}"; do
31 if test -d "$dest"; then
32 destf="$dest/${srcf%%*/}";
33 fi
34 org="$(sed -n '2q; /^#! *\/usr\/bin\/env python *$/p' $srcf)"
35 if [ "x$org" = x ]; then
36 "${install[@]}" "$srcf" "$destf"
37 continue
38 fi
39 tmpf="$destf.tmp"
40 "${install[@]}" "$srcf" "$tmpf"
41 printf >"$tmpf" "#!%s\n" "$pythonpath"
42 sed -e 1d "$srcf" >>"$tmpf"
43 mv -f "$tmpf" "$destf"
44 done