@@ -211,33 +211,37 @@ def unpack_deps(host, prefix_dir, cache_dir):
211211 for name_ver in ["bzip2-1.0.8-3" , "libffi-3.4.4-3" , "openssl-3.5.5-0" ,
212212 "sqlite-3.50.4-0" , "xz-5.4.6-1" , "zstd-1.5.7-1" ]:
213213 filename = f"{ name_ver } -{ host } .tar.gz"
214- download (f"{ deps_url } /{ name_ver } /{ filename } " , cache_dir )
215- shutil .unpack_archive (filename )
216- os .remove (filename )
214+ out_path = download (f"{ deps_url } /{ name_ver } /{ filename } " , cache_dir )
215+ shutil .unpack_archive (out_path )
217216
218217
219218def download (url , cache_dir ):
220219 out_path = cache_dir / basename (url )
221- run (["curl" , "-Lf" , "--retry" , "5" , "--retry-all-errors" , "-o" , str (out_path ), url ])
220+ if not out_path .is_file ():
221+ run (["curl" , "-Lf" , "--retry" , "5" , "--retry-all-errors" , "-o" , str (out_path ), url ])
222+ else :
223+ print (f"Using cached version of { basename (url )} " )
222224 return out_path
223225
224226
225- def configure_host_python (context ):
227+ def configure_host_python (context , host = None ):
226228 if context .clean :
227229 clean (context .host )
230+ if host is None :
231+ host = context .host
228232
229- host_dir = subdir (context . host , create = True )
233+ host_dir = subdir (host , create = True )
230234 prefix_dir = host_dir / "prefix"
231235 if not prefix_dir .exists ():
232236 prefix_dir .mkdir ()
233- cache_dir = context .cache_dir or CROSS_BUILD_DIR / "downloads"
234- unpack_deps (context . host , prefix_dir , cache_dir )
237+ cache_dir = Path ( context .cache_dir ). resolve () or CROSS_BUILD_DIR / "downloads"
238+ unpack_deps (host , prefix_dir , cache_dir )
235239
236240 os .chdir (host_dir )
237241 command = [
238242 # Basic cross-compiling configuration
239243 relpath (PYTHON_DIR / "configure" ),
240- f"--host={ context . host } " ,
244+ f"--host={ host } " ,
241245 f"--build={ sysconfig .get_config_var ('BUILD_GNU_TYPE' )} " ,
242246 f"--with-build-python={ build_python_path ()} " ,
243247 "--without-ensurepip" ,
@@ -253,14 +257,16 @@ def configure_host_python(context):
253257
254258 if context .args :
255259 command .extend (context .args )
256- run (command , host = context . host )
260+ run (command , host = host )
257261
258262
259- def make_host_python (context ):
263+ def make_host_python (context , host = None ):
264+ if host is None :
265+ host = context .host
260266 # The CFLAGS and LDFLAGS set in android-env include the prefix dir, so
261267 # delete any previous Python installation to prevent it being used during
262268 # the build.
263- host_dir = subdir (context . host )
269+ host_dir = subdir (host )
264270 prefix_dir = host_dir / "prefix"
265271 for pattern in ("include/python*" , "lib/libpython*" , "lib/python*" ):
266272 delete_glob (f"{ prefix_dir } /{ pattern } " )
@@ -279,11 +285,18 @@ def make_host_python(context):
279285 )
280286
281287
282- def build_all (context ):
283- steps = [configure_build_python , make_build_python , configure_host_python ,
284- make_host_python ]
285- for step in steps :
286- step (context )
288+ def build_targets (context ):
289+ if context .target in {"all" , "build" }:
290+ configure_build_python (context )
291+ make_build_python (context )
292+
293+ if context .target == "hosts" :
294+ for host in HOSTS :
295+ configure_host_python (context , host )
296+ make_host_python (context , host )
297+ elif context .target not in {"all" , "build" }:
298+ configure_host_python (context , context .target )
299+ make_host_python (context , context .target )
287300
288301
289302def clean (host ):
@@ -297,7 +310,7 @@ def clean_targets(context):
297310 if context .target == "hosts" :
298311 for host in HOSTS :
299312 clean (host )
300- else :
313+ elif context . target not in { "all" , "build" } :
301314 clean (context .target )
302315
303316
@@ -872,17 +885,6 @@ def add_parser(*args, **kwargs):
872885 "make-host" , help = "Run `make` for Android" )
873886
874887 clean = add_parser ("clean" , help = "Delete all build directories" )
875- clean .add_argument (
876- "target" ,
877- nargs = "?" ,
878- default = "all" ,
879- help = (
880- "The host triple to clean (e.g., aarch64-linux-android), "
881- "or 'build' for just the build platform, or 'hosts' for all "
882- "host platforms, or 'all' for the build platform and all "
883- "hosts. Defaults to 'all'"
884- ),
885- )
886888
887889 add_parser ("build-testbed" , help = "Build the testbed app" )
888890 test = add_parser ("test" , help = "Run the testbed app" )
@@ -930,7 +932,22 @@ def add_parser(*args, **kwargs):
930932 "--clean" , action = "store_true" , default = False , dest = "clean" ,
931933 help = "Delete the relevant build directories first" )
932934
933- host_commands = [build , configure_host , make_host , package , ci ]
935+ # Allow "all" and "hosts" options
936+ for subcommand in [clean , build ]:
937+ subcommand .add_argument (
938+ "target" ,
939+ nargs = "?" ,
940+ default = "all" ,
941+ choices = ["all" , "build" , "hosts" ] + HOSTS ,
942+ help = (
943+ "The host triple to build (e.g., aarch64-linux-android), "
944+ "or 'build' for just the build platform, or 'hosts' for all "
945+ "host platforms, or 'all' for the build platform and all "
946+ "hosts. Defaults to 'all'"
947+ ),
948+ )
949+
950+ host_commands = [configure_host , make_host , package , ci ]
934951 if in_source_tree :
935952 host_commands .append (env )
936953 for subcommand in host_commands :
@@ -1003,7 +1020,7 @@ def main():
10031020 "make-build" : make_build_python ,
10041021 "configure-host" : configure_host_python ,
10051022 "make-host" : make_host_python ,
1006- "build" : build_all ,
1023+ "build" : build_targets ,
10071024 "clean" : clean_targets ,
10081025 "build-testbed" : build_testbed ,
10091026 "test" : run_testbed ,
0 commit comments