Skip to content

Commit b16269e

Browse files
committed
Merge issue python#15298: ensure _sysconfigdata is generated in build directory,
not source directory. Patch by: Richard Oudkerk (sbt).
2 parents 744fadd + c101bf3 commit b16269e

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

Lib/sysconfig.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,22 @@ def _generate_posix_vars():
371371
if _PYTHON_BUILD:
372372
vars['LDSHARED'] = vars['BLDSHARED']
373373

374-
destfile = os.path.join(os.path.dirname(__file__), '_sysconfigdata.py')
374+
pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
375+
if hasattr(sys, "gettotalrefcount"):
376+
pybuilddir += '-pydebug'
377+
os.makedirs(pybuilddir, exist_ok=True)
378+
destfile = os.path.join(pybuilddir, '_sysconfigdata.py')
379+
375380
with open(destfile, 'w', encoding='utf8') as f:
376381
f.write('# system configuration generated and used by'
377382
' the sysconfig module\n')
378383
f.write('build_time_vars = ')
379384
pprint.pprint(vars, stream=f)
380385

386+
# Create file used for sys.path fixup -- see Modules/getpath.c
387+
with open('pybuilddir.txt', 'w', encoding='ascii') as f:
388+
f.write(pybuilddir)
389+
381390
def _init_posix(vars):
382391
"""Initialize the module as appropriate for POSIX systems."""
383392
# _sysconfigdata is generated at build time, see _generate_posix_vars()

Makefile.pre.in

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ OBJECT_OBJS= \
410410
Objects/unicodectype.o \
411411
Objects/weakrefobject.o
412412

413-
SYSCONFIGDATA=$(srcdir)/Lib/_sysconfigdata.py
414-
415413
##########################################################################
416414
# objects that get linked into the Python library
417415
LIBRARY_OBJS_OMIT_FROZEN= \
@@ -432,7 +430,7 @@ LIBRARY_OBJS= \
432430

433431
# Default target
434432
all: build_all
435-
build_all: $(BUILDPYTHON) $(SYSCONFIGDATA) oldsharedmods sharedmods gdbhooks Modules/_testembed
433+
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed
436434

437435
# Compile a binary with gcc profile guided optimization.
438436
profile-opt:
@@ -466,17 +464,19 @@ coverage:
466464
$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
467465
$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
468466

469-
platform: $(BUILDPYTHON) $(SYSCONFIGDATA)
467+
platform: $(BUILDPYTHON) pybuilddir.txt
470468
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
471469

