11cb0ef41Sopenharmony_ciimport platform 21cb0ef41Sopenharmony_ciimport sys 31cb0ef41Sopenharmony_ciimport os 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci# TODO: In next version, it will be a JSON file listing all the patches, and then it will iterate through to apply them. 61cb0ef41Sopenharmony_cidef patch_android(): 71cb0ef41Sopenharmony_ci print("- Patches List -") 81cb0ef41Sopenharmony_ci print("[1] [deps/v8/src/trap-handler/trap-handler.h] related to https://github.com/nodejs/node/issues/36287") 91cb0ef41Sopenharmony_ci if platform.system() == "Linux": 101cb0ef41Sopenharmony_ci os.system('patch -f ./deps/v8/src/trap-handler/trap-handler.h < ./android-patches/trap-handler.h.patch') 111cb0ef41Sopenharmony_ci print("\033[92mInfo: \033[0m" + "Tried to patch.") 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciif platform.system() == "Windows": 141cb0ef41Sopenharmony_ci print("android-configure is not supported on Windows yet.") 151cb0ef41Sopenharmony_ci sys.exit(1) 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciif len(sys.argv) == 2 and sys.argv[1] == "patch": 181cb0ef41Sopenharmony_ci patch_android() 191cb0ef41Sopenharmony_ci sys.exit(0) 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciif len(sys.argv) != 4: 221cb0ef41Sopenharmony_ci print("Usage: ./android-configure [patch] <path to the Android NDK> <Android SDK version> <target architecture>") 231cb0ef41Sopenharmony_ci sys.exit(1) 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciif not os.path.exists(sys.argv[1]) or not os.listdir(sys.argv[1]): 261cb0ef41Sopenharmony_ci print("\033[91mError: \033[0m" + "Invalid path to the Android NDK") 271cb0ef41Sopenharmony_ci sys.exit(1) 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciif int(sys.argv[2]) < 24: 301cb0ef41Sopenharmony_ci print("\033[91mError: \033[0m" + "Android SDK version must be at least 24 (Android 7.0)") 311cb0ef41Sopenharmony_ci sys.exit(1) 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciandroid_ndk_path = sys.argv[1] 341cb0ef41Sopenharmony_ciandroid_sdk_version = sys.argv[2] 351cb0ef41Sopenharmony_ciarch = sys.argv[3] 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciif arch == "arm": 381cb0ef41Sopenharmony_ci DEST_CPU = "arm" 391cb0ef41Sopenharmony_ci TOOLCHAIN_PREFIX = "armv7a-linux-androideabi" 401cb0ef41Sopenharmony_cielif arch in ("aarch64", "arm64"): 411cb0ef41Sopenharmony_ci DEST_CPU = "arm64" 421cb0ef41Sopenharmony_ci TOOLCHAIN_PREFIX = "aarch64-linux-android" 431cb0ef41Sopenharmony_ci arch = "arm64" 441cb0ef41Sopenharmony_cielif arch == "x86": 451cb0ef41Sopenharmony_ci DEST_CPU = "ia32" 461cb0ef41Sopenharmony_ci TOOLCHAIN_PREFIX = "i686-linux-android" 471cb0ef41Sopenharmony_cielif arch == "x86_64": 481cb0ef41Sopenharmony_ci DEST_CPU = "x64" 491cb0ef41Sopenharmony_ci TOOLCHAIN_PREFIX = "x86_64-linux-android" 501cb0ef41Sopenharmony_ci arch = "x64" 511cb0ef41Sopenharmony_cielse: 521cb0ef41Sopenharmony_ci print("\033[91mError: \033[0m" + "Invalid target architecture, must be one of: arm, arm64, aarch64, x86, x86_64") 531cb0ef41Sopenharmony_ci sys.exit(1) 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ciprint("\033[92mInfo: \033[0m" + "Configuring for " + DEST_CPU + "...") 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ciif platform.system() == "Darwin": 581cb0ef41Sopenharmony_ci host_os = "darwin" 591cb0ef41Sopenharmony_ci toolchain_path = android_ndk_path + "/toolchains/llvm/prebuilt/darwin-x86_64" 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_cielif platform.system() == "Linux": 621cb0ef41Sopenharmony_ci host_os = "linux" 631cb0ef41Sopenharmony_ci toolchain_path = android_ndk_path + "/toolchains/llvm/prebuilt/linux-x86_64" 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_cios.environ['PATH'] += os.pathsep + toolchain_path + "/bin" 661cb0ef41Sopenharmony_cios.environ['CC'] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang" 671cb0ef41Sopenharmony_cios.environ['CXX'] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang++" 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ciGYP_DEFINES = "target_arch=" + arch 701cb0ef41Sopenharmony_ciGYP_DEFINES += " v8_target_arch=" + arch 711cb0ef41Sopenharmony_ciGYP_DEFINES += " android_target_arch=" + arch 721cb0ef41Sopenharmony_ciGYP_DEFINES += " host_os=" + host_os + " OS=android" 731cb0ef41Sopenharmony_cios.environ['GYP_DEFINES'] = GYP_DEFINES 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ciif os.path.exists("./configure"): 761cb0ef41Sopenharmony_ci os.system("./configure --dest-cpu=" + DEST_CPU + " --dest-os=android --openssl-no-asm --cross-compiling") 77