Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a62cdb

Browse files
committed
gh-103053: Fix test_tools.test_freeze on FreeBSD
Fix test_tools.test_freeze on FreeBSD: run "make distclean" instead of "make clean" in the copied source directory to remove also the "python" program. Other test_freeze changes: * Log executed commands and directories, and the current directory. * No longer uses make -C option to change the directory, instead use subprocess cwd parameter.
1 parent 3c0f65e commit 3a62cdb

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix test_tools.test_freeze on FreeBSD: run "make distclean" instead of "make
2+
clean" in the copied source directory to remove also the "python" program.
3+
Patch by Victor Stinner.

Tools/freeze/test/freeze.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ class UnsupportedError(Exception):
2727
"""The operation isn't supported."""
2828

2929

30-
def _run_quiet(cmd, cwd=None):
31-
#print(f'# {" ".join(shlex.quote(a) for a in cmd)}')
30+
def _run_quiet(cmd, *, cwd=None):
31+
if cwd:
32+
print('+', 'cd', cwd, flush=True)
33+
print('+', shlex.join(cmd), flush=True)
3234
try:
3335
return subprocess.run(
3436
cmd,
@@ -48,8 +50,8 @@ def _run_quiet(cmd, cwd=None):
4850
raise
4951

5052

51-
def _run_stdout(cmd, cwd=None):
52-
proc = _run_quiet(cmd, cwd)
53+
def _run_stdout(cmd):
54+
proc = _run_quiet(cmd)
5355
return proc.stdout.strip()
5456

5557

@@ -91,13 +93,18 @@ def copy_source_tree(newroot, oldroot):
9193

9294
shutil.copytree(oldroot, newroot, ignore=support.copy_python_src_ignore)
9395
if os.path.exists(os.path.join(newroot, 'Makefile')):
94-
_run_quiet([MAKE, 'clean'], newroot)
96+
# Out-of-tree builds require a clean srcdir. "make clean" keeps
97+
# the "python" program, so use "make distclean" instead.
98+
_run_quiet([MAKE, 'distclean'], cwd=newroot)
9599

96100

97101
##################################
98102
# freezing
99103

100104
def prepare(script=None, outdir=None):
105+
print()
106+
print("cwd:", os.getcwd())
107+
101108
if not outdir:
102109
outdir = OUTDIR
103110
os.makedirs(outdir, exist_ok=True)
@@ -125,7 +132,7 @@ def prepare(script=None, outdir=None):
125132
ensure_opt(cmd, 'cache-file', os.path.join(outdir, 'python-config.cache'))
126133
prefix = os.path.join(outdir, 'python-installation')
127134
ensure_opt(cmd, 'prefix', prefix)
128-
_run_quiet(cmd, builddir)
135+
_run_quiet(cmd, cwd=builddir)
129136

130137
if not MAKE:
131138
raise UnsupportedError('make')
@@ -135,20 +142,18 @@ def prepare(script=None, outdir=None):
135142
# this test is most often run as part of the whole suite with a lot
136143
# of other tests running in parallel, from 1-2 vCPU systems up to
137144
# people's NNN core beasts. Don't attempt to use it all.
138-
parallel = f'-j{cores*2//3}'
145+
jobs = cores * 2 // 3
146+
parallel = f'-j{jobs}'
139147
else:
140148
parallel = '-j2'
141149

142150
# Build python.
143151
print(f'building python {parallel=} in {builddir}...')
144-
if os.path.exists(os.path.join(srcdir, 'Makefile')):
145-
# Out-of-tree builds require a clean srcdir.
146-
_run_quiet([MAKE, '-C', srcdir, 'clean'])
147-
_run_quiet([MAKE, '-C', builddir, parallel])
152+
_run_quiet([MAKE, parallel], cwd=builddir)
148153

149154
# Install the build.
150155
print(f'installing python into {prefix}...')
151-
_run_quiet([MAKE, '-C', builddir, 'install'])
156+
_run_quiet([MAKE, 'install'], cwd=builddir)
152157
python = os.path.join(prefix, 'bin', 'python3')
153158

154159
return outdir, scriptfile, python
@@ -161,8 +166,8 @@ def freeze(python, scriptfile, outdir):
161166
print(f'freezing {scriptfile}...')
162167
os.makedirs(outdir, exist_ok=True)
163168
# Use -E to ignore PYTHONSAFEPATH
164-
_run_quiet([python, '-E', FREEZE, '-o', outdir, scriptfile], outdir)
165-
_run_quiet([MAKE, '-C', os.path.dirname(scriptfile)])
169+
_run_quiet([python, '-E', FREEZE, '-o', outdir, scriptfile], cwd=outdir)
170+
_run_quiet([MAKE], cwd=os.path.dirname(scriptfile))
166171

167172
name = os.path.basename(scriptfile).rpartition('.')[0]
168173
executable = os.path.join(outdir, name)

0 commit comments

Comments
 (0)