Skip to content

Commit 45d4d49

Browse files
committed
Fi ci
1 parent 0b3032b commit 45d4d49

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

tools/tolua/genbindings.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@
44
# Android ndk version must be ndk-r9b.
55

66

7+
import argparse
78
import sys
89
import os, os.path
910
import shutil
1011
import subprocess
1112
import re
1213
from contextlib import contextmanager
1314

15+
g_ndk_root = None
1416

1517
def _check_ndk_root_env():
1618
''' Checking the environment ANDROID_NDK, which will be used for building
1719
'''
1820

1921
try:
2022

21-
sdkRoot = os.environ['ANDROID_SDK_ROOT']
23+
ANDROID_NDK = None
24+
25+
sdkRoot = os.environ.get('ANDROID_SDK_ROOT', None)
2226
for _, ndkVers, _ in os.walk("{0}{1}ndk".format(sdkRoot, os.path.sep)):
2327
for ndkVer in ndkVers:
2428
if (ndkVer == '19.2.5345600'):
@@ -27,12 +31,10 @@ def _check_ndk_root_env():
2731
break
2832

2933
if ANDROID_NDK == None:
30-
ANDROID_NDK = os.environ['ANDROID_NDK']
31-
if not os.path.isdir(ANDROID_NDK): raise
34+
ANDROID_NDK = os.environ.get('ANDROID_NDK', None)
3235

33-
except Exception:
34-
print("The ndk-r19c not installed in '{0}{1}ndk', please install via cmdline-tools/bin/sdkmanager --verbose --sdk_root=D:\\dev\\adt\\sdk \"ndk;19.2.5345600\"".format(sdkRoot, os.path.sep))
35-
sys.exit(1)
36+
except:
37+
print('Exception occurred when check_ndk_root_env!')
3638

3739
return ANDROID_NDK
3840

@@ -71,12 +73,13 @@ def _find_all_files_match(dir, cond, all):
7173

7274

