Skip to content

Commit cc056ab

Browse files
gh-162308: Check native extension modules with the target interpreter (#162311)
In native builds configured with `--with-build-python`, `checksharedmods` uses the external build Python and can incorrectly report that a module built into the target Python failed to import. Use the newly built Python for extension checks and for generating missing-stdlib information. Cross builds continue to use the external build Python without importing target modules or adding the target library path.
1 parent 518af64 commit cc056ab

5 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,17 @@ jobs:
547547
run: |
548548
"$BUILD_DIR/host-python/bin/python3" -m test test_sysconfig test_site test_embed
549549
- name: Configure cross build
550-
run: ./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
550+
run: |
551+
# Exercise a native build whose builtin modules differ from the build Python.
552+
echo '_bisect _bisectmodule.c' > Modules/Setup.local
553+
./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
551554
- name: Install cross Python
552555
run: make -j8 install
556+
- name: Check native extension modules with a build Python
557+
run: |
558+
"$BUILD_DIR/host-python/bin/python3" -c "import sys; assert '_bisect' not in sys.builtin_module_names"
559+
"$BUILD_DIR/cross-python/bin/python3" -c "import _bisect, sys; assert '_bisect' in sys.builtin_module_names"
560+
PYTHONSTRICTEXTENSIONBUILD=1 make checksharedmods
553561
- name: Display build info
554562
run: |
555563
"$BUILD_DIR/cross-python/bin/python3" -m test.pythoninfo

‎Makefile.pre.in‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ HOSTRUNNER= @HOSTRUNNER@
332332
PYTHON_FOR_REGEN?=@PYTHON_FOR_REGEN@
333333
UPDATE_FILE=$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/update_file.py
334334
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
335+
MODULE_CHECK_COMMAND=@MODULE_CHECK_COMMAND@
335336
# Single-platform builds depend on $(BUILDPYTHON). Cross builds use an
336337
# external "build Python" and have an empty PYTHON_FOR_BUILD_DEPS.
337338
PYTHON_FOR_BUILD_DEPS=@PYTHON_FOR_BUILD_DEPS@
@@ -1605,11 +1606,11 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
16051606
.PHONY: checksharedmods
16061607
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
16071608
@if [ -n "@MISSING_STDLIB_CONFIG@" ]; then \
1608-
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
1609+
$(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
16091610
else \
1610-
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info; \
1611+
$(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info; \
16111612
fi
1612-
@$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py
1613+
@$(MODULE_CHECK_COMMAND)
16131614

16141615
.PHONY: rundsymutil
16151616
rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Use the newly built interpreter to check extension modules in native builds
2+
configured with :option:`--with-build-python`. This also applies when
3+
generating missing standard library module information. Cross builds continue
4+
to use the build interpreter without importing target extension modules.

‎configure‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ AC_ARG_WITH([build-python],
186186
)
187187
AC_SUBST([PYTHON_FOR_BUILD])
188188

189+
# Module import checks must run with the target interpreter on native builds.
190+
AS_VAR_IF([cross_compiling], [yes],
191+
[MODULE_CHECK_COMMAND='$(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --cross-compiling'],
192+
[MODULE_CHECK_COMMAND='$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/Tools/build/check_extension_modules.py --no-cross-compiling']
193+
)
194+
AC_SUBST([MODULE_CHECK_COMMAND])
195+
189196
AC_MSG_CHECKING([for Python interpreter freezing])
190197
AC_MSG_RESULT([$PYTHON_FOR_FREEZE])
191198
AC_SUBST([PYTHON_FOR_FREEZE])

0 commit comments

Comments
 (0)