unity-devkit 0.3.1.dev236__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/PKG-INFO +1 -1
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/pyproject.toml +1 -1
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/compile_check_unity.py +23 -1
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/player_build.py +43 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_run_unity_batchmode.py +62 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/.gitignore +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/__init__.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/build_unity.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/identity.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/install.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/license.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/license_restore.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/lock_unity.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/matrix.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/projects.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/py.typed +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/test_unity.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/src/unity_devkit/upm_cache.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_build_player.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_identity.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_matrix.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_prepare.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_projects.py +0 -0
- {unity_devkit-0.3.1.dev236 → unity_devkit-0.3.3}/tests/test_upm_cache.py +0 -0
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
import shutil
|
|
4
|
+
from pathlib import Path
|
|
3
5
|
from typing import Annotated
|
|
4
6
|
|
|
5
7
|
import typer
|
|
6
8
|
|
|
9
|
+
from build_artifact_registry.cache import restore, save
|
|
7
10
|
from build_artifact_registry.setup_oras import install_oras
|
|
8
|
-
from .identity import cache_registry
|
|
11
|
+
from .identity import cache_key, cache_registry
|
|
9
12
|
from .license_restore import restore_or_activate_license
|
|
10
13
|
from .player_build import prepare_unity_project, resolve_unity_project, run_unity_batchmode
|
|
11
14
|
from .upm_cache import restore_upm_cache, save_upm_cache
|
|
@@ -13,11 +16,15 @@ from .upm_cache import restore_upm_cache, save_upm_cache
|
|
|
13
16
|
app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
|
|
14
17
|
|
|
15
18
|
COMPILE_ERROR_SIGNATURES = ("error CS",)
|
|
19
|
+
COMPILE_CACHE_SCOPE = "compile"
|
|
16
20
|
|
|
17
21
|
|
|
18
22
|
@app.command()
|
|
19
23
|
def compile_check_unity(
|
|
20
24
|
project: Annotated[str, typer.Option(help="Unity project name (the 'name' field of its unity-devkit.json)")],
|
|
25
|
+
pr_number: Annotated[
|
|
26
|
+
str, typer.Option(help="Pull-request number; empty on non-PR runs selects the dev library-cache scope")
|
|
27
|
+
] = "",
|
|
21
28
|
license_cache_key: Annotated[
|
|
22
29
|
str,
|
|
23
30
|
typer.Option("--license-cache-key", help="ORAS tag the license cache restores under; empty uses today's tag"),
|
|
@@ -28,13 +35,28 @@ def compile_check_unity(
|
|
|
28
35
|
raise SystemExit("compile-check needs --registry (the OCI registry root)")
|
|
29
36
|
project_path = resolve_unity_project(project).path
|
|
30
37
|
cache_namespace = cache_registry(registry)
|
|
38
|
+
parsed_pr_number = int(pr_number) if pr_number else None
|
|
39
|
+
library_cache_key = cache_key(project, COMPILE_CACHE_SCOPE, parsed_pr_number)
|
|
31
40
|
|
|
32
41
|
install_oras()
|
|
33
42
|
restore_or_activate_license(cache_namespace, license_cache_key or None)
|
|
34
43
|
restore_upm_cache(project_path, cache_namespace)
|
|
44
|
+
restore(
|
|
45
|
+
cache_namespace,
|
|
46
|
+
"unity-library",
|
|
47
|
+
library_cache_key,
|
|
48
|
+
Path("."),
|
|
49
|
+
fallback_tags=[cache_key(project, COMPILE_CACHE_SCOPE, None)] if parsed_pr_number is not None else None,
|
|
50
|
+
)
|
|
35
51
|
|
|
36
52
|
print(f"Compile-checking {project}...")
|
|
37
53
|
prepare_unity_project(project_path)
|
|
38
54
|
run_unity_batchmode(project_path, extra_failure_signatures=COMPILE_ERROR_SIGNATURES)
|
|
55
|
+
|
|
56
|
+
package_cache = project_path / "Library" / "PackageCache"
|
|
57
|
+
if package_cache.exists():
|
|
58
|
+
shutil.rmtree(package_cache)
|
|
59
|
+
relative_project_path = project_path.relative_to(Path.cwd())
|
|
60
|
+
save(cache_namespace, "unity-library", library_cache_key, Path("."), [f"{relative_project_path}/Library/"])
|
|
39
61
|
save_upm_cache(project_path, cache_namespace)
|
|
40
62
|
print(" Compiles clean")
|
|
@@ -43,6 +43,11 @@ DOTNET_SDK_VERSION = "8.0.421"
|
|
|
43
43
|
# are discovered.
|
|
44
44
|
QUIET_FAILURE_SIGNATURES = ("An error occurred while resolving packages:",)
|
|
45
45
|
|
|
46
|
+
COMPILE_ERROR_PATTERN = re.compile(
|
|
47
|
+
r"^(?P<file>.+?)\((?P<line>\d+),(?P<column>\d+)\): error (?P<code>CS\d+): (?P<message>.+)$"
|
|
48
|
+
)
|
|
49
|
+
ANNOTATION_LIMIT = 10
|
|
50
|
+
|
|
46
51
|
|
|
47
52
|
def run_unity_batchmode(
|
|
48
53
|
project_path: Path,
|
|
@@ -100,14 +105,52 @@ def run_unity_batchmode(
|
|
|
100
105
|
break
|
|
101
106
|
|
|
102
107
|
if failure_block is not None:
|
|
108
|
+
report_compile_errors(lines)
|
|
103
109
|
raise SystemExit(f"Unity reported a silent failure (exit code {returncode}):\n{failure_block}")
|
|
104
110
|
if returncode != 0 and strict_exit:
|
|
111
|
+
report_compile_errors(lines)
|
|
105
112
|
raise SystemExit(f"Unity exited {returncode}; full editor log at {log_path}")
|
|
106
113
|
if returncode != 0:
|
|
107
114
|
print(f" WARNING: Unity exited {returncode}; no package-manager failure found — full editor log at {log_path}")
|
|
108
115
|
return log_path
|
|
109
116
|
|
|
110
117
|
|
|
118
|
+
def report_compile_errors(lines: list[str]) -> None:
|
|
119
|
+
counts: dict[tuple[str, int, str, str], int] = {}
|
|
120
|
+
for line in lines:
|
|
121
|
+
if line.startswith("[Script Updater]"):
|
|
122
|
+
continue
|
|
123
|
+
match = COMPILE_ERROR_PATTERN.match(line)
|
|
124
|
+
if match is None:
|
|
125
|
+
continue
|
|
126
|
+
key = (match["file"], int(match["line"]), match["code"], match["message"].strip())
|
|
127
|
+
counts[key] = counts.get(key, 0) + 1
|
|
128
|
+
if not counts:
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
print(f"Unity compile errors ({len(counts)} distinct):", file=sys.stderr)
|
|
132
|
+
for (file, line_number, code, message), count in counts.items():
|
|
133
|
+
print(f" {code} x{count} {file}:{line_number} {message}", file=sys.stderr)
|
|
134
|
+
|
|
135
|
+
if os.environ.get("GITHUB_ACTIONS") != "true":
|
|
136
|
+
return
|
|
137
|
+
for (file, line_number, code, message), count in list(counts.items())[:ANNOTATION_LIMIT]:
|
|
138
|
+
title = escape_annotation_property(f"{code} x{count}")
|
|
139
|
+
body = escape_annotation_data(f"{code}: {message}")
|
|
140
|
+
print(f"::error file={escape_annotation_property(file)},line={line_number},title={title}::{body}")
|
|
141
|
+
beyond_limit = len(counts) - ANNOTATION_LIMIT
|
|
142
|
+
if beyond_limit > 0:
|
|
143
|
+
print(f"::error::{escape_annotation_data(f'...and {beyond_limit} more distinct compile errors')}")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def escape_annotation_data(value: str) -> str:
|
|
147
|
+
return value.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def escape_annotation_property(value: str) -> str:
|
|
151
|
+
return escape_annotation_data(value).replace(":", "%3A").replace(",", "%2C")
|
|
152
|
+
|
|
153
|
+
|
|
111
154
|
def read_editor_version(project_path: Path) -> str:
|
|
112
155
|
version_file = project_path / "ProjectSettings" / "ProjectVersion.txt"
|
|
113
156
|
version = editor_version(project_path)
|
|
@@ -72,3 +72,65 @@ def test_package_manager_signature_still_fails(tmp_path: Path, monkeypatch: pyte
|
|
|
72
72
|
|
|
73
73
|
with pytest.raises(SystemExit, match="silent failure"):
|
|
74
74
|
player_build.run_unity_batchmode(tmp_path)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_compile_error_dedups_into_one_annotation(
|
|
78
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pytest.CaptureFixture[str]
|
|
79
|
+
) -> None:
|
|
80
|
+
line = "Assets/Foo.cs(12,34): error CS0246: type not found"
|
|
81
|
+
patch_editor(monkeypatch, write_fake_editor(tmp_path, f"{line}\n{line}", 0))
|
|
82
|
+
monkeypatch.setenv("GITHUB_ACTIONS", "true")
|
|
83
|
+
monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)
|
|
84
|
+
|
|
85
|
+
with pytest.raises(SystemExit, match="silent failure"):
|
|
86
|
+
player_build.run_unity_batchmode(tmp_path, extra_failure_signatures=("error CS",))
|
|
87
|
+
|
|
88
|
+
captured = capfd.readouterr()
|
|
89
|
+
assert captured.out.count("::error file=Assets/Foo.cs,line=12") == 1
|
|
90
|
+
assert "title=CS0246 x2" in captured.out
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_compile_error_reports_distinct_list_locally(
|
|
94
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pytest.CaptureFixture[str]
|
|
95
|
+
) -> None:
|
|
96
|
+
patch_editor(monkeypatch, write_fake_editor(tmp_path, "Assets/Foo.cs(12,34): error CS0246: type not found", 0))
|
|
97
|
+
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
|
|
98
|
+
|
|
99
|
+
with pytest.raises(SystemExit, match="silent failure"):
|
|
100
|
+
player_build.run_unity_batchmode(tmp_path, extra_failure_signatures=("error CS",))
|
|
101
|
+
|
|
102
|
+
captured = capfd.readouterr()
|
|
103
|
+
assert "CS0246" in captured.err
|
|
104
|
+
assert "::error" not in captured.out
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_script_updater_noise_not_annotated(
|
|
108
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pytest.CaptureFixture[str]
|
|
109
|
+
) -> None:
|
|
110
|
+
noise = (
|
|
111
|
+
"[Script Updater] Library/PackageCache/com.cysharp.r3/Runtime/UnityXR.cs(9,89): error CS0246: type not found"
|
|
112
|
+
)
|
|
113
|
+
patch_editor(monkeypatch, write_fake_editor(tmp_path, noise, 0))
|
|
114
|
+
monkeypatch.setenv("GITHUB_ACTIONS", "true")
|
|
115
|
+
monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)
|
|
116
|
+
|
|
117
|
+
player_build.run_unity_batchmode(tmp_path, extra_failure_signatures=("error CS",))
|
|
118
|
+
|
|
119
|
+
captured = capfd.readouterr()
|
|
120
|
+
assert "::error" not in captured.out
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_annotations_capped_at_ten(
|
|
124
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pytest.CaptureFixture[str]
|
|
125
|
+
) -> None:
|
|
126
|
+
log = "\n".join(f"Assets/F{i}.cs({i},1): error CS0246: gone" for i in range(1, 15))
|
|
127
|
+
patch_editor(monkeypatch, write_fake_editor(tmp_path, log, 0))
|
|
128
|
+
monkeypatch.setenv("GITHUB_ACTIONS", "true")
|
|
129
|
+
monkeypatch.delenv("GITHUB_STEP_SUMMARY", raising=False)
|
|
130
|
+
|
|
131
|
+
with pytest.raises(SystemExit, match="silent failure"):
|
|
132
|
+
player_build.run_unity_batchmode(tmp_path, extra_failure_signatures=("error CS",))
|
|
133
|
+
|
|
134
|
+
captured = capfd.readouterr()
|
|
135
|
+
assert captured.out.count("::error file=") == 10
|
|
136
|
+
assert "...and 4 more distinct compile errors" in captured.out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|