472-
# Generate the sysconfig build-time data
473-
$(SYSCONFIGDATA): $(BUILDPYTHON)
470+
# Create build directory and generate the sysconfig build-time data there.
471+
# pybuilddir.txt contains the name of the build dir and is used for
472+
# sys.path fixup -- see Modules/getpath.c.
473+
pybuilddir.txt: $(BUILDPYTHON)
474474
$(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars
475475

476476
# Build the shared modules
477477
# MAKEFLAGS are sorted and normalized. Under GNU make the 's' for
478478
# -s, --silent or --quiet is always the first char.
479-
sharedmods: $(BUILDPYTHON) $(SYSCONFIGDATA)
479+
sharedmods: $(BUILDPYTHON) pybuilddir.txt
480480
@case "$$MAKEFLAGS" in \
481481
s*) quiet="-q";; \
482482
*) quiet="";; \
@@ -1043,7 +1043,7 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
10431043
else true; \
10441044
fi; \
10451045
done
1046-
@for i in $(srcdir)/Lib/*.py ; \
1046+
@for i in $(srcdir)/Lib/*.py `cat pybuilddir.txt`/_sysconfigdata.py; \
10471047
do \
10481048
if test -x $$i; then \
10491049
$(INSTALL_SCRIPT) $$i $(DESTDIR)$(LIBDEST); \
@@ -1203,6 +1203,8 @@ sharedinstall: sharedmods
12031203
--install-scripts=$(BINDIR) \
12041204
--install-platlib=$(DESTSHARED) \
12051205
--root=$(DESTDIR)/
1206+
-rm $(DESTDIR)$(DESTSHARED)/_sysconfigdata.py
1207+
-rm -r $(DESTDIR)$(DESTSHARED)/__pycache__
12061208

12071209
# Here are a couple of targets for MacOSX again, to install a full
12081210
# framework-based Python. frameworkinstall installs everything, the
@@ -1348,9 +1350,10 @@ clean: pycremoval
13481350
find . -name '*.s[ol]' -exec rm -f {} ';'
13491351
find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'
13501352
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
1351-
find build -name 'fficonfig.py' -exec rm -f {} ';' || true
1353+
find build -name '*.py' -exec rm -f {} ';' || true
1354+
find build -name '*.py[co]' -exec rm -f {} ';' || true
1355+
-rm -f pybuilddir.txt
13521356
-rm -f Lib/lib2to3/*Grammar*.pickle
1353-
-rm -f $(SYSCONFIGDATA)
13541357
-rm -f Modules/_testembed Modules/_freeze_importlib
13551358

13561359
profile-removal:
@@ -1374,7 +1377,6 @@ distclean: clobber
13741377
Modules/Setup Modules/Setup.local Modules/Setup.config \
13751378
Modules/ld_so_aix Modules/python.exp Misc/python.pc
13761379
-rm -f python*-gdb.py
1377-
-rm -f pybuilddir.txt
13781380
find $(srcdir) '(' -name '*.fdc' -o -name '*~' \
13791381
-o -name '[@,#]*' -o -name '*.old' \
13801382
-o -name '*.orig' -o -name '*.rej' \

Misc/NEWS

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ Tests
158158
Build
159159
-----
160160

161+
- Issue #15298: ensure _sysconfigdata is generated in build directory, not
162+
source directory.
163+
161164
- Issue #15833: Fix a regression in 3.3 that resulted in exceptions being
162165
raised if importlib failed to write byte-compiled files. This affected
163166
attempts to build Python out-of-tree from a read-only source directory.
@@ -167,8 +170,8 @@ Build
167170

168171
- Issue #16135: Remove OS/2 support.
169172

170-
- Issue #15819: Make sure we can build Python out-of-tree from a readonly source
171-
directory. (Somewhat related to Issue #9860.)
173+
- Issue #15819: Make sure we can build Python out-of-tree from a read-only
174+
source directory. (Somewhat related to issue #9860.)
172175

173176
Documentation
174177
-------------

setup.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ def get_platform():
3333
# This global variable is used to hold the list of modules to be disabled.
3434
disabled_module_list = []
3535

36-
# File which contains the directory for shared mods (for sys.path fixup
37-
# when running from the build dir, see Modules/getpath.c)
38-
_BUILDDIR_COOKIE = "pybuilddir.txt"
39-
4036
def add_dir_to_list(dirlist, dir):
4137
"""Add the directory 'dir' to the list 'dirlist' (after any relative
4238
directories) if:
@@ -252,16 +248,6 @@ def build_extensions(self):
252248
args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
253249
self.compiler.set_executables(**args)
254250

255-
# Not only do we write the builddir cookie, but we manually install
256-
# the shared modules directory if it isn't already in sys.path.
257-
# Otherwise trying to import the extensions after building them
258-
# will fail.
259-
with open(_BUILDDIR_COOKIE, "wb") as f:
260-
f.write(self.build_lib.encode('utf-8', 'surrogateescape'))
261-
abs_build_lib = os.path.join(os.getcwd(), self.build_lib)
262-
if abs_build_lib not in sys.path:
263-
sys.path.append(abs_build_lib)
264-
265251
build_ext.build_extensions(self)
266252

267253
longest = max([len(e.name) for e in self.extensions])

0 commit comments

Comments
 (0)