Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Always use `mise`. Do not call `xcodebuild` or `swift test` directly. Run `mise
| `mise chore` | Strip strings, refresh licenses, format |

- `run_xcodebuild.sh` fails on the exit code, compiler errors, and xcodebuild failure summaries. Still read the log: a passing run must have no compiler warnings and every test must pass.
- `run_xcodebuild.sh` passes `-skipMacroValidation`, so packages with Swift macros build on the command line. In Xcode, select **Trust & Enable** the first time you build such a package.
- Override defaults with environment variables: `CONFIGURATION=Release mise build`, `SIMULATOR_ID=<udid> mise test`, `ALLOW_DIRTY=1 mise package-resolve`.
- Scripts: bash only for thin wrappers, Python 3 with the standard library for anything that parses files. Do not add other script languages.

Expand Down
37 changes: 37 additions & 0 deletions Scripts/Tests/test_run_xcodebuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import re
import subprocess
import unittest
from pathlib import Path

SCRIPT = Path(__file__).resolve().parents[1] / "run_xcodebuild.sh"
PATTERN = re.search(r"^error_pattern='(.*)'$", SCRIPT.read_text(), re.MULTILINE).group(1)


def matches(line: str) -> bool:
return subprocess.run(["grep", "-E", PATTERN], input=line, text=True, capture_output=True).returncode == 0


class ErrorPatternTests(unittest.TestCase):
def test_matches_compiler_and_package_diagnostics(self) -> None:
for line in (
"/src/App/View.swift:12:5: error: cannot find 'x' in scope",
"/src/App/View.swift:12: error: bad",
"/checkouts/pkg/Package.swift:PACKAGE-TARGET:Macros: error: Macro \"Macros\" must be enabled",
"xcodebuild: error: Unable to find a destination",
"error: plain",
"** BUILD FAILED **",
):
with self.subTest(line=line):
self.assertTrue(matches(line))

def test_ignores_errors_inside_system_logs(self) -> None:
for line in (
"2026-10-10 12:00:00.000 App[1:2] [AXLoading] ScreenTimeUI error: noise",
"/usr/lib/libfoo.dylib something error: noise",
):
with self.subTest(line=line):
self.assertFalse(matches(line))


if __name__ == "__main__":
unittest.main()
14 changes: 14 additions & 0 deletions Scripts/Tests/test_strip_stale_xcstrings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib.util
import tempfile
import unittest
from pathlib import Path

Expand Down Expand Up @@ -38,5 +39,18 @@ def test_removes_stale_and_mirrors_source_value(self) -> None:
self.assertEqual(new_doc["strings"]["Hello"]["localizations"]["en"]["stringUnit"]["value"], "Hello")


class IterXcstringsTests(unittest.TestCase):
def test_skips_derived_data_checkouts(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
for folder in ("App/Resources", ".DerivedData/SourcePackages/checkouts/Some/Resources"):
(root / folder).mkdir(parents=True)
(root / folder / "Localizable.xcstrings").write_text("{}")

found = [path.relative_to(root) for path in strip_stale_xcstrings.iter_xcstrings(root)]

self.assertEqual(found, [Path("App/Resources/Localizable.xcstrings")])


if __name__ == "__main__":
unittest.main()
13 changes: 13 additions & 0 deletions Scripts/Tests/test_validate_xcstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,18 @@ def test_unregistered_key_still_fails(self) -> None:
self.assertTrue(any("missing from the catalog" in error for error in errors), errors)


class IterXcstringsTests(unittest.TestCase):
def test_skips_derived_data_checkouts(self) -> None:
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
for folder in ("App/Resources", ".DerivedData/SourcePackages/checkouts/Some/Resources"):
(root / folder).mkdir(parents=True)
(root / folder / "Localizable.xcstrings").write_text("{}")

found = [path.relative_to(root) for path in validate_xcstrings.iter_xcstrings(root)]

self.assertEqual(found, [Path("App/Resources/Localizable.xcstrings")])


if __name__ == "__main__":
unittest.main()
8 changes: 5 additions & 3 deletions Scripts/run_xcodebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ xcodebuild \
-destination "$destination" \
-derivedDataPath .DerivedData \
CODE_SIGNING_ALLOWED=NO \
-skipMacroValidation \
"$@" \
"$action" 2>&1 | tee "$log" | beautify
status=${PIPESTATUS[0]}
set -e

# Match only lines that xcodebuild or the compiler emit: diagnostics start with a
# source path or "error:", and summaries start with "**". The test host process
# also writes to this log, and its system logs can contain "error:" mid-line.
error_pattern='^(/[^:]+:[0-9]+:([0-9]+:)? |xcodebuild: )?error:|^\*\* (BUILD|TEST|ARCHIVE|CLEAN|ANALYZE) FAILED \*\*|^Testing failed:|^Failing tests:'
# source path (`file:line:col:` or `Package.swift:PACKAGE-TARGET:name:`) or
# "error:", and summaries start with "**". The test host process also writes to
# this log, and its system logs can contain "error:" mid-line.
error_pattern='^(/[^:]+(:[^: ]+)*: |xcodebuild: )?error:|^\*\* (BUILD|TEST|ARCHIVE|CLEAN|ANALYZE) FAILED \*\*|^Testing failed:|^Failing tests:'
errors=$(grep -E "$error_pattern" "$log" || true)

if [[ $status -ne 0 || -n $errors ]]; then
Expand Down
1 change: 1 addition & 0 deletions Scripts/strip_stale_xcstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build",
".build",
"DerivedData",
".DerivedData",
"Pods",
"Carthage",
".git",
Expand Down
1 change: 1 addition & 0 deletions Scripts/validate_xcstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build",
".build",
"DerivedData",
".DerivedData",
"Pods",
"Carthage",
".git",
Expand Down
Loading