Open History to see the last commit
1#!/bin/bash
2set -euo pipefail
3module_dir=$(cd "$(dirname "$0")/.." && pwd)
4sdk=$(xcrun --sdk macosx --show-sdk-path)
5compiler=$(xcrun --find swiftc)
6output=$(mktemp -d)
7trap 'rm -rf "$output"' EXIT
8# Keep the real content view and helpers; the Expo bridge is not needed by this harness.
9python3 - "$module_dir" "$output/main.swift" <<'PYTHON'
10import sys
11from pathlib import Path
12module = Path(sys.argv[1])
13source = (module / "ios/T3ReviewDiffView.swift").read_text()
14source = source.replace("import ExpoModulesCore\n", "")
15# Count entry into the real decoder without replacing the production queue or lifecycle.
16row_decode = "try JSONDecoder().decode([ReviewDiffNativeRow].self, from: data)"
17assert source.count(row_decode) == 1
18source = source.replace(row_decode, "try decodeRowsForTest(data)")
19# Instrument the real full-token decoder and accepted publication only.
20start = source.index(" let decodedTokens = try JSONDecoder().decode(")
21end = source.index(" DispatchQueue.main.async", start)
22decode = source[start:end]
23source = source[:start] + decode.replace("try JSONDecoder().decode(", "try decodeTokensForTest(") + source[end:]
24publish = " self.contentView.tokensByRowId = decodedTokens"
25assert source.count(publish) == 1
26source = source.replace(publish, publish + "\n tokenDecodeProbe.publish()")
27# Include the accepted malformed-current fallback in publication counts.
28start = source.index(" func setTokensJson(")
29end = source.index(" func setTokensPatchJson(", start)
30method = source[start:end]
31fallback = " self.contentView.tokensByRowId = [:]"
32assert method.count(fallback) == 1
33source = source[:start] + method.replace(fallback, fallback + "\n tokenDecodeProbe.publish()") + source[end:]
34# Count the actual lookup's row visits only in the compiled test copy.
35needle = """ private func resolvedFileId(for row: ReviewDiffNativeRow) -> String {
36 row.resolvedFileId
37 }"""
38if source.count(needle) != 1:
39 raise RuntimeError("Header lookup instrumentation seam changed")
40source = source.replace(needle, """ private func resolvedFileId(for row: ReviewDiffNativeRow) -> String {
41 HeaderLookupReads.record(row)
42 return row.resolvedFileId
43 }""")
44stubs = """
45public final class AppContext {}
46open class ExpoView: UIView {
47 public required init(appContext: AppContext? = nil) { super.init(frame: .zero) }
48 @available(*, unavailable)
49 public required init?(coder: NSCoder) { fatalError("init(coder:) is unused") }
50}
51final class EventDispatcher {
52 var onEvent: (([String: Any]) -> Void)?
53 func callAsFunction(_ payload: [String: Any]) { onEvent?(payload) }
54}
55"""
56# Expo alone is stubbed; keep the real scroll container as well as the content view.
57Path(sys.argv[2]).write_text(source + "\n" + stubs + "\n"
58 + (module / "tests/ios/main.swift").read_text() + "\n"
59 + (module / "tests/ios/anchor.swift").read_text() + "\n"
60 + (module / "tests/ios/row-decode.swift").read_text() + "\n"
61 + (module / "tests/ios/token-decode.swift").read_text() + "\n"
62 + (module / "tests/ios/geometry.swift").read_text())
63PYTHON
64"$compiler" -O -target "$(uname -m)-apple-ios16.1-macabi" -sdk "$sdk" \
65 -module-cache-path "$output/module-cache" \
66 -F "$sdk/System/iOSSupport/System/Library/Frameworks" \
67 "$module_dir/ios/ReviewDiffCodeLayout.swift" "$output/main.swift" \
68 -o "$output/layout-tests"
69"$output/layout-tests"