Skip to content

Commit

Permalink
Fix test run for windows x86
Browse files Browse the repository at this point in the history
  • Loading branch information
touilleMan committed Apr 2, 2023
1 parent ceeff42 commit 949c2bc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "${{ matrix.PLATFORM }}:" -- --headless
python tests/run.py 1-gdextension --build-dir build/ --godot-binary "${{ matrix.PLATFORM }}:" -- --headless
python tests/run.py 2-pythonscript-init --build-dir build/ --godot-binary "${{ matrix.PLATFORM }}:" -- --headless
# - name: 'Install Mesa3D OpenGL'
# shell: bash
# run: |
Expand Down
57 changes: 42 additions & 15 deletions scripts/fetch_godot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <major>.<minor>.<patch>[-<extra>]
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 <major>.<minor>.<patch>[-<extra>] 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",
Expand All @@ -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 <major>.<minor>.<patch>[-<extra>]
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 <major>.<minor>.<patch>[-<extra>] 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}"
Expand Down
8 changes: 8 additions & 0 deletions tests/1-gdextension/build.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import platform
from pathlib import Path
import subprocess
import shutil


PROJECT_DIR = Path(__file__).resolve().parent
GDEXTENSION_DIR = PROJECT_DIR / "gdextension_api"


if platform.system() == "Windows":
if not shutil.which("cl.exe"):
raise SystemExit(
"`cl.exe` command is missing, have you run `<Visual Studio Path>/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",
Expand Down
5 changes: 1 addition & 4 deletions tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 949c2bc

Please sign in to comment.