Skip to content

Commit 3f5b4fa

Browse files
[3.15] gh-162308: Check native extension modules with the target interpreter (GH-162311) (#162560)
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. (cherry picked from commit cc056ab) Co-authored-by: Jeffery <wangshaojun.jeffery@bytedance.com>
1 parent 095599a commit 3f5b4fa

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
@@ -641,9 +641,17 @@ jobs:
641641
run: |
642642
"$BUILD_DIR/host-python/bin/python3" -m test test_sysconfig test_site test_embed
643643
- name: Configure cross build
644-
run: ./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
644+
run: |
645+
# Exercise a native build whose builtin modules differ from the build Python.
646+
echo '_bisect _bisectmodule.c' > Modules/Setup.local
647+
./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
645648
- name: Install cross Python
646649
run: make -j8 install
650+
- name: Check native extension modules with a build Python
651+
run: |
652+
"$BUILD_DIR/host-python/bin/python3" -c "import sys; assert '_bisect' not in sys.builtin_module_names"
653+
"$BUILD_DIR/cross-python/bin/python3" -c "import _bisect, sys; assert '_bisect' in sys.builtin_module_names"
654+
PYTHONSTRICTEXTENSIONBUILD=1 make checksharedmods
647655
- name: Display build info
648656
run: |
649657
"$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
@@ -317,6 +317,7 @@ HOSTRUNNER= @HOSTRUNNER@
317317
PYTHON_FOR_REGEN?=@PYTHON_FOR_REGEN@
318318
UPDATE_FILE=$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/update_file.py
319319
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
320+
MODULE_CHECK_COMMAND=@MODULE_CHECK_COMMAND@
320321
# Single-platform builds depend on $(BUILDPYTHON). Cross builds use an
321322
# external "build Python" and have an empty PYTHON_FOR_BUILD_DEPS.
322323
PYTHON_FOR_BUILD_DEPS=@PYTHON_FOR_BUILD_DEPS@
@@ -1638,11 +1639,11 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
16381639
.PHONY: checksharedmods
16391640
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
16401641
@if [ -n "@MISSING_STDLIB_CONFIG@" ]; then \
1641-
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
1642+
$(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
16421643
else \
1643-
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info; \
1644+
$(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info; \
16441645
fi
1645-
@$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py
1646+
@$(MODULE_CHECK_COMMAND)
16461647

16471648
.PHONY: rundsymutil
16481649
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
@@ -182,6 +182,13 @@ AC_ARG_WITH([build-python],
182182
)
183183
AC_SUBST([PYTHON_FOR_BUILD])
184184

185+
# Module import checks must run with the target interpreter on native builds.
186+
AS_VAR_IF([cross_compiling], [yes],
187+
[MODULE_CHECK_COMMAND='$(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --cross-compiling'],
188+
[MODULE_CHECK_COMMAND='$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/Tools/build/check_extension_modules.py --no-cross-compiling']
189+
)
190+
AC_SUBST([MODULE_CHECK_COMMAND])
191+
185192
AC_MSG_CHECKING([for Python interpreter freezing])
186193
AC_MSG_RESULT([$PYTHON_FOR_FREEZE])
187194
AC_SUBST([PYTHON_FOR_FREEZE])

0 commit comments

Comments
 (0)