7375
def _find_toolchain_include_path():
76+
global g_ndk_root
7477
'''
7578
Search gcc prebuilt include path
7679
for instance: "$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include"
7780
'''
7881
foundFiles = []
79-
_find_all_files_match(os.path.join(_check_ndk_root_env(), "toolchains"), lambda x : os.path.basename(x) == "stdarg.h" and "arm-linux-androideabi" in x , foundFiles)
82+
_find_all_files_match(os.path.join(g_ndk_root, "toolchains"), lambda x : os.path.basename(x) == "stdarg.h" and "arm-linux-androideabi" in x , foundFiles)
8083
if len(foundFiles) == 0:
8184
return ""
8285
else:
@@ -87,7 +90,8 @@ def _find_llvm_include_path():
8790
Search llvm prebuilt include path.
8891
for instance: "$ANDROID_NDK/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/6.0.2/include"
8992
'''
90-
versionFile = _find_first_file_in_dir(_check_ndk_root_env(), "AndroidVersion.txt")
93+
global g_ndk_root
94+
versionFile = _find_first_file_in_dir(g_ndk_root, "AndroidVersion.txt")
9195
if versionFile is None:
9296
return ""
9397
versionDir = os.path.dirname(versionFile)
@@ -123,12 +127,19 @@ def _run_cmd(command):
123127
raise CmdError(message)
124128

125129
def main():
130+
global g_ndk_root
126131

127132
cur_platform= '??'
128133
llvm_path = '??'
129-
ndk_root = _check_ndk_root_env()
134+
if (g_ndk_root == None or not os.path.isdir(g_ndk_root)):
135+
g_ndk_root = _check_ndk_root_env()
136+
137+
if not os.path.isdir(g_ndk_root):
138+
print("The ndk-r19c root not specified, please specifiy via --ndk_root '/path/to/ndk'")
139+
sys.exit(1)
140+
130141
# del the " in the path
131-
ndk_root = re.sub(r"\"", "", ndk_root)
142+
g_ndk_root = re.sub(r"\"", "", g_ndk_root)
132143
python_bin = _check_python_bin_env()
133144

134145
platform = sys.platform
@@ -143,11 +154,11 @@ def main():
143154
sys.exit(1)
144155

145156
x86_llvm_path = ""
146-
x64_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm/prebuilt', '%s-%s' % (cur_platform, 'x86_64')))
157+
x64_llvm_path = os.path.abspath(os.path.join(g_ndk_root, 'toolchains/llvm/prebuilt', '%s-%s' % (cur_platform, 'x86_64')))
147158
if not os.path.exists(x64_llvm_path):
148-
x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm/prebuilt', '%s' % (cur_platform)))
159+
x86_llvm_path = os.path.abspath(os.path.join(g_ndk_root, 'toolchains/llvm/prebuilt', '%s' % (cur_platform)))
149160
if not os.path.exists(x86_llvm_path):
150-
x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm/prebuilt', '%s-%s' % (cur_platform, 'x86')))
161+
x86_llvm_path = os.path.abspath(os.path.join(g_ndk_root, 'toolchains/llvm/prebuilt', '%s-%s' % (cur_platform, 'x86')))
151162

152163
if os.path.isdir(x64_llvm_path):
153164
llvm_path = x64_llvm_path
@@ -159,11 +170,11 @@ def main():
159170
sys.exit(1)
160171

161172
x86_gcc_toolchain_path = ""
162-
x64_gcc_toolchain_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/arm-linux-androideabi-4.9/prebuilt', '%s-%s' % (cur_platform, 'x86_64')))
173+
x64_gcc_toolchain_path = os.path.abspath(os.path.join(g_ndk_root, 'toolchains/arm-linux-androideabi-4.9/prebuilt', '%s-%s' % (cur_platform, 'x86_64')))
163174
if not os.path.exists(x64_gcc_toolchain_path):
164-
x86_gcc_toolchain_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/arm-linux-androideabi-4.9/prebuilt', '%s' % (cur_platform)))
175+
x86_gcc_toolchain_path = os.path.abspath(os.path.join(g_ndk_root, 'toolchains/arm-linux-androideabi-4.9/prebuilt', '%s' % (cur_platform)))
165176
if not os.path.exists(x86_gcc_toolchain_path):
166-
x86_gcc_toolchain_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/arm-linux-androideabi-4.9/prebuilt', '%s-%s' % (cur_platform, 'x86')))
177+
x86_gcc_toolchain_path = os.path.abspath(os.path.join(g_ndk_root, 'toolchains/arm-linux-androideabi-4.9/prebuilt', '%s-%s' % (cur_platform, 'x86')))
167178

168179
if os.path.isdir(x64_gcc_toolchain_path):
169180
gcc_toolchain_path = x64_gcc_toolchain_path
@@ -189,7 +200,7 @@ def main():
189200
import ConfigParser
190201
config = ConfigParser.ConfigParser()
191202

192-
config.set('DEFAULT', 'androidndkdir', ndk_root)
203+
config.set('DEFAULT', 'androidndkdir', g_ndk_root)
193204
config.set('DEFAULT', 'clangllvmdir', llvm_path)
194205
config.set('DEFAULT', 'gcc_toolchain_dir', gcc_toolchain_path)
195206
config.set('DEFAULT', 'axysdir', axys_root)
@@ -259,4 +270,8 @@ def main():
259270

260271
# -------------- main --------------
261272
if __name__ == '__main__':
273+
parser = argparse.ArgumentParser(description='Install android sdk/ndk')
274+
parser.add_argument("--ndk_root", help="Specificy ndk root")
275+
args = parser.parse_args()
276+
g_ndk_root = args.ndk_root
262277
main()

tools/win-ci/genbindings.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ curl -L "https://dl.google.com/android/repository/android-ndk-r19c-windows-x86_6
3434
Expand-Archive -Path android-ndk-r19c-windows-x86_64.zip -DestinationPath .\
3535
ls
3636
$ndk_root=(Resolve-Path .\android-ndk-r19c).Path
37-
$env:ANDROID_NDK=$ndk_root
37+
# $env:ANDROID_NDK=$ndk_root
3838

3939

4040
## run genbindings.py
4141
pwd
4242
cd ..\tools\tolua
43-
python genbindings.py
43+
python genbindings.py --ndk_root "$ndk_root"
4444

4545
$env:Path = $storedEnvPath
4646
cd ..\..

0 commit comments

Comments
 (0)