debuggers.hg

changeset 20650:d820a6b813db

tools: simplify PYTHON_PATH computation (and fixes for NetBSD)

Doesn't work when build-time python path differs from install-time. Do
we care about this given tools should be packaged/built for the
specific run-time distro?

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 09 10:58:52 2009 +0000 (2009-12-09)
parents 9e9746e635f9
children 8f304c003af4
files tools/Rules.mk tools/python/get-path tools/python/install-wrap
line diff
     1.1 --- a/tools/Rules.mk	Wed Dec 09 10:46:11 2009 +0000
     1.2 +++ b/tools/Rules.mk	Wed Dec 09 10:58:52 2009 +0000
     1.3 @@ -49,8 +49,8 @@ check-$(CONFIG_X86) = $(call cc-ver-chec
     1.4                          "Xen requires at least gcc-3.4")
     1.5  $(eval $(check-y))
     1.6  
     1.7 -DEFAULT_PYTHON_PATH := $(shell $(XEN_ROOT)/tools/python/get-path)
     1.8 -PYTHON_PATH ?= $(DEFAULT_PYTHON_PATH)
     1.9 +_PYTHON_PATH := $(shell which $(PYTHON))
    1.10 +PYTHON_PATH ?= $(_PYTHON_PATH)
    1.11  INSTALL_PYTHON_PROG = \
    1.12  	$(XEN_ROOT)/tools/python/install-wrap "$(PYTHON_PATH)" $(INSTALL_PROG)
    1.13  
     2.1 --- a/tools/python/get-path	Wed Dec 09 10:46:11 2009 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,22 +0,0 @@
     2.4 -#! /usr/bin/env bash
     2.5 -set -e
     2.6 -
     2.7 -check () {
     2.8 -	set +e
     2.9 -	p=`type -p python$v`
    2.10 -	r=$?
    2.11 -	set -e
    2.12 -	if [ $r = 0 ]; then
    2.13 -		echo >&2 "${0##*/}: will use #!$p for python programs"
    2.14 -		printf "%s\n" "$p"
    2.15 -		exit 0
    2.16 -	fi
    2.17 -}
    2.18 -
    2.19 -v="$(python -V 2>&1)"
    2.20 -v="${v#* }"
    2.21 -check
    2.22 -v="${v%.*}"
    2.23 -check
    2.24 -echo >&2 'python version not determined, will use env to find python at runtime'
    2.25 -printf "/usr/bin/env python\n"
     3.1 --- a/tools/python/install-wrap	Wed Dec 09 10:46:11 2009 +0000
     3.2 +++ b/tools/python/install-wrap	Wed Dec 09 10:58:52 2009 +0000
     3.3 @@ -1,44 +1,60 @@
     3.4 -#! /usr/bin/env bash
     3.5 +#!/bin/sh
     3.6  # usage:
     3.7  #  .../install-wrap $(PYTHON_PATH) install <options-to-install> <src>... <dest>
     3.8  # where
     3.9  #  PYTHON_PATH is what to put after #! and may be `/usr/bin/env python'
    3.10  #
    3.11 -# Used via $(INSTALL_PYTHON_PROG) in Rules.mk; PYTHON_PATH comes from
    3.12 -# .../get-path alongside this script
    3.13 +# Used via $(INSTALL_PYTHON_PROG) in Rules.mk; PYTHON_PATH comes from $(PYTHON)
    3.14  
    3.15  set -e
    3.16 -if [ $# -lt 2 ]; then echo >&2 "${0##*/}: too few arguments"; exit 1; fi
    3.17 -pythonpath="$1"; shift
    3.18 +if test $# -lt 2; then
    3.19 +	echo >&2 "${0##*/}: too few arguments"
    3.20 +	exit 1
    3.21 +fi
    3.22  
    3.23 -install=("$1"); shift
    3.24 -srcs=()
    3.25 +pythonpath="$1"
    3.26 +shift
    3.27 +
    3.28 +install="$1"
    3.29 +shift
    3.30 +srcs=""
    3.31  
    3.32  while [ $# != 0 ]; do
    3.33  	case "$1" in
    3.34 -	-|--)	install=("${install[@]}" "$1"); shift; break ;;
    3.35 -	-*)	install=("${install[@]}" "$1"); shift ;;
    3.36 -	*)	break ;;
    3.37 +	-|--)	install=`echo "${install} $1"`
    3.38 +		shift
    3.39 +		break
    3.40 +		;;
    3.41 +	-*)	install=`echo "${install} $1"`
    3.42 +		shift
    3.43 +		;;
    3.44 +	*)	break
    3.45 +		;;
    3.46  	esac
    3.47  done
    3.48 -while [ $# -gt 1 ]; do
    3.49 -	srcs=("${srcs[@]}" "$1"); shift
    3.50 +
    3.51 +while test $# -gt 1; do
    3.52 +	srcs=`echo "${srcs} $1"`
    3.53 +	shift
    3.54  done
    3.55 -dest="$1"; shift
    3.56 +
    3.57 +dest="$1"
    3.58 +shift
    3.59  
    3.60  destf="$dest"
    3.61 -for srcf in "${srcs[@]}"; do
    3.62 +for srcf in ${srcs}; do
    3.63  	if test -d "$dest"; then
    3.64 -		destf="$dest/${srcf%%*/}";
    3.65 +		destf="$dest/${srcf%%*/}"
    3.66  	fi
    3.67  	org="$(sed -n '2q; /^#! *\/usr\/bin\/env python *$/p' $srcf)"
    3.68 -	if [ "x$org" = x ]; then
    3.69 -		"${install[@]}" "$srcf" "$destf"
    3.70 +	if test "x$org" = x; then
    3.71 +		eval "${install} $srcf $destf"
    3.72  		continue
    3.73  	fi
    3.74  	tmpf="$destf.tmp"
    3.75 -	"${install[@]}" "$srcf" "$tmpf"
    3.76 +	eval "${install} $srcf $tmpf"
    3.77  	printf >"$tmpf" "#!%s\n" "$pythonpath"
    3.78  	sed -e 1d "$srcf" >>"$tmpf"
    3.79  	mv -f "$tmpf" "$destf"
    3.80  done
    3.81 +exit 0