38
const readJson = async <T>(filePath: string): Promise<T> =>
39
JSON.parse(await fs.readFile(filePath, 'utf8')) as T;
40
41
+// BetterSwiftAX 0.1.0 references AXWebConstants added in newer macOS SDKs.
42
+// The constants are plain CFString subrole names, so patch the resolved package
43
+// checkout to string literals before building on GitHub macos-15 runners.
44
+const betterSwiftAxSubroleFallbacks = [
45
+ ['kAXLandmarkComplementarySubrole', 'AXLandmarkComplementary'],
46
+ ['kAXLandmarkContentInfoSubrole', 'AXLandmarkContentInfo'],
47
+ ['kAXLandmarkMainSubrole', 'AXLandmarkMain'],
48
+ ['kAXLandmarkNavigationSubrole', 'AXLandmarkNavigation'],
49
+ ['kAXLandmarkRegionSubrole', 'AXLandmarkRegion'],
50
+ ['kAXLandmarkSearchSubrole', 'AXLandmarkSearch'],
51
+ ['kAXMathFenceOperatorSubrole', 'AXMathFenceOperator'],
52
+ ['kAXMathFencedSubrole', 'AXMathFenced'],
53
+ ['kAXMathFractionSubrole', 'AXMathFraction'],
54
+ ['kAXMathIdentifierSubrole', 'AXMathIdentifier'],
55
+ ['kAXMathMultiscriptSubrole', 'AXMathMultiscript'],
56
+ ['kAXMathNumberSubrole', 'AXMathNumber'],
57
+ ['kAXMathOperatorSubrole', 'AXMathOperator'],
58
+ ['kAXMathRootSubrole', 'AXMathRoot'],
59
+ ['kAXMathRowSubrole', 'AXMathRow'],
60
+ ['kAXMathSeparatorOperatorSubrole', 'AXMathSeparatorOperator'],
61
+ ['kAXMathSquareRootSubrole', 'AXMathSquareRoot'],
62
+ ['kAXMathSubscriptSuperscriptSubrole', 'AXMathSubscriptSuperscript'],
63
+ ['kAXMathTableCellSubrole', 'AXMathTableCell'],
64
+ ['kAXMathTableRowSubrole', 'AXMathTableRow'],
65
+ ['kAXMathTableSubrole', 'AXMathTable'],
66
+ ['kAXMathTextSubrole', 'AXMathText'],
67
+ ['kAXMathUnderOverSubrole', 'AXMathUnderOver'],
68
+ ['kAXMeterSubrole', 'AXMeter'],
69
+ ['kAXRubyInlineSubrole', 'AXRubyInline'],
70
+ ['kAXRubyTextSubrole', 'AXRubyText'],
71
+ ['kAXSubscriptStyleGroupSubrole', 'AXSubscriptStyleGroup'],
72
+ ['kAXSummarySubrole', 'AXSummary'],
73
+ ['kAXSuperscriptStyleGroupSubrole', 'AXSuperscriptStyleGroup'],
74
+ ['kAXTabPanelSubrole', 'AXTabPanel'],
75
+ ['kAXTermSubrole', 'AXTerm'],
76
+ ['kAXTimeGroupSubrole', 'AXTimeGroup'],
77
+ ['kAXUserInterfaceTooltipSubrole', 'AXUserInterfaceTooltip'],
78
+ ['kAXVideoSubrole', 'AXVideo'],
79
+ ['kAXWebApplicationSubrole', 'AXWebApplication'],
80
+] as const;
81
+
82
const ensurePlatform = () => {
83
if (process.platform !== 'darwin') {
84
throw new Error(
122
throw new Error('No upstream license file found in platform-imessage submodule.');
123
};
124
125
+const patchBetterSwiftAxForCurrentSdk = async () => {
126
+ await $`swift package resolve`.cwd(submodulePath);
127
+
128
+ const sourcePath = path.join(
129
+ submodulePath,
130
+ '.build/checkouts/BetterSwiftAX/Sources/AccessibilityControl/Accessibility+Subrole.swift'
131
+ );
132
+ if (!(await exists(sourcePath))) {
133
+ throw new Error(
134
+ 'Swift package resolution completed but BetterSwiftAX Accessibility+Subrole.swift was not found.'
135
+ );
136
+ }
137
+
138
+ const source = await fs.readFile(sourcePath, 'utf8');
139
+ let patched = source;
140
+ for (const [constantName, stringValue] of betterSwiftAxSubroleFallbacks) {
141
+ patched = patched.replaceAll(`= ${constantName}`, `= ("${stringValue}" as CFString)`);
142
+ }
143
+
144
+ if (patched !== source) {
145
+ await fs.chmod(sourcePath, 0o644).catch(() => undefined);
146
+ await fs.writeFile(sourcePath, patched, 'utf8');
147
+ console.log('Patched BetterSwiftAX subrole constants for older macOS SDKs.');
148
+ }
149
+};
150
+
151
const buildTarget = async (target: Target) => {
152
console.log(`Building imessage-cli for ${target.platform} (${target.swiftArch})...`);
153
+ await patchBetterSwiftAxForCurrentSdk();
154
await $`swift build -c release --product imessage-cli --arch ${target.swiftArch}`.cwd(
155
submodulePath
156
);