annotate tools/python/get-path @ 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)
rev   line source
keir@17830 1 #! /usr/bin/env bash
keir@17830 2 set -e
keir@17830 3
keir@17830 4 check () {
keir@17830 5 set +e
keir@17830 6 p=`type -p python$v`
keir@17830 7 r=$?
keir@17830 8 set -e
keir@17830 9 if [ $r = 0 ]; then
keir@17830 10 echo >&2 "${0##*/}: will use #!$p for python programs"
keir@17830 11 printf "%s\n" "$p"
keir@17830 12 exit 0
keir@17830 13 fi
keir@17830 14 }
keir@17830 15
keir@17830 16 v="$(python -V 2>&1)"
keir@17830 17 v="${v#* }"
keir@17830 18 check
keir@17830 19 v="${v%.*}"
keir@17830 20 check
keir@17830 21 echo >&2 'python version not determined, will use env to find python at runtime'
keir@17830 22 printf "/usr/bin/env python\n"