11import platform
22import sys
33import os
4+ import shutil
5+ import subprocess
46
57# TODO: In next version, it will be a JSON file listing all the patches, and then it will iterate through to apply them.
68def patch_android ():
@@ -18,8 +20,8 @@ def patch_android():
1820 patch_android ()
1921 sys .exit (0 )
2022
21- if len (sys .argv ) != 4 :
22- print ("Usage: ./android-configure [patch] <path to the Android NDK> <Android SDK version> <target architecture>" )
23+ if len (sys .argv ) < 4 :
24+ print ("Usage: ./android-configure [patch] <path to the Android NDK> <Android SDK version> <target architecture> [configure options...] " )
2325 sys .exit (1 )
2426
2527if not os .path .exists (sys .argv [1 ]) or not os .listdir (sys .argv [1 ]):
@@ -33,6 +35,7 @@ def patch_android():
3335android_ndk_path = sys .argv [1 ]
3436android_sdk_version = sys .argv [2 ]
3537arch = sys .argv [3 ]
38+ configure_options = sys .argv [4 :]
3639
3740if arch == "arm" :
3841 DEST_CPU = "arm"
@@ -63,8 +66,26 @@ def patch_android():
6366 toolchain_path = android_ndk_path + "/toolchains/llvm/prebuilt/linux-x86_64"
6467
6568os .environ ['PATH' ] += os .pathsep + toolchain_path + "/bin"
66- os .environ ['CC' ] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang"
67- os .environ ['CXX' ] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang++"
69+ target_cc = os .path .join (toolchain_path , "bin" ,
70+ TOOLCHAIN_PREFIX + android_sdk_version + "-clang" )
71+ target_cxx = os .path .join (toolchain_path , "bin" ,
72+ TOOLCHAIN_PREFIX + android_sdk_version + "-clang++" )
73+
74+ # configure.py uses CC/CXX for compiler detection, while GYP uses the
75+ # toolset-specific variables when generating host and target rules.
76+ os .environ ['CC_target' ] = (os .environ .get ('CC_target' ) or
77+ os .environ .get ('CC' ) or target_cc )
78+ os .environ ['CXX_target' ] = (os .environ .get ('CXX_target' ) or
79+ os .environ .get ('CXX' ) or target_cxx )
80+ os .environ ['CC' ] = os .environ ['CC_target' ]
81+ os .environ ['CXX' ] = os .environ ['CXX_target' ]
82+
83+ host_cc_name = 'cc' if platform .system () == "Darwin" else 'gcc'
84+ host_cxx_name = 'c++' if platform .system () == "Darwin" else 'g++'
85+ os .environ ['CC_host' ] = (os .environ .get ('CC_host' ) or
86+ shutil .which (host_cc_name ) or host_cc_name )
87+ os .environ ['CXX_host' ] = (os .environ .get ('CXX_host' ) or
88+ shutil .which (host_cxx_name ) or host_cxx_name )
6889
6990GYP_DEFINES = "target_arch=" + arch
7091GYP_DEFINES += " v8_target_arch=" + arch
@@ -74,4 +95,11 @@ def patch_android():
7495os .environ ['GYP_DEFINES' ] = GYP_DEFINES
7596
7697if os .path .exists ("./configure" ):
77- os .system ("./configure --dest-cpu=" + DEST_CPU + " --dest-os=android --openssl-no-asm --cross-compiling" )
98+ command = [
99+ "./configure" ,
100+ "--dest-cpu=" + DEST_CPU ,
101+ "--dest-os=android" ,
102+ "--openssl-no-asm" ,
103+ "--cross-compiling" ,
104+ ] + configure_options
105+ subprocess .run (command , check = True )
0 commit comments