Skip to content

Commit

Permalink
- Issue #14330: For cross builds, don't use host python, use host sea…
Browse files Browse the repository at this point in the history
…rch paths

  for host compiler.
  • Loading branch information
doko42 committed Jun 30, 2012
1 parent b457b9b commit 1abe1c5
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 27 deletions.
4 changes: 4 additions & 0 deletions Lib/distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def get_platform ():
return 'win-ia64'
return sys.platform

# Set for cross builds explicitly
if "_PYTHON_HOST_PLATFORM" in os.environ:
return os.environ["_PYTHON_HOST_PLATFORM"]

if os.name != "posix" or not hasattr(os, 'uname'):
# XXX what about the architecture? NT is Intel or Alpha,
# Mac OS is M68k or PPC, etc.
Expand Down
8 changes: 8 additions & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def _safe_realpath(path):
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
_PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))

# set for cross builds
if "_PROJECT_BASE" in os.environ:
_PROJECT_BASE = _safe_realpath(os.environ["_PROJECT_BASE"])

def _is_python_source_dir(d):
for fn in ("Setup.dist", "Setup.local"):
if os.path.isfile(os.path.join(d, "Modules", fn)):
Expand Down Expand Up @@ -673,6 +677,10 @@ def get_platform():
# Mac OS is M68k or PPC, etc.
return sys.platform

# Set for cross builds explicitly
if "_PYTHON_HOST_PLATFORM" in os.environ:
return os.environ["_PYTHON_HOST_PLATFORM"]

# Try to distinguish various flavours of Unix
osname, host, release, version, machine = os.uname()

Expand Down
30 changes: 17 additions & 13 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ LIBOBJS= @LIBOBJS@
PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)

PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
HOST_GNU_TYPE= @host@

# The task to run while instrument when building the profile-opt target
PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
#PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py
Expand Down Expand Up @@ -446,6 +450,7 @@ build_all_generate_profile:
$(MAKE) all CFLAGS="$(CFLAGS) -fprofile-generate" LIBS="$(LIBS) -lgcov"

run_profile_task:
: # FIXME: can't run for a cross build
$(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK)

build_all_use_profile:
Expand All @@ -462,18 +467,17 @@ $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)

platform: $(BUILDPYTHON) $(SYSCONFIGDATA)
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform

# Generate the sysconfig build-time data
$(SYSCONFIGDATA): $(BUILDPYTHON)
$(RUNSHARED) ./$(BUILDPYTHON) -SE -m sysconfig --generate-posix-vars
$(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars

# Build the shared modules
sharedmods: $(BUILDPYTHON) $(SYSCONFIGDATA)
@case $$MAKEFLAGS in \
*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
esac
case $$MAKEFLAGS in *s*) quiet=-q; esac; \
$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build

