From 95bfb7cdf28e1cb581ca6224355e724e8a2350ed Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 2 Aug 2025 10:36:42 +0500 Subject: [PATCH] scripts: build-ninja: add support for installing libraries with cmake, compared to yanking them out of build directory Set up hlsdk-portable to install in APK style directory (omitting game and game library directories from path). Minor refactoring. --- android/app/build.gradle.kts | 2 +- scripts/build-ninja.py | 44 +++++++++++++++++++----------------- scripts/configure-ninja.py | 8 +++---- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 4309fc68..17e2c80e 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -30,7 +30,7 @@ android { File(engineRoot, "scripts/configure-ninja.py").path, engineRoot, "--variant=\${ndk.variantName}", - "--abi=Android-\${ndk.abi}", + "--abi=\${ndk.abi}", "--configuration-dir=\${ndk.buildRoot}", "--ndk-version=\${ndk.moduleNdkVersion}", "--min-sdk-version=\${ndk.minPlatform}", diff --git a/scripts/build-ninja.py b/scripts/build-ninja.py index d88bd4d3..4c99e1db 100644 --- a/scripts/build-ninja.py +++ b/scripts/build-ninja.py @@ -18,23 +18,26 @@ import subprocess import sys -def run_cmake(path, libs, out): - cmake_exec = ["cmake", "--build", path] - +def run_cmake(bin_path, libs, inst_path): + cmake_exec = ["cmake", "--build", bin_path] cmake_process = subprocess.Popen(cmake_exec) cmake_process.communicate() - for lib in libs: - src = os.path.join(path, *lib.split("/")) - dest = os.path.join(out, lib.split("/")[-1]) + if libs: + for lib in libs: + src = os.path.join(bin_path, *lib.split("/")) + dest = os.path.join(inst_path, lib.split("/")[-1]) - dest_dir = os.path.dirname(dest) + dest_dir = os.path.dirname(dest) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - - shutil.copyfile(src, dest) + if not os.path.exists(dest_dir): + os.makedirs(dest_dir) + shutil.copyfile(src, dest) + else: + cmake_exec = ["cmake", "--install", bin_path, "--prefix", inst_path] + cmake_process = subprocess.Popen(cmake_exec) + cmake_process.communicate() def main(): parser = argparse.ArgumentParser() @@ -57,23 +60,22 @@ def main(): waf_exec += ["--targets={}".format(args.targets)] else: # build SDL2 and hlsdk-portable with cmake - sdl_out_path = os.path.join(args.out_dir, "SDL") - hlsdk_out_path = os.path.join(args.out_dir, "hlsdk-portable") + sdl_bin_path = os.path.join(args.out_dir, "SDL") + hlsdk_bin_path = os.path.join(args.out_dir, "hlsdk-portable") abi = args.waflock.replace(".lock-waf_android_", "").replace("_build", "") - dest_dir = os.path.join(args.top_dir, "android", "app", "src", "main", "jniLibs", abi) + inst_path = os.path.join(args.top_dir, "android", "app", "src", "main", "jniLibs", abi) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) + if not os.path.exists(inst_path): + os.makedirs(inst_path) - run_cmake(sdl_out_path, ["libSDL2.so"], dest_dir) - run_cmake(hlsdk_out_path, ["cl_dll/libclient.so", "dlls/libserver.so"], dest_dir) + run_cmake(sdl_bin_path, ["libSDL2.so"], inst_path) + run_cmake(hlsdk_bin_path, None, inst_path) process = subprocess.Popen(waf_exec, env=env) process.communicate() - sys.exit(0) - + return 0 if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/scripts/configure-ninja.py b/scripts/configure-ninja.py index d4c7da18..678ed40a 100755 --- a/scripts/configure-ninja.py +++ b/scripts/configure-ninja.py @@ -54,7 +54,7 @@ def main(): args, unknown = parser.parse_known_args() - abi = args.abi[8:] + abi = args.abi cmake_build_type = "Debug" if args.variant in ["debug", "asan"] else "Release" cmake_toolchain_path = os.path.join(args.ndk_root, "build", "cmake", "android.toolchain.cmake") @@ -77,7 +77,7 @@ def main(): hlsdk_out_path = os.path.join(args.configuration_dir, "hlsdk-portable") run_cmake(hlsdk_path, hlsdk_out_path, cmake_toolchain_path, abi, cmake_build_type, args.ndk_root, - args.min_sdk_version) + args.min_sdk_version, "-DANDROID_APK=ON") # waf configure waf_path = os.path.join(args.wscript_path, "waf") @@ -101,8 +101,8 @@ def main(): f.write(os.path.join(out_path, "build.ninja")) # required for Android Studio - sys.exit(0) + return 0 if __name__ == "__main__": - main() + sys.exit(main())