@@ -923,8 +923,7 @@ def real_hostpython_location(self):
923923 if host_name == 'hostpython3' :
924924 return self ._host_recipe .python_exe
925925 else :
926- python_recipe = self .ctx .python_recipe
927- return 'python{}' .format (python_recipe .version )
926+ return 'python{}' .format (self .ctx .python_recipe .version )
928927
929928 @property
930929 def hostpython_location (self ):
@@ -1248,6 +1247,55 @@ class PyProjectRecipe(PythonRecipe):
12481247 extra_build_args = []
12491248 call_hostpython_via_targetpython = False
12501249
1250+ def get_pip_name (self ):
1251+ name_str = self .name
1252+ if self .name not in self .ctx .use_prebuilt_version_for :
1253+ name_str += f"=={ self .version } "
1254+ return name_str
1255+
1256+ def get_pip_install_args (self , arch ):
1257+ python_recipe = Recipe .get_recipe ("python3" , self .ctx )
1258+ opts = [
1259+ "install" ,
1260+ self .get_pip_name (),
1261+ "--disable-pip-version-check" ,
1262+ "--python-version" ,
1263+ python_recipe .version ,
1264+ "--only-binary=:all:" ,
1265+ ]
1266+ # add platform tags
1267+ tags = self .get_wheel_platform_tag (arch .arch )
1268+ for tag in tags :
1269+ opts .append (f"--platform={ tag } " )
1270+
1271+ # add extra index urls
1272+ for index in self .ctx .extra_index_urls :
1273+ opts .extend (["--extra-index-url" , index ])
1274+
1275+ return opts
1276+
1277+ def lookup_prebuilt (self , arch ):
1278+ pip_options = self .get_pip_install_args (arch )
1279+ # do not install
1280+ pip_options .extend (["--dry-run" ])
1281+ pip_env = self .get_hostrecipe_env ()
1282+ try :
1283+ shprint (self ._host_recipe .pip , * pip_options , _env = pip_env )
1284+ except Exception as e :
1285+ warning (f"Lookup fail result: { e } " )
1286+ return False
1287+ return True
1288+
1289+ def check_prebuilt (self , arch , msg = "" ):
1290+ if self .ctx .skip_prebuilt :
1291+ return False
1292+
1293+ if self .lookup_prebuilt (arch ):
1294+ if msg != "" :
1295+ info (f"Prebuilt pip wheel found, { msg } " )
1296+ return True
1297+ return
1298+
12511299 def get_recipe_env (self , arch , ** kwargs ):
12521300 # Custom hostpython
12531301 self .ctx .python_recipe .python_exe = join (
@@ -1259,24 +1307,40 @@ def get_recipe_env(self, arch, **kwargs):
12591307
12601308 with open (build_opts , "w" ) as file :
12611309 file .write ("[bdist_wheel]\n plat_name={}" .format (
1262- self .get_wheel_platform_tag (arch )
1310+ self .get_wheel_platform_tag (arch . arch )[ 0 ]
12631311 ))
12641312 file .close ()
12651313
12661314 env ["DIST_EXTRA_CONFIG" ] = build_opts
12671315 return env
12681316
1269- def get_wheel_platform_tag (self , arch ):
1317+ def get_wheel_platform_tag (self , arch , ctx = None ):
1318+ if ctx is None :
1319+ ctx = self .ctx
12701320 # https://peps.python.org/pep-0738/#packaging
12711321 # official python only supports 64 bit:
12721322 # android_21_arm64_v8a
12731323 # android_21_x86_64
1274- return f"android_{ self .ctx .ndk_api } _" + {
1275- "arm64-v8a" : "arm64_v8a" ,
1276- "x86_64" : "x86_64" ,
1277- "armeabi-v7a" : "arm" ,
1278- "x86" : "i686" ,
1279- }[arch .arch ]
1324+ _suffix = {
1325+ "arm64-v8a" : ["arm64_v8a" , "aarch64" ],
1326+ "x86_64" : ["x86_64" ],
1327+ "armeabi-v7a" : ["arm" ],
1328+ "x86" : ["i686" ],
1329+ }[arch ]
1330+ return [f"android_{ ctx .ndk_api } _" + _ for _ in _suffix ]
1331+
1332+ def install_prebuilt_wheel (self , arch ):
1333+ info ("Installing prebuilt built wheel" )
1334+ destination = self .ctx .get_python_install_dir (arch .arch )
1335+ pip_options = self .get_pip_install_args (arch )
1336+ pip_options .extend (["--target" , destination ])
1337+ pip_options .append ("--upgrade" )
1338+ pip_env = self .get_hostrecipe_env ()
1339+ try :
1340+ shprint (self ._host_recipe .pip , * pip_options , _env = pip_env )
1341+ except Exception :
1342+ return False
1343+ return True
12801344
12811345 def install_wheel (self , arch , built_wheels ):
12821346 with patch_wheel_setuptools_logging ():
@@ -1287,7 +1351,7 @@ def install_wheel(self, arch, built_wheels):
12871351 # Fix wheel platform tag
12881352 wheel_tag = wheel_tags (
12891353 _wheel ,
1290- platform_tags = self .get_wheel_platform_tag (arch ) ,
1354+ platform_tags = self .get_wheel_platform_tag (arch . arch )[ 0 ] ,
12911355 remove = True ,
12921356 )
12931357 selected_wheel = join (built_wheel_dir , wheel_tag )
@@ -1305,6 +1369,11 @@ def install_wheel(self, arch, built_wheels):
13051369 wf .close ()
13061370
13071371 def build_arch (self , arch ):
1372+ if self .check_prebuilt (arch , "skipping build_arch" ) is not None :
1373+ result = self .install_prebuilt_wheel (arch )
1374+ if result :
1375+ return
1376+ warning ("Failed to install prebuilt wheel, falling back to build_arch" )
13081377
13091378 build_dir = self .get_build_dir (arch .arch )
13101379 if not (isfile (join (build_dir , "pyproject.toml" )) or isfile (join (build_dir , "setup.py" ))):
0 commit comments