# Build static library
# avoid long command lines, same as LIBRARY_OBJS
Expand Down Expand Up @@ -1073,25 +1077,25 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
$(DESTDIR)$(LIBDEST)/distutils/tests ; \
fi
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
$(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
$(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
./$(BUILDPYTHON) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
$(PYTHON_FOR_BUILD) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"

# Create the PLATDIR source directory, if one wasn't distributed..
$(srcdir)/Lib/$(PLATDIR):
Expand Down Expand Up @@ -1185,7 +1189,7 @@ libainstall: all python-config
# Install the dynamically loadable modules
# This goes into $(exec_prefix)
sharedinstall: sharedmods
$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
--prefix=$(prefix) \
--install-scripts=$(BINDIR) \
--install-platlib=$(DESTSHARED) \
Expand Down Expand Up @@ -1257,7 +1261,7 @@ frameworkinstallextras:
# This installs a few of the useful scripts in Tools/scripts
scriptsinstall:
SRCDIR=$(srcdir) $(RUNSHARED) \
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/setup.py install \
$(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \
--prefix=$(prefix) \
--install-scripts=$(BINDIR) \
--root=$(DESTDIR)/
Expand Down
52 changes: 52 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ CC
EXPORT_MACOSX_DEPLOYMENT_TARGET
CONFIGURE_MACOSX_DEPLOYMENT_TARGET
SGI_ABI
_PYTHON_HOST_PLATFORM
MACHDEP
FRAMEWORKINSTALLAPPSPREFIX
FRAMEWORKUNIXTOOLSPREFIX
Expand All @@ -700,6 +701,7 @@ UNIVERSALSDK
CONFIG_ARGS
SOVERSION
VERSION
PYTHON_FOR_BUILD
host_os
host_vendor
host_cpu
Expand Down Expand Up @@ -2880,6 +2882,29 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac



if test "$cross_compiling" = yes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python interpreter for cross build" >&5
$as_echo_n "checking for python interpreter for cross build... " >&6; }
if test -z "$PYTHON_FOR_BUILD"; then
for interp in python$PACKAGE_VERSION python3 python; do
which $interp >/dev/null 2>&1 || continue
if $interp -c 'import sys;sys.exit(not sys.version_info[:2] >= (3,3))'; then
break
fi
interp=
done
if test x$interp = x; then
as_fn_error $? "python$PACKAGE_VERSION interpreter not found" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
$as_echo "$interp" >&6; }
PYTHON_FOR_BUILD="_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
fi
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
fi



if test "$prefix" != "/"; then
prefix=`echo "$prefix" | sed -e 's/\/$//g'`
Expand Down Expand Up @@ -3218,6 +3243,29 @@ then
esac
fi


if test "$cross_compiling" = yes; then
case "$host" in
*-*-linux*)
case "$host_cpu" in
arm*)
_host_cpu=arm
;;
*)
_host_cpu=$host_cpu
esac
;;
*-*-cygwin*)
_host_cpu=
;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
as_fn_error $? "cross build not supported for $host" "$LINENO" 5
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
fi

# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
# disable features if it is defined, without any means to access these
# features as extensions. For these systems, we skip the definition of
Expand Down Expand Up @@ -5540,6 +5588,10 @@ else # shared is disabled
esac
fi

if test "$cross_compiling" = yes; then
RUNSHARED=
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDLIBRARY" >&5
$as_echo "$LDLIBRARY" >&6; }

Expand Down
48 changes: 48 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ AC_CONFIG_HEADER(pyconfig.h)

AC_CANONICAL_HOST

if test "$cross_compiling" = yes; then
AC_MSG_CHECKING([for python interpreter for cross build])
if test -z "$PYTHON_FOR_BUILD"; then
for interp in python$PACKAGE_VERSION python3 python; do
which $interp >/dev/null 2>&1 || continue
if $interp -c 'import sys;sys.exit(not sys.version_info@<:@:2@:>@ >= (3,3))'; then
break
fi
interp=
done
if test x$interp = x; then
AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found])
fi
AC_MSG_RESULT($interp)
PYTHON_FOR_BUILD="_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
fi
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
fi
AC_SUBST(PYTHON_FOR_BUILD)

dnl Ensure that if prefix is specified, it does not end in a slash. If
dnl it does, we get path names containing '//' which is both ugly and
dnl can cause trouble.
Expand Down Expand Up @@ -352,6 +373,29 @@ then
'') MACHDEP="unknown";;
esac
fi

AC_SUBST(_PYTHON_HOST_PLATFORM)
if test "$cross_compiling" = yes; then
case "$host" in
*-*-linux*)
case "$host_cpu" in
arm*)
_host_cpu=arm
;;
*)
_host_cpu=$host_cpu
esac
;;
*-*-cygwin*)
_host_cpu=
;;
*)
# for now, limit cross builds to known configurations
MACHDEP="unknown"
AC_MSG_ERROR([cross build not supported for $host])
esac
_PYTHON_HOST_PLATFORM="$MACHDEP${_host_cpu:+-$_host_cpu}"
fi

# Some systems cannot stand _XOPEN_SOURCE being defined at all; they
# disable features if it is defined, without any means to access these
Expand Down Expand Up @@ -913,6 +957,10 @@ else # shared is disabled
esac
fi

if test "$cross_compiling" = yes; then
RUNSHARED=
fi

AC_MSG_RESULT($LDLIBRARY)

AC_PROG_RANLIB
Expand Down
Loading

0 comments on commit 1abe1c5

Please sign in to comment.