diff --git a/AGENTS.md b/AGENTS.md index 2428068..62cad8c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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= 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. diff --git a/Scripts/Tests/test_run_xcodebuild.py b/Scripts/Tests/test_run_xcodebuild.py new file mode 100644 index 0000000..f32c7f6 --- /dev/null +++ b/Scripts/Tests/test_run_xcodebuild.py @@ -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() diff --git a/Scripts/Tests/test_strip_stale_xcstrings.py b/Scripts/Tests/test_strip_stale_xcstrings.py index 456e80c..14ba3e0 100644 --- a/Scripts/Tests/test_strip_stale_xcstrings.py +++ b/Scripts/Tests/test_strip_stale_xcstrings.py @@ -1,4 +1,5 @@ import importlib.util +import tempfile import unittest from pathlib import Path @@ -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() diff --git a/Scripts/Tests/test_validate_xcstrings.py b/Scripts/Tests/test_validate_xcstrings.py index c15fd7b..279973f 100644 --- a/Scripts/Tests/test_validate_xcstrings.py +++ b/Scripts/Tests/test_validate_xcstrings.py @@ -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() diff --git a/Scripts/run_xcodebuild.sh b/Scripts/run_xcodebuild.sh index 004bbfe..2e81f49 100755 --- a/Scripts/run_xcodebuild.sh +++ b/Scripts/run_xcodebuild.sh @@ -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 diff --git a/Scripts/strip_stale_xcstrings.py b/Scripts/strip_stale_xcstrings.py index b59cb0a..e5231a3 100644 --- a/Scripts/strip_stale_xcstrings.py +++ b/Scripts/strip_stale_xcstrings.py @@ -12,6 +12,7 @@ "build", ".build", "DerivedData", + ".DerivedData", "Pods", "Carthage", ".git", diff --git a/Scripts/validate_xcstrings.py b/Scripts/validate_xcstrings.py index 64f1ff3..f7e7b53 100644 --- a/Scripts/validate_xcstrings.py +++ b/Scripts/validate_xcstrings.py @@ -28,6 +28,7 @@ "build", ".build", "DerivedData", + ".DerivedData", "Pods", "Carthage", ".git",