From 7a9128dfc7a331dfcdefff3508509f1bd41a671c Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sun, 2 Apr 2023 14:06:38 +0200 Subject: [PATCH] Fix test run for windows x86 --- .github/workflows/build.yml | 6 ++-- scripts/fetch_godot.py | 57 ++++++++++++++++++++++++++---------- tests/1-gdextension/build.py | 8 +++++ tests/run.py | 5 +--- 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e47d0d54..7efda805 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,9 +128,9 @@ jobs: shell: bash run: | set -eux - python tests/run.py 0-gdscript --build-dir build/ -- --headless - python tests/run.py 1-gdextension --build-dir build/ -- --headless - python tests/run.py 2-pythonscript-init --build-dir build/ -- --headless + python tests/run.py 0-gdscript --build-dir build/ --godot-binary "${{ env.PLATFORM }}:" -- --headless + python tests/run.py 1-gdextension --build-dir build/ --godot-binary "${{ env.PLATFORM }}:" -- --headless + python tests/run.py 2-pythonscript-init --build-dir build/ --godot-binary "${{ env.PLATFORM }}:" -- --headless # - name: 'Install Mesa3D OpenGL' # shell: bash # run: | diff --git a/scripts/fetch_godot.py b/scripts/fetch_godot.py index 95026c99..e311efad 100644 --- a/scripts/fetch_godot.py +++ b/scripts/fetch_godot.py @@ -5,7 +5,7 @@ import re import platform import shutil -from typing import Tuple +from typing import Optional, Tuple import subprocess import argparse from pathlib import Path @@ -23,18 +23,49 @@ def log(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) +def get_default_godot_version_from_meson(build_dir: Path) -> str: + # Ultra lazy & fast json parsing ^^ + meson_build_options = build_dir / "meson-info/intro-buildoptions.json" + version = ( + meson_build_options.read_text() + .split('"name": "godot_version", "value": "', 1)[-1] + .split('"', 1)[0] + ) + assert version + return version + + +def parse_raw_version(raw_version: str) -> GodotBinaryVersion: + # Provided value is version information with format ..[-] + match = re.match(r"^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(\w+))?$", raw_version) + if match: + major, minor, patch, extra = match.groups() + else: + raise ValueError( + f"`{raw_version}` is neither an existing file nor a valid ..[-] Godot version format" + ) + return (major, minor, patch, extra or "stable") + + def parse_godot_binary_hint( godot_binary_hint: str, -) -> Tuple[GodotBinaryPlatform, GodotBinaryVersion]: +) -> Tuple[GodotBinaryPlatform, Optional[GodotBinaryVersion]]: try: build_machine, raw_version = godot_binary_hint.split(":") except ValueError: build_machine = "" raw_version = godot_binary_hint - raw_version = raw_version - build_machine = build_machine or platform.machine() - build_platform = f"{platform.system()}-{build_machine}".lower() + # e.g. `build_machine == "x86"` + build_machine = (build_machine or platform.machine()).lower() + # e.g. `build_platform_prefix == "windows-"` + build_platform_prefix = f"{platform.system()}-".lower() + if build_machine.startswith(build_platform_prefix): + build_platform = build_machine + else: + build_platform = build_platform_prefix + build_machine + # e.g. `build_platform == "windows-x86"` + godot_build_platform = { "linux-x86_64": "linux.x86_64", "linux-x64": "linux.x86_64", @@ -53,20 +84,16 @@ def parse_godot_binary_hint( f"Don't know how to download a Godot binary for your platform `{build_platform}`" ) - # Provided value is version information with format ..[-] - match = re.match(r"^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(\w+))?$", raw_version) - if match: - major, minor, patch, extra = match.groups() - else: - raise ValueError( - f"`{raw_version}` is neither an existing file nor a valid ..[-] Godot version format" - ) - return godot_build_platform, (major, minor, patch, extra or "stable") + # If version has not been provided, it will be determined later with `get_default_godot_version_from_meson()` + version = parse_raw_version(raw_version) if raw_version else None + return godot_build_platform, version def fetch_godot_binary( - build_dir: Path, godot_platform: GodotBinaryPlatform, version: GodotBinaryVersion + build_dir: Path, godot_platform: GodotBinaryPlatform, version: Optional[GodotBinaryVersion] ) -> Path: + if not version: + version = parse_raw_version(get_default_godot_version_from_meson(build_dir)) major, minor, patch, extra = version strversion = f"{major}.{minor}.{patch}" if patch != "0" else f"{major}.{minor}" binary_name = f"Godot_v{strversion}-{extra}_{godot_platform}" diff --git a/tests/1-gdextension/build.py b/tests/1-gdextension/build.py index 85198891..39438fc4 100644 --- a/tests/1-gdextension/build.py +++ b/tests/1-gdextension/build.py @@ -1,6 +1,7 @@ import platform from pathlib import Path import subprocess +import shutil PROJECT_DIR = Path(__file__).resolve().parent @@ -8,12 +9,19 @@ if platform.system() == "Windows": + if not shutil.which("cl.exe"): + raise SystemExit( + "`cl.exe` command is missing, have you run `/vcvarsall.bat` ?" + ) + cmd = ["cl.exe", "/DEBUG", "/LD", "my.c", "/I", str(GDEXTENSION_DIR)] print(f"cd {PROJECT_DIR} && " + " ".join(cmd)) subprocess.check_call(cmd, cwd=PROJECT_DIR) else: assert platform.system() in ("Linux", "Darwin") + if not shutil.which("cc"): + raise SystemExit("`cc` command is missing") cmd = [ "cc", diff --git a/tests/run.py b/tests/run.py index 6b74e739..bf4f8c64 100644 --- a/tests/run.py +++ b/tests/run.py @@ -13,9 +13,6 @@ from tempfile import TemporaryDirectory -DEFAULT_GODOT_BINARY_VERSION = "4.0.1" - - BASEDIR = Path(__file__).resolve().parent RED = "\033[0;31m" GREEN = "\033[0;32m" @@ -195,7 +192,7 @@ def run_test( ) parser.add_argument( "--godot-binary", - default=DEFAULT_GODOT_BINARY_VERSION, + default="", help="Path to Godot binary to use, or version of Godot to download and use", ) parser.add_argument(