mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-109615: Fix test_tools.test_freeze SRCDIR (#109935)
Fix copy_source_tree() function of test_tools.test_freeze:
* Don't copy SRC_DIR/build/ anymore. This directory is modified by
other tests running in parallel.
* Add test.support.copy_python_src_ignore().
* Use sysconfig to get the source directory.
* Use sysconfig.get_config_var() to get CONFIG_ARGS variable.
(cherry picked from commit 1512d6c6ee
)
This commit is contained in:
parent
3ab9fdaedb
commit
1fc25a389c
5 changed files with 60 additions and 50 deletions
|
@ -747,7 +747,7 @@ class Regrtest:
|
||||||
if sysconfig.is_python_build():
|
if sysconfig.is_python_build():
|
||||||
self.tmp_dir = sysconfig.get_config_var('abs_builddir')
|
self.tmp_dir = sysconfig.get_config_var('abs_builddir')
|
||||||
if self.tmp_dir is None:
|
if self.tmp_dir is None:
|
||||||
# bpo-30284: On Windows, only srcdir is available. Using
|
# gh-74470: On Windows, only srcdir is available. Using
|
||||||
# abs_builddir mostly matters on UNIX when building Python
|
# abs_builddir mostly matters on UNIX when building Python
|
||||||
# out of the source tree, especially when the source tree
|
# out of the source tree, especially when the source tree
|
||||||
# is read only.
|
# is read only.
|
||||||
|
|
|
@ -2554,3 +2554,29 @@ C_RECURSION_LIMIT = 1500
|
||||||
#Windows doesn't have os.uname() but it doesn't support s390x.
|
#Windows doesn't have os.uname() but it doesn't support s390x.
|
||||||
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
|
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
|
||||||
'skipped on s390x')
|
'skipped on s390x')
|
||||||
|
|
||||||
|
_BASE_COPY_SRC_DIR_IGNORED_NAMES = frozenset({
|
||||||
|
# SRC_DIR/.git
|
||||||
|
'.git',
|
||||||
|
# ignore all __pycache__/ sub-directories
|
||||||
|
'__pycache__',
|
||||||
|
})
|
||||||
|
|
||||||
|
# Ignore function for shutil.copytree() to copy the Python source code.
|
||||||
|
def copy_python_src_ignore(path, names):
|
||||||
|
ignored = _BASE_COPY_SRC_DIR_IGNORED_NAMES
|
||||||
|
if os.path.basename(path) == 'Doc':
|
||||||
|
ignored |= {
|
||||||
|
# SRC_DIR/Doc/build/
|
||||||
|
'build',
|
||||||
|
# SRC_DIR/Doc/venv/
|
||||||
|
'venv',
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if we are at the root of the source code
|
||||||
|
elif 'Modules' in names:
|
||||||
|
ignored |= {
|
||||||
|
# SRC_DIR/build/
|
||||||
|
'build',
|
||||||
|
}
|
||||||
|
return ignored
|
||||||
|
|
|
@ -7,6 +7,7 @@ import socket
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import sysconfig
|
||||||
import tempfile
|
import tempfile
|
||||||
import textwrap
|
import textwrap
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -765,6 +766,27 @@ class TestSupport(unittest.TestCase):
|
||||||
|
|
||||||
#self.assertEqual(available, 2)
|
#self.assertEqual(available, 2)
|
||||||
|
|
||||||
|
def test_copy_python_src_ignore(self):
|
||||||
|
src_dir = sysconfig.get_config_var('srcdir')
|
||||||
|
src_dir = os.path.abspath(src_dir)
|
||||||
|
|
||||||
|
ignored = {'.git', '__pycache__'}
|
||||||
|
|
||||||
|
# Source code directory
|
||||||
|
names = os.listdir(src_dir)
|
||||||
|
self.assertEqual(support.copy_python_src_ignore(src_dir, names),
|
||||||
|
ignored | {'build'})
|
||||||
|
|
||||||
|
# Doc/ directory
|
||||||
|
path = os.path.join(src_dir, 'Doc')
|
||||||
|
self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
|
||||||
|
ignored | {'build', 'venv'})
|
||||||
|
|
||||||
|
# An other directory
|
||||||
|
path = os.path.join(src_dir, 'Objects')
|
||||||
|
self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
|
||||||
|
ignored)
|
||||||
|
|
||||||
# XXX -follows a list of untested API
|
# XXX -follows a list of untested API
|
||||||
# make_legacy_pyc
|
# make_legacy_pyc
|
||||||
# is_resource_enabled
|
# is_resource_enabled
|
||||||
|
|
|
@ -21,7 +21,7 @@ from test.support import (captured_stdout, captured_stderr,
|
||||||
skip_if_broken_multiprocessing_synchronize, verbose,
|
skip_if_broken_multiprocessing_synchronize, verbose,
|
||||||
requires_subprocess, is_emscripten, is_wasi,
|
requires_subprocess, is_emscripten, is_wasi,
|
||||||
requires_venv_with_pip, TEST_HOME_DIR,
|
requires_venv_with_pip, TEST_HOME_DIR,
|
||||||
requires_resource)
|
requires_resource, copy_python_src_ignore)
|
||||||
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
|
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
|
||||||
import unittest
|
import unittest
|
||||||
import venv
|
import venv
|
||||||
|
@ -561,6 +561,7 @@ class BasicTest(BaseTest):
|
||||||
platlibdir,
|
platlibdir,
|
||||||
stdlib_zip)
|
stdlib_zip)
|
||||||
additional_pythonpath_for_non_installed = []
|
additional_pythonpath_for_non_installed = []
|
||||||
|
|
||||||
# Copy stdlib files to the non-installed python so venv can
|
# Copy stdlib files to the non-installed python so venv can
|
||||||
# correctly calculate the prefix.
|
# correctly calculate the prefix.
|
||||||
for eachpath in sys.path:
|
for eachpath in sys.path:
|
||||||
|
@ -577,7 +578,8 @@ class BasicTest(BaseTest):
|
||||||
if os.path.isfile(fn):
|
if os.path.isfile(fn):
|
||||||
shutil.copy(fn, libdir)
|
shutil.copy(fn, libdir)
|
||||||
elif os.path.isdir(fn):
|
elif os.path.isdir(fn):
|
||||||
shutil.copytree(fn, os.path.join(libdir, name))
|
shutil.copytree(fn, os.path.join(libdir, name),
|
||||||
|
ignore=copy_python_src_ignore)
|
||||||
else:
|
else:
|
||||||
additional_pythonpath_for_non_installed.append(
|
additional_pythonpath_for_non_installed.append(
|
||||||
eachpath)
|
eachpath)
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sysconfig
|
||||||
|
from test import support
|
||||||
|
|
||||||
|
|
||||||
TESTS_DIR = os.path.dirname(__file__)
|
TESTS_DIR = os.path.dirname(__file__)
|
||||||
TOOL_ROOT = os.path.dirname(TESTS_DIR)
|
TOOL_ROOT = os.path.dirname(TESTS_DIR)
|
||||||
SRCDIR = os.path.dirname(os.path.dirname(TOOL_ROOT))
|
SRCDIR = os.path.abspath(sysconfig.get_config_var('srcdir'))
|
||||||
|
|
||||||
MAKE = shutil.which('make')
|
MAKE = shutil.which('make')
|
||||||
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')
|
FREEZE = os.path.join(TOOL_ROOT, 'freeze.py')
|
||||||
|
@ -75,56 +76,17 @@ def ensure_opt(args, name, value):
|
||||||
|
|
||||||
|
|
||||||
def copy_source_tree(newroot, oldroot):
|
def copy_source_tree(newroot, oldroot):
|
||||||
print(f'copying the source tree into {newroot}...')
|
print(f'copying the source tree from {oldroot} to {newroot}...')
|
||||||
if os.path.exists(newroot):
|
if os.path.exists(newroot):
|
||||||
if newroot == SRCDIR:
|
if newroot == SRCDIR:
|
||||||
raise Exception('this probably isn\'t what you wanted')
|
raise Exception('this probably isn\'t what you wanted')
|
||||||
shutil.rmtree(newroot)
|
shutil.rmtree(newroot)
|
||||||
|
|
||||||
def ignore_non_src(src, names):
|
shutil.copytree(oldroot, newroot, ignore=support.copy_python_src_ignore)
|
||||||
"""Turns what could be a 1000M copy into a 100M copy."""
|
|
||||||
# Don't copy the ~600M+ of needless git repo metadata.
|
|
||||||
# source only, ignore cached .pyc files.
|
|
||||||
subdirs_to_skip = {'.git', '__pycache__'}
|
|
||||||
if os.path.basename(src) == 'Doc':
|
|
||||||
# Another potential ~250M+ of non test related data.
|
|
||||||
subdirs_to_skip.add('build')
|
|
||||||
subdirs_to_skip.add('venv')
|
|
||||||
return subdirs_to_skip
|
|
||||||
|
|
||||||
shutil.copytree(oldroot, newroot, ignore=ignore_non_src)
|
|
||||||
if os.path.exists(os.path.join(newroot, 'Makefile')):
|
if os.path.exists(os.path.join(newroot, 'Makefile')):
|
||||||
_run_quiet([MAKE, 'clean'], newroot)
|
_run_quiet([MAKE, 'clean'], newroot)
|
||||||
|
|
||||||
|
|
||||||
def get_makefile_var(builddir, name):
|
|
||||||
regex = re.compile(rf'^{name} *=\s*(.*?)\s*$')
|
|
||||||
filename = os.path.join(builddir, 'Makefile')
|
|
||||||
try:
|
|
||||||
infile = open(filename, encoding='utf-8')
|
|
||||||
except FileNotFoundError:
|
|
||||||
return None
|
|
||||||
with infile:
|
|
||||||
for line in infile:
|
|
||||||
m = regex.match(line)
|
|
||||||
if m:
|
|
||||||
value, = m.groups()
|
|
||||||
return value or ''
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_config_var(builddir, name):
|
|
||||||
python = os.path.join(builddir, 'python')
|
|
||||||
if os.path.isfile(python):
|
|
||||||
cmd = [python, '-c',
|
|
||||||
f'import sysconfig; print(sysconfig.get_config_var("{name}"))']
|
|
||||||
try:
|
|
||||||
return _run_stdout(cmd)
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
pass
|
|
||||||
return get_makefile_var(builddir, name)
|
|
||||||
|
|
||||||
|
|
||||||
##################################
|
##################################
|
||||||
# freezing
|
# freezing
|
||||||
|
|
||||||
|
@ -151,10 +113,8 @@ def prepare(script=None, outdir=None):
|
||||||
|
|
||||||
# Run configure.
|
# Run configure.
|
||||||
print(f'configuring python in {builddir}...')
|
print(f'configuring python in {builddir}...')
|
||||||
cmd = [
|
config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '')
|
||||||
os.path.join(srcdir, 'configure'),
|
cmd = [os.path.join(srcdir, 'configure'), *config_args]
|
||||||
*shlex.split(get_config_var(SRCDIR, 'CONFIG_ARGS') or ''),
|
|
||||||
]
|
|
||||||
ensure_opt(cmd, 'cache-file', os.path.join(outdir, 'python-config.cache'))
|
ensure_opt(cmd, 'cache-file', os.path.join(outdir, 'python-config.cache'))
|
||||||
prefix = os.path.join(outdir, 'python-installation')
|
prefix = os.path.join(outdir, 'python-installation')
|
||||||
ensure_opt(cmd, 'prefix', prefix)
|
ensure_opt(cmd, 'prefix', prefix)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue