@@ -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
100104def 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