• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import platform
2import sys
3import os
4
5# TODO: In next version, it will be a JSON file listing all the patches, and then it will iterate through to apply them.
6def patch_android():
7    print("- Patches List -")
8    print("[1] [deps/v8/src/trap-handler/trap-handler.h] related to https://github.com/nodejs/node/issues/36287")
9    if platform.system() == "Linux":
10        os.system('patch -f ./deps/v8/src/trap-handler/trap-handler.h < ./android-patches/trap-handler.h.patch')
11    print("\033[92mInfo: \033[0m" + "Tried to patch.")
12
13if platform.system() == "Windows":
14    print("android-configure is not supported on Windows yet.")
15    sys.exit(1)
16
17if len(sys.argv) == 2 and sys.argv[1] == "patch":
18    patch_android()
19    sys.exit(0)
20
21if len(sys.argv) != 4:
22    print("Usage: ./android-configure [patch] <path to the Android NDK> <Android SDK version> <target architecture>")
23    sys.exit(1)
24
25if not os.path.exists(sys.argv[1]) or not os.listdir(sys.argv[1]):
26    print("\033[91mError: \033[0m" + "Invalid path to the Android NDK")
27    sys.exit(1)
28
29if int(sys.argv[2]) < 24:
30    print("\033[91mError: \033[0m" + "Android SDK version must be at least 24 (Android 7.0)")
31    sys.exit(1)
32
33android_ndk_path = sys.argv[1]
34android_sdk_version = sys.argv[2]
35arch = sys.argv[3]
36
37if arch == "arm":
38    DEST_CPU = "arm"
39    TOOLCHAIN_PREFIX = "armv7a-linux-androideabi"
40elif arch in ("aarch64", "arm64"):
41    DEST_CPU = "arm64"
42    TOOLCHAIN_PREFIX = "aarch64-linux-android"
43    arch = "arm64"
44elif arch == "x86":
45    DEST_CPU = "ia32"
46    TOOLCHAIN_PREFIX = "i686-linux-android"
47elif arch == "x86_64":
48    DEST_CPU = "x64"
49    TOOLCHAIN_PREFIX = "x86_64-linux-android"
50    arch = "x64"
51else:
52    print("\033[91mError: \033[0m" + "Invalid target architecture, must be one of: arm, arm64, aarch64, x86, x86_64")
53    sys.exit(1)
54
55print("\033[92mInfo: \033[0m" + "Configuring for " + DEST_CPU + "...")
56
57if platform.system() == "Darwin":
58    host_os = "darwin"
59    toolchain_path = android_ndk_path + "/toolchains/llvm/prebuilt/darwin-x86_64"
60
61elif platform.system() == "Linux":
62    host_os = "linux"
63    toolchain_path = android_ndk_path + "/toolchains/llvm/prebuilt/linux-x86_64"
64
65os.environ['PATH'] += os.pathsep + toolchain_path + "/bin"
66os.environ['CC'] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" +  "clang"
67os.environ['CXX'] = toolchain_path + "/bin/" + TOOLCHAIN_PREFIX + android_sdk_version + "-" + "clang++"
68
69GYP_DEFINES = "target_arch=" + arch
70GYP_DEFINES += " v8_target_arch=" + arch
71GYP_DEFINES += " android_target_arch=" + arch
72GYP_DEFINES += " host_os=" + host_os + " OS=android"
73os.environ['GYP_DEFINES'] = GYP_DEFINES
74
75if os.path.exists("./configure"):
76    os.system("./configure --dest-cpu=" + DEST_CPU + " --dest-os=android --openssl-no-asm --cross-compiling")
77