From 8a7dcfdb1507527fc3be41750d8bb11c624bab0d Mon Sep 17 00:00:00 2001 From: DmitriySalnikov Date: Thu, 14 Nov 2024 21:51:10 +0300 Subject: [PATCH] Added script validation on a minimal version of python. Fixed quotes in string interpolation to support the minimal version. Supersedes #58 --- .github/workflows/gdextension_build.yml | 29 ++++++++++ lib_utils_external.py | 70 +++++++++++++++++-------- 2 files changed, 76 insertions(+), 23 deletions(-) diff --git a/.github/workflows/gdextension_build.yml b/.github/workflows/gdextension_build.yml index 9a7cf070..904200e7 100644 --- a/.github/workflows/gdextension_build.yml +++ b/.github/workflows/gdextension_build.yml @@ -331,6 +331,35 @@ jobs: use_cache: ${{env.USE_CACHE}} token: ${{secrets.TELEMETRY_TOKEN}} + # ============================================ + + check-python-version: + name: 🐍 Check compatibility with python + runs-on: ubuntu-latest + strategy: + matrix: + PYTHON_VER: ["3.8"] # this is the minimum available version to install on ubuntu 22.04 and 24.04 + # but the code is most likely compatible with python 3.6 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + sparse-checkout: | + . + patches + + - name: Setup python ${{matrix.PYTHON_VER}} + uses: actions/setup-python@v5 + with: + python-version: ${{matrix.PYTHON_VER}} + + - name: Try to compile all .py files + run: | + python --version + files="SConstruct $(find . -maxdepth 1 -name "*.py") $(find patches -name "*.py")" + echo "Found files: '$files'" + python -m py_compile $files + echo "All files compiled successfully!" # ============================================ diff --git a/lib_utils_external.py b/lib_utils_external.py index 8877cf25..5d43c982 100644 --- a/lib_utils_external.py +++ b/lib_utils_external.py @@ -10,8 +10,8 @@ # Get the name of the cmake build directory def get_cmake_build_dir_name(env: SConsEnvironment) -> str: if env.get("threads", True) and env["platform"] == "web": - return f"{env["platform"]}_{env["arch"]}_threads" - return f"cmake_build_out/{env["platform"]}_{env["arch"]}" + return f'{env["platform"]}_{env["arch"]}_threads' + return f'cmake_build_out/{env["platform"]}_{env["arch"]}' # Get a path to the build folder of the cmake library @@ -19,10 +19,10 @@ def get_cmake_build_dir(env: SConsEnvironment, lib_path: str) -> str: abs_scons_root = os.path.dirname(os.path.abspath(__file__)) # CMake doesn't seem to be able to work with the cache at all... # - #scons_cache_path = os.environ.get("SCONS_CACHE") - #if scons_cache_path: + # scons_cache_path = os.environ.get("SCONS_CACHE") + # if scons_cache_path: # return os.path.join(abs_scons_root, scons_cache_path, "cmake", lib_path, get_cmake_build_dir_name(env)) - #else: + # else: return os.path.join(abs_scons_root, lib_path, get_cmake_build_dir_name(env)) @@ -72,7 +72,7 @@ def apply_git_patches(env: SConsEnvironment, patches_to_apply: list, working_dir encoding="utf-8", ) print_subprocess_result(result, "git") - print(f"Successfully applied patch: {patch}") + print(f"Successfully applied patch: '{patch}'") except subprocess.CalledProcessError as e: print_subprocess_result(e, "git") print("Please fix the patches, disable them, or try to git reset!") @@ -91,26 +91,46 @@ def cmake_build_project(env: SConsEnvironment, lib_path: str, extra_args: list, linker_flags = extra_c_compiler_flags.get("linker_flags", []).copy() if platform == "windows": - arch_map = { "arm32": "ARM", "arm64": "ARM64", "x86_32": "Win32", "x86_64":"x64" } - platform_args += ["-G", "Visual Studio 17 2022", - "-A", arch_map[arch], - "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" + ("" if env["use_static_cpp"] else "DLL")] + arch_map = {"arm32": "ARM", "arm64": "ARM64", "x86_32": "Win32", "x86_64": "x64"} + platform_args += [ + "-G", + "Visual Studio 17 2022", + "-A", + arch_map[arch], + "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" + ("" if env["use_static_cpp"] else "DLL"), + ] elif platform == "linux": - platform_args += ["-G", "Ninja Multi-Config",] + platform_args += [ + "-G", + "Ninja Multi-Config", + ] elif platform == "macos": - platform_args += ["-G", "Ninja Multi-Config", - "-DCMAKE_SYSTEM_NAME=Darwin",] + platform_args += [ + "-G", + "Ninja Multi-Config", + "-DCMAKE_SYSTEM_NAME=Darwin", + ] elif platform == "ios": - platform_args += ["-G", "Ninja Multi-Config", - "-DCMAKE_SYSTEM_NAME=iOS",] + platform_args += [ + "-G", + "Ninja Multi-Config", + "-DCMAKE_SYSTEM_NAME=iOS", + ] elif platform == "android": - arch_map = { "arm32": "armeabi-v7a", "arm64": "arm64-v8a", "x86_32": "x86", "x86_64":"x86_64" } - platform_args += ["-G", "Ninja Multi-Config", - f"-DCMAKE_TOOLCHAIN_FILE={os.getenv("ANDROID_HOME")}/ndk/25.2.9519653/build/cmake/android.toolchain.cmake", - f"-DANDROID_ABI={arch_map[arch]}", f"-DANDROID_PLATFORM={env.get("android_api_level", 21)}",] + arch_map = {"arm32": "armeabi-v7a", "arm64": "arm64-v8a", "x86_32": "x86", "x86_64": "x86_64"} + platform_args += [ + "-G", + "Ninja Multi-Config", + f'-DCMAKE_TOOLCHAIN_FILE={os.getenv("ANDROID_HOME")}/ndk/25.2.9519653/build/cmake/android.toolchain.cmake', + f"-DANDROID_ABI={arch_map[arch]}", + f'-DANDROID_PLATFORM={env.get("android_api_level", 21)}', + ] elif platform == "web": - platform_args += ["-G", "Ninja Multi-Config", - f"-DCMAKE_TOOLCHAIN_FILE={os.path.dirname(WhereIs("emcc"))}/cmake/Modules/Platform/Emscripten.cmake",] + platform_args += [ + "-G", + "Ninja Multi-Config", + f'-DCMAKE_TOOLCHAIN_FILE={os.path.dirname(WhereIs("emcc"))}/cmake/Modules/Platform/Emscripten.cmake', + ] if env.get("threads", True): compiler_flags += ["-sUSE_PTHREADS=1"] linker_flags += ["-sUSE_PTHREADS=1"] @@ -118,13 +138,17 @@ def cmake_build_project(env: SConsEnvironment, lib_path: str, extra_args: list, build_args += ["--config", "Debug" if env["dev_build"] else "Release"] if len(compiler_flags): - platform_args += [f"-DCMAKE_C_FLAGS={";".join(compiler_flags)}", f"-DCMAKE_CXX_FLAGS={";".join(compiler_flags)}"] + platform_args += [ + f'-DCMAKE_C_FLAGS={";".join(compiler_flags)}', + f'-DCMAKE_CXX_FLAGS={";".join(compiler_flags)}', + ] if len(linker_flags): - platform_args += [f"-DCMAKE_EXE_LINKER_FLAGS={";".join(linker_flags)}"] + platform_args += [f'-DCMAKE_EXE_LINKER_FLAGS={";".join(linker_flags)}'] curdir = os.curdir os.chdir(lib_path) try: + def config(): result = subprocess.run( ["cmake", f"-B{get_cmake_build_dir(env, lib_path)}"] + platform_args + extra_args,