Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,24 @@ jobs:
run: |
"$BUILD_DIR/host-python/bin/python3" -m test test_sysconfig test_site test_embed
- name: Configure cross build
run: ./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
run: |
# Exercise a native build whose builtin modules differ from the build Python.
echo '_bisect _bisectmodule.c' > Modules/Setup.local
./configure --prefix="$BUILD_DIR/cross-python" --with-build-python="$BUILD_DIR/host-python/bin/python3"
- name: Install cross Python
run: make -j8 install
- name: Check native extension modules with a build Python
run: |
"$BUILD_DIR/host-python/bin/python3" -c "import sys; assert '_bisect' not in sys.builtin_module_names"
"$BUILD_DIR/cross-python/bin/python3" -c "import _bisect, sys; assert '_bisect' in sys.builtin_module_names"
# checksharedmods must use the newly built target interpreter and enforce native import checks
recipe=$(make -n checksharedmods)
echo "$recipe" | grep -F -- '--no-cross-compiling'
if echo "$recipe" | grep -F "$BUILD_DIR/host-python"; then
echo "Error: checksharedmods incorrectly invoked the build Python" >&2
exit 1
fi
PYTHONSTRICTEXTENSIONBUILD=1 make checksharedmods
- name: Display build info
run: |
"$BUILD_DIR/cross-python/bin/python3" -m test.pythoninfo
Expand Down
39 changes: 39 additions & 0 deletions Lib/test/test_tools/test_makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,42 @@ def test_makefile_test_folders(self):
unique_test_dirs = set(test_dirs)
self.assertSetEqual(unique_test_dirs, used)
self.assertEqual(len(test_dirs), len(unique_test_dirs))

def test_makefile_module_check_command(self):
vars = {}
with open(MAKEFILE, 'r', encoding='utf-8') as f:
for line in f:
if '=' in line and not line.startswith(('\t', ' ', '#')):
key, _, val = line.partition('=')
vars[key.strip()] = val.strip()

self.assertIn('MODULE_CHECK_COMMAND', vars)
cmd = vars['MODULE_CHECK_COMMAND']
tokens = cmd.split()
if vars.get('_PYTHON_HOST_PLATFORM'):
self.assertIn('--cross-compiling', tokens)
self.assertNotIn('--no-cross-compiling', tokens)
self.assertIn('PYTHON_FOR_BUILD', cmd)
else:
self.assertIn('--no-cross-compiling', tokens)
self.assertNotIn('--cross-compiling', tokens)
self.assertIn('BUILDPYTHON', cmd)

def test_makefile_checksharedmods_recipe(self):
"""Ensure checksharedmods recipe uses $(RUNSHARED_FOR_BUILD) $(MODULE_CHECK_COMMAND)."""
found_target = False
found_recipe = False
with open(MAKEFILE, 'r', encoding='utf-8') as f:
for line in f:
if line.startswith('checksharedmods:'):
found_target = True
elif found_target:
if line.startswith(('\t', ' ')):
if 'MODULE_CHECK_COMMAND' in line:
found_recipe = True
self.assertIn('$(RUNSHARED_FOR_BUILD) $(MODULE_CHECK_COMMAND)', line)
self.assertNotIn('$(RUNSHARED) $(MODULE_CHECK_COMMAND)', line)
else:
break
self.assertTrue(found_target, "checksharedmods target not found in Makefile")
self.assertTrue(found_recipe, "MODULE_CHECK_COMMAND not invoked in checksharedmods recipe")
7 changes: 4 additions & 3 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ HOSTRUNNER= @HOSTRUNNER@
PYTHON_FOR_REGEN?=@PYTHON_FOR_REGEN@
UPDATE_FILE=$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/update_file.py
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
MODULE_CHECK_COMMAND=@MODULE_CHECK_COMMAND@
# Single-platform builds depend on $(BUILDPYTHON). Cross builds use an
# external "build Python" and have an empty PYTHON_FOR_BUILD_DEPS.
PYTHON_FOR_BUILD_DEPS=@PYTHON_FOR_BUILD_DEPS@
Expand Down Expand Up @@ -1605,11 +1606,11 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
.PHONY: checksharedmods
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
@if [ -n "@MISSING_STDLIB_CONFIG@" ]; then \
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
$(RUNSHARED_FOR_BUILD) $(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info --with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
else \
$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info; \
$(RUNSHARED_FOR_BUILD) $(MODULE_CHECK_COMMAND) --generate-missing-stdlib-info; \
fi
@$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py
@$(RUNSHARED_FOR_BUILD) $(MODULE_CHECK_COMMAND)

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ AC_ARG_WITH([build-python],
)
AC_SUBST([PYTHON_FOR_BUILD])

# Module import checks must run with the target interpreter on native builds.
AS_VAR_IF([cross_compiling], [yes],
[MODULE_CHECK_COMMAND='$(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py --cross-compiling'],
[MODULE_CHECK_COMMAND='./$(BUILDPYTHON) -E $(srcdir)/Tools/build/check_extension_modules.py --no-cross-compiling']
)
AC_SUBST([MODULE_CHECK_COMMAND])

AC_MSG_CHECKING([for Python interpreter freezing])
AC_MSG_RESULT([$PYTHON_FOR_FREEZE])
AC_SUBST([PYTHON_FOR_FREEZE])
Expand Down
Loading