From 0c8ae82fe3f931b965353819a5ea198bca0a94db Mon Sep 17 00:00:00 2001 From: patricejiang Date: Mon, 18 Mar 2019 13:56:19 +0800 Subject: [PATCH 1/4] fix lua bindings --- tools/tolua/genbindings.py | 46 +++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 8b61ad77d8..870df9ca13 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -37,6 +37,49 @@ def _check_python_bin_env(): return PYTHON_BIN +def _find_first_file_in_dir(dir, fn): + if os.path.isfile(dir): + if os.path.basename(dir) == fn: + return os.path.join(os.path.dirname(dir), fn) + else : + return None + elif os.path.isdir(dir): + for subdir in os.listdir(dir): + searchPath = _find_first_file_in_dir(os.path.join(dir, subdir), fn) + if searchPath is not None: + return searchPath + else: + return None + +def _find_all_files_match(dir, cond, all): + if cond(dir): + all.append(dir) + elif os.path.isdir(dir): + for subdir in os.listdir(dir): + _find_all_files_match(os.path.join(dir, subdir), cond, all) + + +def _find_toolchain_include_path(): + foundFiles = [] + _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) + if len(foundFiles) == 0: + return "" + else: + return "-I" + os.path.dirname(foundFiles[0]) + +def _find_llvm_include_path(): + versionFile = _find_first_file_in_dir(_check_ndk_root_env(), "AndroidVersion.txt") + if versionFile is None: + return "" + llvmIncludePath = os.path.join(os.path.dirname(versionFile), "lib64/clang/include") + return "-I"+llvmIncludePath + + +def _defaultIncludePath(): + llvmInclude = _find_llvm_include_path() + toolchainInclude = _find_toolchain_include_path() + return llvmInclude + " " + toolchainInclude + class CmdError(Exception): pass @@ -112,6 +155,7 @@ def main(): cocos_root = os.path.abspath(os.path.join(project_root, '')) cxx_generator_root = os.path.abspath(os.path.join(project_root, 'tools/bindings-generator')) + extraFlags = _defaultIncludePath() # save config to file config = ConfigParser.ConfigParser() config.set('DEFAULT', 'androidndkdir', ndk_root) @@ -119,7 +163,7 @@ def main(): config.set('DEFAULT', 'gcc_toolchain_dir', gcc_toolchain_path) config.set('DEFAULT', 'cocosdir', cocos_root) config.set('DEFAULT', 'cxxgeneratordir', cxx_generator_root) - config.set('DEFAULT', 'extra_flags', '') + config.set('DEFAULT', 'extra_flags', extraFlags) conf_ini_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'userconf.ini')) From b3d5b6ef39ffae40222876ba6f19d700fe224344 Mon Sep 17 00:00:00 2001 From: Arnold <397136899@qq.com> Date: Mon, 18 Mar 2019 16:22:02 +0800 Subject: [PATCH 2/4] fix 1 --- tools/tolua/genbindings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 870df9ca13..e60eb2c820 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -71,14 +71,18 @@ def _find_llvm_include_path(): versionFile = _find_first_file_in_dir(_check_ndk_root_env(), "AndroidVersion.txt") if versionFile is None: return "" - llvmIncludePath = os.path.join(os.path.dirname(versionFile), "lib64/clang/include") + versionDir = os.path.dirname(versionFile) + includeDir = _find_first_file_in_dir(versionDir, "stdarg.h") + llvmIncludePath = os.path.dirname(includeDir) return "-I"+llvmIncludePath def _defaultIncludePath(): llvmInclude = _find_llvm_include_path() toolchainInclude = _find_toolchain_include_path() - return llvmInclude + " " + toolchainInclude + exactIncludes = llvmInclude + " " + toolchainInclude + print("exact include " + exactIncludes) + return exactIncludes class CmdError(Exception): From a03109ca36b1379e3264942abb1859deb2780da7 Mon Sep 17 00:00:00 2001 From: patricejiang Date: Mon, 18 Mar 2019 16:27:46 +0800 Subject: [PATCH 3/4] remove log --- tools/tolua/genbindings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index e60eb2c820..d445548d1a 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -81,7 +81,6 @@ def _defaultIncludePath(): llvmInclude = _find_llvm_include_path() toolchainInclude = _find_toolchain_include_path() exactIncludes = llvmInclude + " " + toolchainInclude - print("exact include " + exactIncludes) return exactIncludes From 0922ca9e7f8e2793b16c8eba10d2664cd1c123c2 Mon Sep 17 00:00:00 2001 From: Arnold <397136899@qq.com> Date: Tue, 19 Mar 2019 02:03:48 +0800 Subject: [PATCH 4/4] add doc --- tools/tolua/genbindings.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index d445548d1a..c95de1adfd 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -60,6 +60,10 @@ def _find_all_files_match(dir, cond, all): def _find_toolchain_include_path(): + ''' + Search gcc prebuilt include path + for instance: "$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/include" + ''' foundFiles = [] _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) if len(foundFiles) == 0: @@ -68,6 +72,10 @@ def _find_toolchain_include_path(): return "-I" + os.path.dirname(foundFiles[0]) def _find_llvm_include_path(): + ''' + Search llvm prebuilt include path. + for instance: "$NDK_ROOT/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/6.0.2/include" + ''' versionFile = _find_first_file_in_dir(_check_ndk_root_env(), "AndroidVersion.txt") if versionFile is None: return "" @@ -78,6 +86,8 @@ def _find_llvm_include_path(): def _defaultIncludePath(): + '''default include path for libclang, llvm & gcc include path + ''' llvmInclude = _find_llvm_include_path() toolchainInclude = _find_toolchain_include_path() exactIncludes = llvmInclude + " " + toolchainInclude