Skip to content

Commit 9731330

Browse files
author
doko@python.org
committed
- Issue #15484: Fix _PYTHON_PROJECT_BASE for srcdir != builddir builds;
use _PYTHON_PROJECT_BASE in distutils/sysconfig.py.
1 parent 0c77bf7 commit 9731330

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

Diff for: Lib/distutils/sysconfig.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
# Path to the base directory of the project. On Windows the binary may
2525
# live in project/PCBuild9. If we're dealing with an x64 Windows build,
2626
# it'll live in project/PCbuild/amd64.
27-
project_base = os.path.dirname(os.path.abspath(sys.executable))
27+
# set for cross builds
28+
if "_PYTHON_PROJECT_BASE" in os.environ:
29+
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
30+
else:
31+
project_base = os.path.dirname(os.path.abspath(sys.executable))
2832
if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
2933
project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
3034
# PC/VS7.1
@@ -98,7 +102,7 @@ def get_python_inc(plat_specific=0, prefix=None):
98102
# the build directory may not be the source directory, we
99103
# must use "srcdir" from the makefile to find the "Include"
100104
# directory.
101-
base = _sys_home or os.path.dirname(os.path.abspath(sys.executable))
105+
base = _sys_home or project_base
102106
if plat_specific:
103107
return base
104108
if _sys_home:
@@ -251,8 +255,7 @@ def get_config_h_filename():
251255
def get_makefile_filename():
252256
"""Return full pathname of installed Makefile from the Python build."""
253257
if python_build:
254-
return os.path.join(_sys_home or os.path.dirname(sys.executable),
255-
"Makefile")
258+
return os.path.join(_sys_home or project_base, "Makefile")
256259
lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
257260
config_file = 'config-{}{}'.format(get_python_version(), build_flags)
258261
return os.path.join(lib_dir, config_file, 'Makefile')
@@ -555,7 +558,7 @@ def get_config_vars(*args):
555558
# testing, for example, we might be running a non-installed python
556559
# from a different directory.
557560
if python_build and os.name == "posix":
558-
base = os.path.dirname(os.path.abspath(sys.executable))
561+
base = project_base
559562
if (not os.path.isabs(_config_vars['srcdir']) and
560563
base != os.getcwd()):
561564
# srcdir is relative and we are not in the same directory

Diff for: Misc/NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ Tests
533533
Build
534534
-----
535535

536+
- Issue #15484: Fix _PYTHON_PROJECT_BASE for srcdir != builddir builds;
537+
use _PYTHON_PROJECT_BASE in distutils/sysconfig.py.
538+
536539
- Issue #17029: Let h2py search the multiarch system include directory.
537540

538541
- Issue #16953: Fix socket module compilation on platforms with

Diff for: configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ $as_echo_n "checking for python interpreter for cross build... " >&6; }
29422942
fi
29432943
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $interp" >&5
29442944
$as_echo "$interp" >&6; }
2945-
PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
2945+
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
29462946
fi
29472947
elif test "$cross_compiling" = maybe; then
29482948
as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5

Diff for: configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if test "$cross_compiling" = yes; then
6565
AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found])
6666
fi
6767
AC_MSG_RESULT($interp)
68-
PYTHON_FOR_BUILD="_PYTHON_PROJECT_BASE=$srcdir"' _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
68+
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/plat-$(MACHDEP) '$interp
6969
fi
7070
elif test "$cross_compiling" = maybe; then
7171
AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])

0 commit comments

Comments
 (0)