66import subprocess
77
88
9- TESTS_DIR = os .path .dirname (__file__ )
10- TOOL_ROOT = os .path .dirname (TESTS_DIR )
11- SRCDIR = os .path .dirname (os .path .dirname (TOOL_ROOT ))
9+ TESTS_DIR = os .path .dirname (__file__ )
10+ TOOL_ROOT = os .path .dirname (TESTS_DIR )
11+ SOURCE_DIR = os .path .dirname (os .path .dirname (TOOL_ROOT ))
1212
1313MAKE = shutil .which ('make' )
1414FREEZE = os .path .join (TOOL_ROOT , 'freeze.py' )
@@ -77,7 +77,7 @@ def ensure_opt(args, name, value):
7777def copy_source_tree (newroot , oldroot ):
7878 print (f'copying the source tree into { newroot } ...' )
7979 if os .path .exists (newroot ):
80- if newroot == SRCDIR :
80+ if newroot == SOURCE_DIR :
8181 raise Exception ('this probably isn\' t what you wanted' )
8282 shutil .rmtree (newroot )
8383
@@ -96,9 +96,9 @@ def ignore_non_src(src, names):
9696 if os .path .exists (os .path .join (newroot , 'Makefile' )):
9797 _run_quiet ([MAKE , 'clean' ], newroot )
9898
99- def get_makefile_var (builddir , name ):
99+ def get_makefile_var (final_dir , name ):
100100 regex = re .compile (rf'^{ name } *=\s*(.*?)\s*$' )
101- filename = os .path .join (builddir , 'Makefile' )
101+ filename = os .path .join (final_dir , 'Makefile' )
102102 try :
103103 infile = open (filename , encoding = 'utf-8' )
104104 except FileNotFoundError :
@@ -112,16 +112,16 @@ def get_makefile_var(builddir, name):
112112 return None
113113
114114
115- def get_config_var (builddir , name ):
116- python = os .path .join (builddir , 'python' )
115+ def get_config_var (final_dir , name ):
116+ python = os .path .join (final_dir , 'python' )
117117 if os .path .isfile (python ):
118118 cmd = [python , '-c' ,
119119 f'import sysconfig; print(sysconfig.get_config_var("{ name } "))' ]
120120 try :
121121 return _run_stdout (cmd )
122122 except subprocess .CalledProcessError :
123123 pass
124- return get_makefile_var (builddir , name )
124+ return get_makefile_var (final_dir , name )
125125
126126
127127##################################
@@ -141,23 +141,23 @@ def prepare(script=None, outdir=None):
141141
142142 # Make a copy of the repo to avoid affecting the current build
143143 # (e.g. changing PREFIX).
144- srcdir = os .path .join (outdir , 'cpython' )
145- copy_source_tree (srcdir , SRCDIR )
144+ interim_dir = os .path .join (outdir , 'cpython' )
145+ copy_source_tree (interim_dir , SOURCE_DIR )
146146
147- # We use an out-of-tree build (instead of srcdir ).
148- builddir = os .path .join (outdir , 'python-build' )
149- os .makedirs (builddir , exist_ok = True )
147+ # We use an out-of-tree build (instead of interim_dir ).
148+ final_dir = os .path .join (outdir , 'python-build' )
149+ os .makedirs (final_dir , exist_ok = True )
150150
151151 # Run configure.
152- print (f'configuring python in { builddir } ...' )
152+ print (f'configuring python in { final_dir } ...' )
153153 cmd = [
154- os .path .join (srcdir , 'configure' ),
155- * shlex .split (get_config_var (SRCDIR , 'CONFIG_ARGS' ) or '' ),
154+ os .path .join (interim_dir , 'configure' ),
155+ * shlex .split (get_config_var (SOURCE_DIR , 'CONFIG_ARGS' ) or '' ),
156156 ]
157157 ensure_opt (cmd , 'cache-file' , os .path .join (outdir , 'python-config.cache' ))
158158 prefix = os .path .join (outdir , 'python-installation' )
159159 ensure_opt (cmd , 'prefix' , prefix )
160- _run_quiet (cmd , builddir )
160+ _run_quiet (cmd , final_dir )
161161
162162 if not MAKE :
163163 raise UnsupportedError ('make' )
@@ -172,15 +172,15 @@ def prepare(script=None, outdir=None):
172172 parallel = '-j2'
173173
174174 # Build python.
175- print (f'building python { parallel = } in { builddir } ...' )
176- if os .path .exists (os .path .join (srcdir , 'Makefile' )):
177- # Out-of-tree builds require a clean srcdir .
178- _run_quiet ([MAKE , '-C' , srcdir , 'clean' ])
179- _run_quiet ([MAKE , '-C' , builddir , parallel ])
175+ print (f'building python { parallel = } in { final_dir } ...' )
176+ if os .path .exists (os .path .join (interim_dir , 'Makefile' )):
177+ # Out-of-tree builds require a clean interim_dir .
178+ _run_quiet ([MAKE , '-C' , interim_dir , 'clean' ])
179+ _run_quiet ([MAKE , '-C' , final_dir , parallel ])
180180
181181 # Install the build.
182182 print (f'installing python into { prefix } ...' )
183- _run_quiet ([MAKE , '-C' , builddir , 'install' ])
183+ _run_quiet ([MAKE , '-C' , final_dir , 'install' ])
184184 python = os .path .join (prefix , 'bin' , 'python3' )
185185
186186 return outdir , scriptfile , python
0 commit comments