stim 0.0.0 → 1.1.0
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.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/android-CC5bUer7.mjs +204 -0
- package/dist/android-DnZlT3aU.mjs +2279 -0
- package/dist/android-cas-DGlTStWu.mjs +1078 -0
- package/dist/android-cas-compiler.d.mts +1 -0
- package/dist/android-cas-compiler.mjs +71 -0
- package/dist/android-xmyGBNy5.mjs +665 -0
- package/dist/app-install-oZIQRbdD.mjs +1141 -0
- package/dist/build-lock-vE45ZzJZ.mjs +645 -0
- package/dist/build-slots-CgacA9zQ.mjs +152 -0
- package/dist/cache-manifest-oeH18ERr.mjs +66 -0
- package/dist/cache-manifest.d.mts +27 -0
- package/dist/cache-manifest.mjs +2 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +40 -0
- package/dist/collector-run.d.mts +119 -0
- package/dist/collector-run.mjs +541 -0
- package/dist/command-output-8wHMEde0.mjs +289 -0
- package/dist/config-D7uu8Gbq.mjs +381 -0
- package/dist/deps-64wVnpZc.mjs +435 -0
- package/dist/dev-client-Bvky1hya.mjs +557 -0
- package/dist/device-DJKv5Qej.mjs +250 -0
- package/dist/device-lease-D-G3SgVe.mjs +335 -0
- package/dist/device-pool-BlHXnYYs.mjs +408 -0
- package/dist/device-remote-CCgkG82J.mjs +1209 -0
- package/dist/doctor-BRF9aAJ3.mjs +530 -0
- package/dist/doctor-DlVxTtMq.mjs +1137 -0
- package/dist/error-diagnostics-B5IJwv3-.mjs +636 -0
- package/dist/errors-B6W7FkxQ.mjs +15 -0
- package/dist/exec-bsN9MJXb.mjs +63 -0
- package/dist/gc-DhXdgSdt.mjs +1651 -0
- package/dist/guide-DrhrDBo5.mjs +4319 -0
- package/dist/ios-BZxKPuqP.mjs +382 -0
- package/dist/ios-CK1Vrk6Q.mjs +2721 -0
- package/dist/ios-device-CYbuRNXR.mjs +81 -0
- package/dist/ios-device-CdSm0GDw.mjs +413 -0
- package/dist/logs-Dxoy16Qv.mjs +176 -0
- package/dist/logs-query-oqn47Ffx.mjs +273 -0
- package/dist/metro-B01H3EuD.mjs +184 -0
- package/dist/metro-store-CDDZHtPl.mjs +92 -0
- package/dist/ndjson-DcAtEx_K.mjs +131 -0
- package/dist/ndjson-DvHSsNU9.d.mts +16 -0
- package/dist/ownership-B9QIdQOw.mjs +475 -0
- package/dist/ownership-D8HmSv2E.mjs +60 -0
- package/dist/ownership-claim-CeJLEpjD.mjs +569 -0
- package/dist/process-output-C7IlIzd7.mjs +40 -0
- package/dist/project-COj6nzzh.mjs +243 -0
- package/dist/reclaim-BPvN2HlP.mjs +347 -0
- package/dist/reload-DYZEBbZy.mjs +332 -0
- package/dist/remote-cache-DOi5-zLj.mjs +934 -0
- package/dist/server-bare-BYHqEeyw.mjs +352 -0
- package/dist/server-expo-BEMr_m6p.mjs +312 -0
- package/dist/server-expo-rb0k-0w7.mjs +2 -0
- package/dist/settings-BSwrY4FZ.mjs +687 -0
- package/dist/spawn-entry-nCE6m770.mjs +14 -0
- package/dist/start-ByCylYtB.mjs +822 -0
- package/dist/state-IYEY-zi8.mjs +268 -0
- package/dist/stats-DZ4Q5J-7.mjs +62 -0
- package/dist/stats-wqxPm7Tv.mjs +307 -0
- package/dist/status-Dia0XTqG.mjs +363 -0
- package/dist/stop-BApyaF21.mjs +591 -0
- package/dist/stop-D6o5zAdm.mjs +3 -0
- package/dist/supervisor-run.d.mts +84 -0
- package/dist/supervisor-run.mjs +210 -0
- package/dist/workspace-process-lock-CxOO9-pf.mjs +47 -0
- package/dist/worktree-Dx3ZC5lS.mjs +539 -0
- package/dist/worktree-DxEmUI_n.mjs +1322 -0
- package/dist/xcode-CDB6fytw.mjs +1705 -0
- package/package.json +61 -8
- package/shim/android-cas-pch.cmake +35 -0
- package/shim/android-cas.gradle +29 -0
- package/shim/android-cas.toolchain.cmake +12 -0
- package/shim/android-optimizations.gradle +30 -0
- package/shim/bundle-response.cjs +46 -0
- package/shim/bundle-response.d.cts +5 -0
- package/shim/expo-metro-config.cjs +188 -0
- package/shim/metro-cache-generation.cjs +20 -0
- package/shim/metro-cache-generation.d.cts +5 -0
- package/skill/SKILL.md +14 -0
|
@@ -0,0 +1,2721 @@
|
|
|
1
|
+
import { t as getExecutor } from "./exec-bsN9MJXb.mjs";
|
|
2
|
+
import { S as upsertProject, f as getProject, l as getConcurrencyLimits } from "./config-D7uu8Gbq.mjs";
|
|
3
|
+
import { r as createNdjsonWriter } from "./ndjson-DcAtEx_K.mjs";
|
|
4
|
+
import { D as workspaceLogsDir, T as workspaceDir, _ as writeWorkspaceState, g as writeWorkspaceLaunch, n as MODE_EXPO, p as readWorkspaceState, t as MODE_BARE } from "./state-IYEY-zi8.mjs";
|
|
5
|
+
import { C as removeTemporaryEntry, S as makeTemporaryDirectory, g as repoRoot, s as gitCommonDir } from "./worktree-Dx3ZC5lS.mjs";
|
|
6
|
+
import { a as findProjectRoot, c as projectShortcut, i as detectIsExpo, r as detectBundleId, t as appProjectProblem } from "./project-COj6nzzh.mjs";
|
|
7
|
+
import { i as resolveProjectMetro, r as pidExists } from "./metro-B01H3EuD.mjs";
|
|
8
|
+
import { n as verifyCollectorOwnership } from "./ownership-D8HmSv2E.mjs";
|
|
9
|
+
import { a as easAuthNote, c as loadProjectProvider, d as resolveEasCliBin, f as resolveRemote, i as checkEasAuth, n as UPLOAD_TIMEOUT_MS, o as exitAfterFlush, p as uploadRemote, r as cacheLevel, s as isEasAuthFailureText, t as RESOLVE_TIMEOUT_MS, v as POOL_SETTING_REMEDY, x as parkedMaxSetting } from "./remote-cache-DOi5-zLj.mjs";
|
|
10
|
+
import { D as remoteIosSetting, E as remoteDeviceSettingError, F as unknownSettingKeys, H as resolveOptimizations, L as detectProviders, M as settingShapeErrors, O as resolveCacheProviderConfig, P as tunnelModeSetting, V as optimizationBuildProfile, _ as iosSigningIdentitySha1SettingError, a as SETTING_SHAPE_REMEDY, d as cacheProviderSettingError, f as iosLanHostSetting, g as iosSigningIdentitySha1Setting, h as iosSigningIdentitySettingError, k as resolveSettings, m as iosSigningIdentitySetting, p as iosLanHostSettingError, r as REMOTE_DEVICE_BACKENDS, w as publicUrlSetting, z as artifactCachePolicy } from "./settings-BSwrY4FZ.mjs";
|
|
11
|
+
import { _ as launchErrorPreview, c as launchErrorReport, g as stepTimer, h as stepClock, i as formatDuration, l as phaseLine, m as shortUdid, n as appReadinessMessage, p as shortHash } from "./command-output-8wHMEde0.mjs";
|
|
12
|
+
import { C as launchIosApp, E as unverifiedLaunchLines, O as verifyLaunch, T as readMetroRecords, b as isBundleProof, c as RELEASE_VERIFY_WAIT_MS, f as clearOtherUserApps, i as LAUNCH_BUNDLING, k as verifyReleaseLaunch, m as devClientUrl, n as DEFAULT_METRO_PORT, o as LAUNCH_FATAL, s as LAUNCH_UNVERIFIED, v as installIosApp, w as readCollectorRecords, y as iosAppProcess } from "./app-install-oZIQRbdD.mjs";
|
|
13
|
+
import { d as listIosRuntimes } from "./ios-BZxKPuqP.mjs";
|
|
14
|
+
import { C as untrackedNativeFiles, S as untrackedMissLine, _ as providerUploadOutcome, b as storeBuild, c as buildCacheKey, d as filesystemBuildCapability, f as fingerprintDiffRecord, g as providerDownloadPath, h as prepareProviderDownloadDir, i as releaseBuildLock, l as describeFingerprintMiss, m as fingerprintProject, n as acquireBuildLock, o as takeoverLine, p as fingerprintDiffSuffix, s as waitForBuild, t as WAIT_CEILING_MS, v as refingerprintAfterMutation, y as resolveBuild } from "./build-lock-vE45ZzJZ.mjs";
|
|
15
|
+
import { r as claimFailure } from "./ownership-claim-CeJLEpjD.mjs";
|
|
16
|
+
import { a as lostLine, c as releaseLeaseOnSignal, i as leaseExpiryText, l as runLease, n as DEBUG_VERIFY_STEP_MS, o as lostRefusal, r as acquireRunLease, s as parseDeviceWait, t as selectFromPool, u as waitFlagConflict } from "./device-pool-BlHXnYYs.mjs";
|
|
17
|
+
import { r as releaseBuildSlot, t as acquireBuildSlot } from "./build-slots-CgacA9zQ.mjs";
|
|
18
|
+
import { a as swapJsBundle, c as ensureWorkspaceStorageSafely, d as noMetroMessage, f as noMetroRemedy, l as gateShouldRetry, m as sleep, n as pickDevClientScheme, o as needsPrebuild, p as resolveMetroWithRetry, r as schemesFromInfoPlist, s as runPrebuild, t as devClientScheme, u as launchOutcomeRecord } from "./dev-client-Bvky1hya.mjs";
|
|
19
|
+
import { a as statsProjectKey, i as recordRunStats, n as readRunEstimates, t as createRunRecorder } from "./stats-wqxPm7Tv.mjs";
|
|
20
|
+
import { C as unknownIosDeviceTypeRefusal, _ as checkDeviceCapacity, b as ensureOwnedDevice, c as discoverXcodeProject, d as resolveScheme, i as buildIos, l as readBundleExecutable, m as describeDiagnostic, n as COMPILATION_CACHE_UNAVAILABLE, o as compilationCacheActivityLine, t as COMPILATION_CACHE_NOT_RUN, u as readBundleId, v as clearIosAdoptionPending, w as unknownIosRuntimeRefusal, y as ensureBooted } from "./xcode-CDB6fytw.mjs";
|
|
21
|
+
import { a as ensureMetroReachable, b as ownedSessionName, c as remoteIosDeps, l as resolveRemoteContext, n as binOnPath, o as ensureRemoteBootOwned, r as bundleEntryPoint, w as gateMetroOrigin } from "./device-remote-CCgkG82J.mjs";
|
|
22
|
+
import { t as spawnEntry } from "./spawn-entry-nCE6m770.mjs";
|
|
23
|
+
import { a as printNativeCrashReport, n as IOS_CRASH_REPORT_RETRY, o as simulatorConsolePaths, r as captureNativeCrashes, t as errorDiagnostics } from "./error-diagnostics-B5IJwv3-.mjs";
|
|
24
|
+
import { a as iosDeviceProcess, c as listIosDevices, d as verifyIosDeviceReleaseLaunch, i as installIosDeviceApp, l as localNetworkPending, n as LAUNCH_PROBE_TIMEOUT_MS, o as iosPoolCandidates, r as awaitIosDeviceLaunch, s as iosPoolNoCandidatesRefusal, t as DEVICECTL_INSTALL_TIMEOUT_MS, u as resolveIosPhysicalDevice } from "./ios-device-CdSm0GDw.mjs";
|
|
25
|
+
import { a as runPodInstall, n as podsAreStale, r as readPodState } from "./deps-64wVnpZc.mjs";
|
|
26
|
+
import { existsSync, mkdirSync, mkdtempSync, openSync, rmSync, writeFileSync } from "node:fs";
|
|
27
|
+
import { InvalidArgumentError } from "commander";
|
|
28
|
+
import { X509Certificate } from "node:crypto";
|
|
29
|
+
import { basename, join } from "node:path";
|
|
30
|
+
import { networkInterfaces, tmpdir } from "node:os";
|
|
31
|
+
import chalk from "chalk";
|
|
32
|
+
import { createWarnOnce, loadCacheProvider, resolveTieredBuild, storeTieredBuild } from "@stim-cli/cache";
|
|
33
|
+
//#region src/engine/ios-profile.ts
|
|
34
|
+
const TAG = /<(\/?)\s*([A-Za-z0-9_]+)(?:\s[^>]*?)?(\/?)>/g;
|
|
35
|
+
const ENTITIES = {
|
|
36
|
+
amp: "&",
|
|
37
|
+
lt: "<",
|
|
38
|
+
gt: ">",
|
|
39
|
+
quot: "\"",
|
|
40
|
+
apos: "'"
|
|
41
|
+
};
|
|
42
|
+
var PlistError = class extends Error {};
|
|
43
|
+
function codePoint(value) {
|
|
44
|
+
if (!Number.isInteger(value) || value < 0 || value > 1114111 || value >= 55296 && value <= 57343) throw new PlistError(`character reference out of range: ${value}`);
|
|
45
|
+
return String.fromCodePoint(value);
|
|
46
|
+
}
|
|
47
|
+
function decodeEntities(raw) {
|
|
48
|
+
return raw.replace(/&(#x?[0-9A-Fa-f]+|[a-z]+);/g, (match, body) => {
|
|
49
|
+
if (body.startsWith("#x") || body.startsWith("#X")) return codePoint(Number.parseInt(body.slice(2), 16));
|
|
50
|
+
if (body.startsWith("#")) return codePoint(Number.parseInt(body.slice(1), 10));
|
|
51
|
+
return ENTITIES[body] ?? match;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function peekTag(cursor) {
|
|
55
|
+
TAG.lastIndex = cursor.pos;
|
|
56
|
+
const match = TAG.exec(cursor.xml);
|
|
57
|
+
if (!match) return null;
|
|
58
|
+
return {
|
|
59
|
+
name: (match[2] ?? "").toLowerCase(),
|
|
60
|
+
closing: match[1] === "/",
|
|
61
|
+
selfClosing: match[3] === "/",
|
|
62
|
+
end: TAG.lastIndex
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function takeTag(cursor) {
|
|
66
|
+
const tag = peekTag(cursor);
|
|
67
|
+
if (tag) cursor.pos = tag.end;
|
|
68
|
+
return tag;
|
|
69
|
+
}
|
|
70
|
+
function takeText(cursor, name) {
|
|
71
|
+
const close = cursor.xml.indexOf(`</${name}>`, cursor.pos);
|
|
72
|
+
if (close < 0) {
|
|
73
|
+
cursor.pos = cursor.xml.length;
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
const raw = cursor.xml.slice(cursor.pos, close);
|
|
77
|
+
cursor.pos = close + name.length + 3;
|
|
78
|
+
return raw;
|
|
79
|
+
}
|
|
80
|
+
function parseValue(cursor) {
|
|
81
|
+
const peeked = peekTag(cursor);
|
|
82
|
+
if (!peeked || peeked.closing) return void 0;
|
|
83
|
+
const tag = takeTag(cursor);
|
|
84
|
+
if (tag.selfClosing) {
|
|
85
|
+
if (tag.name === "true") return true;
|
|
86
|
+
if (tag.name === "false") return false;
|
|
87
|
+
if (tag.name === "array") return [];
|
|
88
|
+
if (tag.name === "dict") return {};
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
switch (tag.name) {
|
|
92
|
+
case "plist": return parseValue(cursor);
|
|
93
|
+
case "dict": {
|
|
94
|
+
const out = {};
|
|
95
|
+
for (;;) {
|
|
96
|
+
const next = peekTag(cursor);
|
|
97
|
+
if (!next) break;
|
|
98
|
+
if (next.closing) {
|
|
99
|
+
cursor.pos = next.end;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
cursor.pos = next.end;
|
|
103
|
+
if (next.name !== "key") continue;
|
|
104
|
+
const key = decodeEntities(next.selfClosing ? "" : takeText(cursor, "key"));
|
|
105
|
+
const value = parseValue(cursor);
|
|
106
|
+
if (value !== void 0) out[key] = value;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
case "array": {
|
|
111
|
+
const out = [];
|
|
112
|
+
for (;;) {
|
|
113
|
+
const next = peekTag(cursor);
|
|
114
|
+
if (!next) break;
|
|
115
|
+
if (next.closing) {
|
|
116
|
+
cursor.pos = next.end;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
const value = parseValue(cursor);
|
|
120
|
+
if (value === void 0) break;
|
|
121
|
+
out.push(value);
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
case "string":
|
|
126
|
+
case "key": return decodeEntities(takeText(cursor, tag.name));
|
|
127
|
+
case "integer": return Number.parseInt(takeText(cursor, "integer").trim(), 10);
|
|
128
|
+
case "real": return Number.parseFloat(takeText(cursor, "real").trim());
|
|
129
|
+
case "date": return new Date(takeText(cursor, "date").trim());
|
|
130
|
+
case "data": return Buffer.from(takeText(cursor, "data").replace(/\s+/g, ""), "base64");
|
|
131
|
+
case "true":
|
|
132
|
+
takeText(cursor, "true");
|
|
133
|
+
return true;
|
|
134
|
+
case "false":
|
|
135
|
+
takeText(cursor, "false");
|
|
136
|
+
return false;
|
|
137
|
+
default:
|
|
138
|
+
takeText(cursor, tag.name);
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function parsePlist(xml) {
|
|
143
|
+
if (typeof xml !== "string" || xml.trim() === "") return null;
|
|
144
|
+
const stripped = xml.replace(/<!--[\s\S]*?-->/g, "");
|
|
145
|
+
const start = stripped.indexOf("<plist");
|
|
146
|
+
const cursor = {
|
|
147
|
+
xml: stripped,
|
|
148
|
+
pos: start < 0 ? 0 : start
|
|
149
|
+
};
|
|
150
|
+
try {
|
|
151
|
+
const value = parseValue(cursor);
|
|
152
|
+
return value === void 0 ? null : value;
|
|
153
|
+
} catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function isDict(value) {
|
|
158
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && !Buffer.isBuffer(value) && !(value instanceof Date);
|
|
159
|
+
}
|
|
160
|
+
function stringsOf(value) {
|
|
161
|
+
if (!Array.isArray(value)) return null;
|
|
162
|
+
return value.filter((v) => typeof v === "string");
|
|
163
|
+
}
|
|
164
|
+
function parseProvisioningProfilePlist(xml) {
|
|
165
|
+
const root = parsePlist(xml);
|
|
166
|
+
if (!isDict(root)) return null;
|
|
167
|
+
const entitlements = isDict(root.Entitlements ?? null) ? root.Entitlements : {};
|
|
168
|
+
const teamIdentifier = stringsOf(root.TeamIdentifier);
|
|
169
|
+
const expiration = root.ExpirationDate;
|
|
170
|
+
const certificates = Array.isArray(root.DeveloperCertificates) ? root.DeveloperCertificates.filter((v) => Buffer.isBuffer(v)) : [];
|
|
171
|
+
return {
|
|
172
|
+
name: typeof root.Name === "string" ? root.Name : null,
|
|
173
|
+
uuid: typeof root.UUID === "string" ? root.UUID : null,
|
|
174
|
+
teamIdentifier: teamIdentifier?.[0] ?? null,
|
|
175
|
+
expirationDate: expiration instanceof Date && !Number.isNaN(expiration.getTime()) ? expiration : null,
|
|
176
|
+
provisionedDevices: stringsOf(root.ProvisionedDevices),
|
|
177
|
+
provisionsAllDevices: root.ProvisionsAllDevices === true,
|
|
178
|
+
getTaskAllow: entitlements["get-task-allow"] === true,
|
|
179
|
+
certificates
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function provisioningProfileKind(profile) {
|
|
183
|
+
if (profile.provisionedDevices) return profile.getTaskAllow ? "development" : "ad hoc";
|
|
184
|
+
return profile.provisionsAllDevices ? "enterprise" : "App Store";
|
|
185
|
+
}
|
|
186
|
+
function certificateCommonName(der) {
|
|
187
|
+
if (!Buffer.isBuffer(der) || der.length === 0) return null;
|
|
188
|
+
let subject;
|
|
189
|
+
try {
|
|
190
|
+
subject = new X509Certificate(der).subject;
|
|
191
|
+
} catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
for (const part of String(subject).split(/\r?\n/)) {
|
|
195
|
+
const trimmed = part.trim();
|
|
196
|
+
if (trimmed.startsWith("CN=")) return trimmed.slice(3).trim() || null;
|
|
197
|
+
}
|
|
198
|
+
return /(?:^|,)\s*CN=([^,]+)/.exec(String(subject))?.[1]?.trim() || null;
|
|
199
|
+
}
|
|
200
|
+
const IDENTITY_LINE = /^\s*\d+\)\s+([0-9A-Fa-f]{40})\s+"(.+)"\s*$/;
|
|
201
|
+
function parseSigningIdentities(text) {
|
|
202
|
+
if (typeof text !== "string") return [];
|
|
203
|
+
const out = [];
|
|
204
|
+
for (const line of text.split(/\r?\n/)) {
|
|
205
|
+
const match = IDENTITY_LINE.exec(line);
|
|
206
|
+
if (!match) continue;
|
|
207
|
+
out.push({
|
|
208
|
+
sha1: match[1].toUpperCase(),
|
|
209
|
+
name: match[2]
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
const SIGNING_CODES = {
|
|
215
|
+
noProfile: "STIM_NO_PROFILE",
|
|
216
|
+
profileMismatch: "STIM_PROFILE_MISMATCH",
|
|
217
|
+
noIdentity: "STIM_NO_SIGNING_IDENTITY",
|
|
218
|
+
codesignFailed: "STIM_CODESIGN_FAILED"
|
|
219
|
+
};
|
|
220
|
+
const XCODE_STEP = "build once from Xcode to install it -- Stim will not, because registering a device or minting a profile changes your Apple Developer account.";
|
|
221
|
+
const KEYCHAIN_REMEDY = "Open Xcode > Settings > Accounts and download your certificates, or unlock the login keychain with `security unlock-keychain`. `security find-identity -v -p codesigning` should list `Apple Development: ...`.";
|
|
222
|
+
function signingConfiguration(input) {
|
|
223
|
+
return input.configuration ?? "Debug";
|
|
224
|
+
}
|
|
225
|
+
function profileGate(input) {
|
|
226
|
+
const now = input.now ?? Date.now();
|
|
227
|
+
if (!input.profilePresent) return {
|
|
228
|
+
ok: false,
|
|
229
|
+
code: SIGNING_CODES.noProfile,
|
|
230
|
+
reason: "The app bundle has no embedded.mobileprovision, so it was built unsigned or for the simulator.",
|
|
231
|
+
remedy: `Set a team and profile for the target's ${signingConfiguration(input)} configuration in Xcode > Signing & Capabilities, then ${XCODE_STEP}`
|
|
232
|
+
};
|
|
233
|
+
if (!input.profile) return {
|
|
234
|
+
ok: false,
|
|
235
|
+
code: SIGNING_CODES.noProfile,
|
|
236
|
+
reason: "`security cms -D` could not decode the app bundle's embedded.mobileprovision.",
|
|
237
|
+
remedy: `The profile inside the app is corrupt. Delete the build cache entry with \`stim gc --delete\`, then ${XCODE_STEP}`
|
|
238
|
+
};
|
|
239
|
+
const profile = input.profile;
|
|
240
|
+
const named = profile.name ? `"${profile.name}"` : "the embedded profile";
|
|
241
|
+
if (!profile.expirationDate || profile.expirationDate.getTime() <= now) return {
|
|
242
|
+
ok: false,
|
|
243
|
+
code: SIGNING_CODES.profileMismatch,
|
|
244
|
+
reason: profile.expirationDate ? `The ${provisioningProfileKind(profile)} profile ${named} expired on ${profile.expirationDate.toISOString()}.` : `The ${provisioningProfileKind(profile)} profile ${named} carries no ExpirationDate, so Stim cannot prove it is still valid.`,
|
|
245
|
+
remedy: `Renew the profile under Signing & Capabilities, then ${XCODE_STEP}`
|
|
246
|
+
};
|
|
247
|
+
if (!profile.provisionedDevices) {
|
|
248
|
+
const kind = provisioningProfileKind(profile);
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
code: SIGNING_CODES.profileMismatch,
|
|
252
|
+
reason: `${named} is an ${kind} profile, which carries no ProvisionedDevices list, so Stim cannot prove ${input.udid ?? "the target device"} is admitted.`,
|
|
253
|
+
remedy: `Local device runs need a development profile. Select one under Signing & Capabilities, then ${XCODE_STEP}`
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const udid = input.udid;
|
|
257
|
+
if (!udid || !profile.provisionedDevices.some((d) => d.toLowerCase() === udid.toLowerCase())) return {
|
|
258
|
+
ok: false,
|
|
259
|
+
code: SIGNING_CODES.profileMismatch,
|
|
260
|
+
reason: `The ${provisioningProfileKind(profile)} profile ${named} lists ${profile.provisionedDevices.length} device(s) and ${udid ?? "the target device"} is not one of them.`,
|
|
261
|
+
remedy: `Register ${udid ?? "the device"} at developer.apple.com, regenerate the profile, then ${XCODE_STEP}`
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
ok: true,
|
|
265
|
+
profile
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function signingGate(input) {
|
|
269
|
+
const gated = profileGate(input);
|
|
270
|
+
if (!gated.ok) return gated;
|
|
271
|
+
const profile = gated.profile;
|
|
272
|
+
const named = profile.name ? `"${profile.name}"` : "the embedded profile";
|
|
273
|
+
const identities = Array.isArray(input.identities) ? input.identities : [];
|
|
274
|
+
if (identities.length === 0) return {
|
|
275
|
+
ok: false,
|
|
276
|
+
code: SIGNING_CODES.noIdentity,
|
|
277
|
+
reason: "`security find-identity -v -p codesigning` lists no codesigning identity on this machine.",
|
|
278
|
+
remedy: KEYCHAIN_REMEDY
|
|
279
|
+
};
|
|
280
|
+
if (input.pinnedSha1) {
|
|
281
|
+
const wanted = input.pinnedSha1.trim().toUpperCase();
|
|
282
|
+
const match = identities.find((i) => i.sha1 === wanted);
|
|
283
|
+
if (match) return {
|
|
284
|
+
ok: true,
|
|
285
|
+
identity: match
|
|
286
|
+
};
|
|
287
|
+
return {
|
|
288
|
+
ok: false,
|
|
289
|
+
code: SIGNING_CODES.noIdentity,
|
|
290
|
+
reason: `ios.signingIdentitySha1 is ${wanted}, which is not in the keychain. Available: ${identities.map((i) => `${i.sha1} "${i.name}"`).join(", ")}.`,
|
|
291
|
+
remedy: KEYCHAIN_REMEDY
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const wantedName = input.pinnedName?.trim() || certificateCommonName(profile.certificates[0] ?? null);
|
|
295
|
+
if (!wantedName) return {
|
|
296
|
+
ok: false,
|
|
297
|
+
code: SIGNING_CODES.noIdentity,
|
|
298
|
+
reason: `Stim could not read a signing-identity name out of ${named}: its DeveloperCertificates entry has no readable subject CN.`,
|
|
299
|
+
remedy: "Set ios.signingIdentity in .stim.json to the identity name to re-sign with, or ios.signingIdentitySha1 to its SHA-1 hash."
|
|
300
|
+
};
|
|
301
|
+
const matches = identities.filter((i) => i.name === wantedName);
|
|
302
|
+
if (matches.length === 1) return {
|
|
303
|
+
ok: true,
|
|
304
|
+
identity: matches[0]
|
|
305
|
+
};
|
|
306
|
+
if (matches.length === 0) return {
|
|
307
|
+
ok: false,
|
|
308
|
+
code: SIGNING_CODES.noIdentity,
|
|
309
|
+
reason: `The app was signed by "${wantedName}", which is not in this machine's keychain. Available: ${identities.map((i) => `"${i.name}"`).join(", ")}.`,
|
|
310
|
+
remedy: `${KEYCHAIN_REMEDY} Or set ios.signingIdentity in .stim.json to one of the identities listed above.`
|
|
311
|
+
};
|
|
312
|
+
return {
|
|
313
|
+
ok: false,
|
|
314
|
+
code: SIGNING_CODES.noIdentity,
|
|
315
|
+
reason: `${matches.length} keychain identities share the name "${wantedName}", so Stim cannot pick one: ${matches.map((i) => i.sha1).join(", ")}.`,
|
|
316
|
+
remedy: "Set ios.signingIdentitySha1 in .stim.json to the SHA-1 hash of the certificate to sign with."
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/engine/ios-signing.ts
|
|
321
|
+
const EMBEDDED_PROFILE = "embedded.mobileprovision";
|
|
322
|
+
const SIGNING_TIMEOUT_MS = 12e4;
|
|
323
|
+
function lastLines(text, count = 5) {
|
|
324
|
+
return String(text ?? "").split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.trim() !== "").slice(-count);
|
|
325
|
+
}
|
|
326
|
+
function errorText(error) {
|
|
327
|
+
const withOutput = error;
|
|
328
|
+
const stderr = String(withOutput?.stderr ?? "").trim();
|
|
329
|
+
const stdout = String(withOutput?.stdout ?? "").trim();
|
|
330
|
+
return stderr || stdout || String(withOutput?.message ?? error);
|
|
331
|
+
}
|
|
332
|
+
function readEmbeddedProfile(appPath, { exec = null } = {}) {
|
|
333
|
+
const executor = exec || getExecutor();
|
|
334
|
+
const path = join(appPath, EMBEDDED_PROFILE);
|
|
335
|
+
if (!existsSync(path)) return {
|
|
336
|
+
present: false,
|
|
337
|
+
profile: null
|
|
338
|
+
};
|
|
339
|
+
try {
|
|
340
|
+
return {
|
|
341
|
+
present: true,
|
|
342
|
+
profile: parseProvisioningProfilePlist(executor.runFile("security", [
|
|
343
|
+
"cms",
|
|
344
|
+
"-D",
|
|
345
|
+
"-i",
|
|
346
|
+
path
|
|
347
|
+
], { timeoutMs: SIGNING_TIMEOUT_MS }))
|
|
348
|
+
};
|
|
349
|
+
} catch {
|
|
350
|
+
return {
|
|
351
|
+
present: true,
|
|
352
|
+
profile: null
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function findSigningIdentities({ exec = null } = {}) {
|
|
357
|
+
const executor = exec || getExecutor();
|
|
358
|
+
try {
|
|
359
|
+
return parseSigningIdentities(executor.runFile("security", [
|
|
360
|
+
"find-identity",
|
|
361
|
+
"-v",
|
|
362
|
+
"-p",
|
|
363
|
+
"codesigning"
|
|
364
|
+
], { timeoutMs: SIGNING_TIMEOUT_MS }));
|
|
365
|
+
} catch {
|
|
366
|
+
return [];
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function gateProfileForDevice(options) {
|
|
370
|
+
const read = readEmbeddedProfile(options.appPath, { exec: options.exec ?? null });
|
|
371
|
+
return profileGate({
|
|
372
|
+
profilePresent: read.present,
|
|
373
|
+
profile: read.profile,
|
|
374
|
+
identities: [],
|
|
375
|
+
udid: options.udid,
|
|
376
|
+
configuration: options.configuration ?? null,
|
|
377
|
+
...options.now === void 0 ? {} : { now: options.now }
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function gateAppForDevice(options) {
|
|
381
|
+
const read = readEmbeddedProfile(options.appPath, { exec: options.exec ?? null });
|
|
382
|
+
return signingGate({
|
|
383
|
+
profilePresent: read.present,
|
|
384
|
+
profile: read.profile,
|
|
385
|
+
identities: read.present ? findSigningIdentities({ exec: options.exec ?? null }) : [],
|
|
386
|
+
udid: options.udid,
|
|
387
|
+
configuration: options.configuration ?? null,
|
|
388
|
+
pinnedName: options.pinnedName ?? null,
|
|
389
|
+
pinnedSha1: options.pinnedSha1 ?? null,
|
|
390
|
+
...options.now === void 0 ? {} : { now: options.now }
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function extractEntitlements(appPath, executor) {
|
|
394
|
+
try {
|
|
395
|
+
return String(executor.runFile("codesign", [
|
|
396
|
+
"-d",
|
|
397
|
+
"--entitlements",
|
|
398
|
+
"-",
|
|
399
|
+
"--xml",
|
|
400
|
+
appPath
|
|
401
|
+
], { timeoutMs: SIGNING_TIMEOUT_MS })).trim();
|
|
402
|
+
} catch {
|
|
403
|
+
return "";
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function resealBundle({ appPath, identity, exec = null }) {
|
|
407
|
+
const executor = exec || getExecutor();
|
|
408
|
+
const signAs = identity.sha1 || identity.name;
|
|
409
|
+
let mode = "preserve-metadata";
|
|
410
|
+
let preserveError = null;
|
|
411
|
+
try {
|
|
412
|
+
executor.runFile("codesign", [
|
|
413
|
+
"--force",
|
|
414
|
+
"--sign",
|
|
415
|
+
signAs,
|
|
416
|
+
"--preserve-metadata=identifier,entitlements,flags,runtime",
|
|
417
|
+
appPath
|
|
418
|
+
], { timeoutMs: SIGNING_TIMEOUT_MS });
|
|
419
|
+
} catch (error) {
|
|
420
|
+
preserveError = error;
|
|
421
|
+
}
|
|
422
|
+
let tempDir = null;
|
|
423
|
+
if (preserveError) {
|
|
424
|
+
const entitlements = extractEntitlements(appPath, executor);
|
|
425
|
+
const args = [
|
|
426
|
+
"--force",
|
|
427
|
+
"--sign",
|
|
428
|
+
signAs
|
|
429
|
+
];
|
|
430
|
+
if (entitlements !== "") {
|
|
431
|
+
tempDir = mkdtempSync(join(tmpdir(), "stim-entitlements-"));
|
|
432
|
+
const plist = join(tempDir, "entitlements.plist");
|
|
433
|
+
writeFileSync(plist, `${entitlements}\n`, "utf-8");
|
|
434
|
+
args.push("--entitlements", plist);
|
|
435
|
+
mode = "entitlements";
|
|
436
|
+
} else mode = "no-entitlements";
|
|
437
|
+
args.push(appPath);
|
|
438
|
+
try {
|
|
439
|
+
executor.runFile("codesign", args, { timeoutMs: SIGNING_TIMEOUT_MS });
|
|
440
|
+
} catch (error) {
|
|
441
|
+
return {
|
|
442
|
+
ok: false,
|
|
443
|
+
code: SIGNING_CODES.codesignFailed,
|
|
444
|
+
reason: `codesign could not re-seal ${appPath} with "${identity.name}": ${errorText(error)}`,
|
|
445
|
+
remedy: `Unlock the login keychain (\`security unlock-keychain\`) and confirm exactly one identity matches "${identity.name}".`,
|
|
446
|
+
lastLines: [...lastLines(errorText(preserveError)), ...lastLines(errorText(error))]
|
|
447
|
+
};
|
|
448
|
+
} finally {
|
|
449
|
+
if (tempDir) rmSync(tempDir, {
|
|
450
|
+
recursive: true,
|
|
451
|
+
force: true
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
executor.runFile("codesign", [
|
|
457
|
+
"--verify",
|
|
458
|
+
"--strict",
|
|
459
|
+
appPath
|
|
460
|
+
], { timeoutMs: SIGNING_TIMEOUT_MS });
|
|
461
|
+
} catch (error) {
|
|
462
|
+
return {
|
|
463
|
+
ok: false,
|
|
464
|
+
code: SIGNING_CODES.codesignFailed,
|
|
465
|
+
reason: `codesign --verify --strict rejected ${appPath} after re-sealing it with "${identity.name}": ${errorText(error)}`,
|
|
466
|
+
remedy: "The bundle signed but did not seal. Delete the cached artifact with `stim gc --delete` and build fresh, then retry.",
|
|
467
|
+
lastLines: lastLines(errorText(error))
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
ok: true,
|
|
472
|
+
identity,
|
|
473
|
+
mode
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function sealAppForDevice(options) {
|
|
477
|
+
const gate = gateAppForDevice(options);
|
|
478
|
+
if (!gate.ok) return {
|
|
479
|
+
...gate,
|
|
480
|
+
lastLines: []
|
|
481
|
+
};
|
|
482
|
+
return resealBundle({
|
|
483
|
+
appPath: options.appPath,
|
|
484
|
+
identity: gate.identity,
|
|
485
|
+
exec: options.exec ?? null
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/engine/ios-lan.ts
|
|
490
|
+
const IP_TXT = "ip.txt";
|
|
491
|
+
function chooseLanAddress({ pinned = null, candidates }) {
|
|
492
|
+
const list = Array.isArray(candidates) ? candidates : [];
|
|
493
|
+
if (pinned) return {
|
|
494
|
+
address: pinned,
|
|
495
|
+
interfaceName: list.find((candidate) => candidate.address === pinned)?.interfaceName ?? null,
|
|
496
|
+
pinned: true,
|
|
497
|
+
candidates: list.length
|
|
498
|
+
};
|
|
499
|
+
const first = list[0];
|
|
500
|
+
if (!first) return null;
|
|
501
|
+
return {
|
|
502
|
+
address: first.address,
|
|
503
|
+
interfaceName: first.interfaceName,
|
|
504
|
+
pinned: false,
|
|
505
|
+
candidates: list.length
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
function lanOriginUrlFor(address, port) {
|
|
509
|
+
return `http://${address}:${port}`;
|
|
510
|
+
}
|
|
511
|
+
function ipTxtContents(address, port) {
|
|
512
|
+
return `${String(address).trim()}:${String(port).trim()}\n`;
|
|
513
|
+
}
|
|
514
|
+
function writeIpTxt(appPath, address, port, { write = writeFileSync } = {}) {
|
|
515
|
+
const path = join(appPath, IP_TXT);
|
|
516
|
+
write(path, ipTxtContents(address, port), "utf-8");
|
|
517
|
+
return path;
|
|
518
|
+
}
|
|
519
|
+
async function ensureLanReachable({ origin, metroPort, root, isExpo, logsDir, gateOrigin = gateMetroOrigin, readRecords = null }) {
|
|
520
|
+
const result = await gateOrigin({
|
|
521
|
+
origin,
|
|
522
|
+
metroPort,
|
|
523
|
+
platform: "ios",
|
|
524
|
+
entryPoint: bundleEntryPoint(root, isExpo),
|
|
525
|
+
readRecords: readRecords ?? (() => readMetroRecords(logsDir)),
|
|
526
|
+
isProof: isBundleProof
|
|
527
|
+
});
|
|
528
|
+
if (result.failed) return {
|
|
529
|
+
failed: result.reason ?? `${origin} is not this workspace's Metro.`,
|
|
530
|
+
remedy: `The phone reaches Metro at ${origin}, so that address has to serve THIS workspace's dev server. \`stim start\` prints the port it reserved. Set ios.lanHost in .stim.json when this Mac has several network interfaces and the phone shares one that is not the first.`
|
|
531
|
+
};
|
|
532
|
+
return { ok: true };
|
|
533
|
+
}
|
|
534
|
+
function copyAppAside(appPath, { exec = null, mkdtemp = () => makeTemporaryDirectory(appPath, "stim-ios-device-") } = {}) {
|
|
535
|
+
const e = exec || getExecutor();
|
|
536
|
+
const tmpDir = mkdtemp();
|
|
537
|
+
const copy = join(tmpDir, basename(appPath));
|
|
538
|
+
try {
|
|
539
|
+
e.runFile("cp", [
|
|
540
|
+
"-c",
|
|
541
|
+
"-R",
|
|
542
|
+
appPath,
|
|
543
|
+
copy
|
|
544
|
+
]);
|
|
545
|
+
} catch {
|
|
546
|
+
try {
|
|
547
|
+
e.runFile("cp", [
|
|
548
|
+
"-R",
|
|
549
|
+
appPath,
|
|
550
|
+
copy
|
|
551
|
+
]);
|
|
552
|
+
} catch (error) {
|
|
553
|
+
removeTemporaryEntry(tmpDir);
|
|
554
|
+
throw error;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
tmpDir,
|
|
559
|
+
appPath: copy
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/engine/lan-address.ts
|
|
564
|
+
const EN_INTERFACE = /^en(\d+)$/;
|
|
565
|
+
const EXCLUDED_INTERFACE = /^(?:utun|bridge|awdl)/;
|
|
566
|
+
const LINK_LOCAL = /^169\.254\./;
|
|
567
|
+
function isIpv4(entry) {
|
|
568
|
+
return entry.family === "IPv4" || entry.family === 4;
|
|
569
|
+
}
|
|
570
|
+
function lanCandidates(interfaces) {
|
|
571
|
+
const ranked = [];
|
|
572
|
+
const seen = /* @__PURE__ */ new Set();
|
|
573
|
+
for (const [interfaceName, entries] of Object.entries(interfaces ?? {})) {
|
|
574
|
+
if (EXCLUDED_INTERFACE.test(interfaceName)) continue;
|
|
575
|
+
const en = EN_INTERFACE.exec(interfaceName);
|
|
576
|
+
for (const entry of entries ?? []) {
|
|
577
|
+
if (!entry || typeof entry !== "object" || !isIpv4(entry) || entry.internal === true) continue;
|
|
578
|
+
const address = typeof entry.address === "string" ? entry.address.trim() : "";
|
|
579
|
+
if (address === "" || LINK_LOCAL.test(address)) continue;
|
|
580
|
+
if (seen.has(address)) continue;
|
|
581
|
+
seen.add(address);
|
|
582
|
+
ranked.push({
|
|
583
|
+
interfaceName,
|
|
584
|
+
address,
|
|
585
|
+
rank: en ? 0 : 1,
|
|
586
|
+
index: en ? Number(en[1]) : 0
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
ranked.sort((a, b) => a.rank - b.rank || a.index - b.index || a.interfaceName.localeCompare(b.interfaceName) || a.address.localeCompare(b.address));
|
|
591
|
+
return ranked.map(({ interfaceName, address }) => ({
|
|
592
|
+
interfaceName,
|
|
593
|
+
address
|
|
594
|
+
}));
|
|
595
|
+
}
|
|
596
|
+
function hostLanCandidates(interfaces = networkInterfaces) {
|
|
597
|
+
return lanCandidates(interfaces());
|
|
598
|
+
}
|
|
599
|
+
function buildLogFile(root) {
|
|
600
|
+
return join(workspaceLogsDir(root), `build-ios.ndjson`);
|
|
601
|
+
}
|
|
602
|
+
const MAX_PRINTED_DIAGNOSTICS = 6;
|
|
603
|
+
function deviceLabel(device, udid) {
|
|
604
|
+
const name = device?.deviceName || device?.name || null;
|
|
605
|
+
return name ? `${name} (${shortUdid(udid)})` : shortUdid(udid);
|
|
606
|
+
}
|
|
607
|
+
function deviceShortName(device, udid) {
|
|
608
|
+
return device?.deviceName || device?.name || shortUdid(udid);
|
|
609
|
+
}
|
|
610
|
+
function appNameFromPath(appPath) {
|
|
611
|
+
if (typeof appPath !== "string" || appPath.trim() === "") return null;
|
|
612
|
+
const name = basename(appPath).replace(/\.app$/i, "");
|
|
613
|
+
return name === "" ? null : name;
|
|
614
|
+
}
|
|
615
|
+
function iosConfigurationSetting(settings) {
|
|
616
|
+
const ios = settings?.["ios"];
|
|
617
|
+
if (!ios || typeof ios !== "object" || Array.isArray(ios)) return null;
|
|
618
|
+
const raw = ios["configuration"];
|
|
619
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw.trim() : null;
|
|
620
|
+
}
|
|
621
|
+
function resolveConfiguration(flag, settings) {
|
|
622
|
+
return (typeof flag === "string" && flag.trim() !== "" ? flag.trim() : null) || iosConfigurationSetting(settings);
|
|
623
|
+
}
|
|
624
|
+
function iosStringSetting(settings, key) {
|
|
625
|
+
const ios = settings?.["ios"];
|
|
626
|
+
if (!ios || typeof ios !== "object" || Array.isArray(ios)) return null;
|
|
627
|
+
const raw = ios[key];
|
|
628
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw.trim() : null;
|
|
629
|
+
}
|
|
630
|
+
function resolveDeviceType(flag, settings) {
|
|
631
|
+
return (typeof flag === "string" && flag.trim() !== "" ? flag.trim() : null) || iosStringSetting(settings, "deviceType");
|
|
632
|
+
}
|
|
633
|
+
function resolveRuntime(flag, settings) {
|
|
634
|
+
return (typeof flag === "string" && flag.trim() !== "" ? flag.trim() : null) || iosStringSetting(settings, "runtime");
|
|
635
|
+
}
|
|
636
|
+
function deviceModelRefusal({ deviceTypeFlag, runtimeFlag, deviceType, runtime, physical, remoteBackend, listRuntimes }) {
|
|
637
|
+
if (typeof deviceTypeFlag === "string" && deviceTypeFlag.trim() === "") return {
|
|
638
|
+
code: "STIM_BAD_ARG",
|
|
639
|
+
message: "--device-type was given an empty name.",
|
|
640
|
+
remedy: "Pass `--device-type <name>` with a model `xcrun simctl list devicetypes` names, e.g. \"iPad Pro 13-inch (M4)\"."
|
|
641
|
+
};
|
|
642
|
+
if (typeof runtimeFlag === "string" && runtimeFlag.trim() === "") return {
|
|
643
|
+
code: "STIM_BAD_ARG",
|
|
644
|
+
message: "--runtime was given an empty version.",
|
|
645
|
+
remedy: "Pass `--runtime <version>` with a runtime `xcrun simctl list runtimes` reports, e.g. \"18.5\"."
|
|
646
|
+
};
|
|
647
|
+
if (physical || remoteBackend) return null;
|
|
648
|
+
if (!deviceType && !runtime) return null;
|
|
649
|
+
let runtimes;
|
|
650
|
+
try {
|
|
651
|
+
runtimes = listRuntimes();
|
|
652
|
+
} catch (error) {
|
|
653
|
+
return {
|
|
654
|
+
code: "STIM_NO_DEVICE",
|
|
655
|
+
message: `Could not read the installed simulator runtimes: ${error?.message || error}`,
|
|
656
|
+
remedy: "Run `stim doctor` to check the simulator toolchain, then try again."
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
const refusal = unknownIosRuntimeRefusal(runtime, runtimes) ?? unknownIosDeviceTypeRefusal(deviceType, runtimes, runtime);
|
|
660
|
+
return refusal ? {
|
|
661
|
+
code: "STIM_BAD_ARG",
|
|
662
|
+
message: refusal.message,
|
|
663
|
+
remedy: refusal.remedy
|
|
664
|
+
} : null;
|
|
665
|
+
}
|
|
666
|
+
function isReleaseConfiguration(configuration) {
|
|
667
|
+
return typeof configuration === "string" && configuration.trim() !== "" && configuration.trim().toLowerCase() !== "debug";
|
|
668
|
+
}
|
|
669
|
+
function podAction(podState, verdict) {
|
|
670
|
+
if (verdict?.stale) return {
|
|
671
|
+
install: true,
|
|
672
|
+
reason: verdict.reason
|
|
673
|
+
};
|
|
674
|
+
if (verdict?.noPods && podState?.hasPodfile) return {
|
|
675
|
+
install: true,
|
|
676
|
+
reason: "ios/Podfile exists but no pods are installed"
|
|
677
|
+
};
|
|
678
|
+
return { install: false };
|
|
679
|
+
}
|
|
680
|
+
function xcodeFailureReport(result, logPath) {
|
|
681
|
+
const diagnostics = Array.isArray(result?.diagnostics) ? result.diagnostics : [];
|
|
682
|
+
const code = result?.exitCode;
|
|
683
|
+
const how = code === null || code === void 0 ? "" : ` (exit code ${code})`;
|
|
684
|
+
return {
|
|
685
|
+
message: diagnostics.length ? `\`xcodebuild\` failed${how} with ${diagnostics.length} diagnostic${diagnostics.length === 1 ? "" : "s"}.` : `\`xcodebuild\` failed${how} with no recognizable diagnostic.`,
|
|
686
|
+
remedy: diagnostics.find((d) => d?.remedy)?.remedy || `See ${logPath} for the transcript.`
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
function printDiagnostics(note, result) {
|
|
690
|
+
const diagnostics = Array.isArray(result?.diagnostics) ? result.diagnostics : [];
|
|
691
|
+
const shown = diagnostics.slice(0, MAX_PRINTED_DIAGNOSTICS);
|
|
692
|
+
for (const diagnostic of shown) note(chalk.red(phaseLine("error", describeDiagnostic(diagnostic))));
|
|
693
|
+
const hidden = diagnostics.length - shown.length + (result?.truncated || 0);
|
|
694
|
+
if (hidden > 0) note(chalk.dim(phaseLine("error", `... and ${hidden} more diagnostic${hidden === 1 ? "" : "s"} in the log`)));
|
|
695
|
+
if (diagnostics.length === 0) {
|
|
696
|
+
note(chalk.red(phaseLine("error", "xcodebuild failed with no recognizable diagnostic; last lines:")));
|
|
697
|
+
for (const line of (result?.tail || []).slice(-5)) note(chalk.dim(phaseLine("", line)));
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/commands/ios/collector.ts
|
|
702
|
+
function collectorLogFile(root) {
|
|
703
|
+
return join(workspaceLogsDir(root), `collector-ios.log`);
|
|
704
|
+
}
|
|
705
|
+
function collectorEntry() {
|
|
706
|
+
return spawnEntry("collector-run");
|
|
707
|
+
}
|
|
708
|
+
const COLLECTOR_EXIT_WAIT_MS = 2e3;
|
|
709
|
+
const COLLECTOR_POLL_MS = 25;
|
|
710
|
+
async function stopPreviousCollector({ root, kill = (pid, signal) => process.kill(pid, signal), alive = pidExists, readState = readWorkspaceState, verify = verifyCollectorOwnership, waitMs = COLLECTOR_EXIT_WAIT_MS, note = (_line) => {} }) {
|
|
711
|
+
const previous = (readState(root)?.collectors)?.["ios"] || null;
|
|
712
|
+
const previousPid = Number(previous?.pid) || null;
|
|
713
|
+
let killed = null;
|
|
714
|
+
if (previousPid) {
|
|
715
|
+
const ownership = verify({
|
|
716
|
+
pid: previousPid,
|
|
717
|
+
platform: "ios",
|
|
718
|
+
root,
|
|
719
|
+
isAlive: alive,
|
|
720
|
+
expected: previous
|
|
721
|
+
});
|
|
722
|
+
if (ownership.status === "ours") {
|
|
723
|
+
try {
|
|
724
|
+
kill(previousPid, "SIGTERM");
|
|
725
|
+
killed = previousPid;
|
|
726
|
+
} catch (err) {
|
|
727
|
+
if (err?.code !== "ESRCH") note(chalk.yellow(`Could not stop the previous ios log collector (pid ${previousPid}): ${err?.message || err}`));
|
|
728
|
+
}
|
|
729
|
+
const deadline = Date.now() + waitMs;
|
|
730
|
+
while (Date.now() < deadline && alive(previousPid)) await sleep(COLLECTOR_POLL_MS);
|
|
731
|
+
} else if (ownership.status === "unverified") note(chalk.dim(`Previous ios log collector (pid ${previousPid}): ${ownership.reason}, so it was not signalled -- starting a replacement anyway`));
|
|
732
|
+
}
|
|
733
|
+
return { killed };
|
|
734
|
+
}
|
|
735
|
+
async function replaceCollector({ root, udid, bundleId, appName, appExecutable, physical = false, payloadUrl = null, spawn = (cmd, args, opts) => getExecutor().spawn(cmd, args, opts), kill = (pid, signal) => process.kill(pid, signal), alive = pidExists, readState = readWorkspaceState, verify = verifyCollectorOwnership, waitMs = COLLECTOR_EXIT_WAIT_MS, note = (_line) => {} }) {
|
|
736
|
+
const { killed } = await stopPreviousCollector({
|
|
737
|
+
root,
|
|
738
|
+
kill,
|
|
739
|
+
alive,
|
|
740
|
+
readState,
|
|
741
|
+
verify,
|
|
742
|
+
waitMs,
|
|
743
|
+
note
|
|
744
|
+
});
|
|
745
|
+
const args = [
|
|
746
|
+
collectorEntry(),
|
|
747
|
+
"--platform",
|
|
748
|
+
"ios",
|
|
749
|
+
"--root",
|
|
750
|
+
root,
|
|
751
|
+
"--udid",
|
|
752
|
+
udid,
|
|
753
|
+
"--bundle",
|
|
754
|
+
bundleId
|
|
755
|
+
];
|
|
756
|
+
if (appName) args.push("--app-name", appName);
|
|
757
|
+
if (appExecutable) args.push("--app-executable", appExecutable);
|
|
758
|
+
if (physical) args.push("--physical");
|
|
759
|
+
if (payloadUrl) args.push("--payload-url", payloadUrl);
|
|
760
|
+
let stdio = "ignore";
|
|
761
|
+
try {
|
|
762
|
+
mkdirSync(workspaceLogsDir(root), { recursive: true });
|
|
763
|
+
const fd = openSync(collectorLogFile(root), "a");
|
|
764
|
+
stdio = [
|
|
765
|
+
"ignore",
|
|
766
|
+
fd,
|
|
767
|
+
fd
|
|
768
|
+
];
|
|
769
|
+
} catch {}
|
|
770
|
+
let child;
|
|
771
|
+
try {
|
|
772
|
+
child = spawn(process.execPath, args, {
|
|
773
|
+
cwd: root,
|
|
774
|
+
detached: true,
|
|
775
|
+
stdio,
|
|
776
|
+
env: process.env
|
|
777
|
+
});
|
|
778
|
+
child?.unref?.();
|
|
779
|
+
} catch (err) {
|
|
780
|
+
note(chalk.yellow(`Could not start the ios log collector: ${err?.message || err}`));
|
|
781
|
+
return {
|
|
782
|
+
killed,
|
|
783
|
+
pid: null
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
killed,
|
|
788
|
+
pid: child?.pid ?? null
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
//#endregion
|
|
792
|
+
//#region src/commands/ios/dependencies.ts
|
|
793
|
+
const DEFAULT_DEPS = {
|
|
794
|
+
findProjectRoot,
|
|
795
|
+
resolveSettings,
|
|
796
|
+
gitCommonDir,
|
|
797
|
+
repoRoot,
|
|
798
|
+
detectBundleId,
|
|
799
|
+
detectIsExpo,
|
|
800
|
+
devClientScheme,
|
|
801
|
+
getProject,
|
|
802
|
+
upsertProject,
|
|
803
|
+
projectShortcut,
|
|
804
|
+
checkDeviceCapacity,
|
|
805
|
+
ensureOwnedDevice,
|
|
806
|
+
listIosRuntimes,
|
|
807
|
+
ensureBooted,
|
|
808
|
+
resolveRemoteContext,
|
|
809
|
+
remoteIosDeps,
|
|
810
|
+
ensureMetroReachable,
|
|
811
|
+
ensureRemoteBootOwned,
|
|
812
|
+
detectProviders,
|
|
813
|
+
resolveProjectMetro,
|
|
814
|
+
resolveMetroWithRetry,
|
|
815
|
+
readWorkspaceState,
|
|
816
|
+
pidExists,
|
|
817
|
+
getConcurrencyLimits,
|
|
818
|
+
fingerprintProject,
|
|
819
|
+
untrackedNativeFiles,
|
|
820
|
+
resolveBuild,
|
|
821
|
+
storeBuild,
|
|
822
|
+
resolveCacheProviderConfig,
|
|
823
|
+
loadCacheProvider,
|
|
824
|
+
acquireBuildLock,
|
|
825
|
+
releaseBuildLock,
|
|
826
|
+
waitForBuild,
|
|
827
|
+
acquireBuildSlot,
|
|
828
|
+
releaseBuildSlot,
|
|
829
|
+
loadProjectProvider,
|
|
830
|
+
checkEasAuth,
|
|
831
|
+
resolveEasCliBin,
|
|
832
|
+
resolveRemote,
|
|
833
|
+
uploadRemote,
|
|
834
|
+
needsPrebuild,
|
|
835
|
+
runPrebuild,
|
|
836
|
+
readPodState,
|
|
837
|
+
podsAreStale,
|
|
838
|
+
runPodInstall,
|
|
839
|
+
buildIos,
|
|
840
|
+
discoverXcodeProject,
|
|
841
|
+
resolveScheme,
|
|
842
|
+
listIosDevices,
|
|
843
|
+
hostLanCandidates,
|
|
844
|
+
ensureLanReachable,
|
|
845
|
+
gateProfileForDevice,
|
|
846
|
+
sealAppForDevice,
|
|
847
|
+
installIosDeviceApp,
|
|
848
|
+
awaitIosDeviceLaunch,
|
|
849
|
+
acquireRunLease,
|
|
850
|
+
runLease,
|
|
851
|
+
selectFromPool,
|
|
852
|
+
releaseLeaseOnSignal,
|
|
853
|
+
iosDeviceProcess,
|
|
854
|
+
verifyIosDeviceReleaseLaunch,
|
|
855
|
+
readBundleId,
|
|
856
|
+
readBundleExecutable,
|
|
857
|
+
swapJsBundle,
|
|
858
|
+
installIosApp,
|
|
859
|
+
clearOtherUserApps,
|
|
860
|
+
clearIosAdoptionPending,
|
|
861
|
+
launchIosApp,
|
|
862
|
+
verifyLaunch,
|
|
863
|
+
verifyReleaseLaunch,
|
|
864
|
+
ensureWorkspaceStorage: ensureWorkspaceStorageSafely,
|
|
865
|
+
replaceCollector,
|
|
866
|
+
stopPreviousCollector,
|
|
867
|
+
writeWorkspaceLaunch,
|
|
868
|
+
writeWorkspaceState,
|
|
869
|
+
createWriter: createNdjsonWriter,
|
|
870
|
+
recordStats: recordRunStats,
|
|
871
|
+
readEstimates: readRunEstimates,
|
|
872
|
+
now: () => Date.now()
|
|
873
|
+
};
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region src/commands/ios/result.ts
|
|
876
|
+
function lastBuildRecord({ fingerprint = null, cacheKey = null, cacheHit = false, cacheSkipped = false, durationMs = 0, appPath = null, bundleId = null, startedAt, status, errorCode = null }) {
|
|
877
|
+
const record = {
|
|
878
|
+
platform: "ios",
|
|
879
|
+
fingerprint,
|
|
880
|
+
cacheKey,
|
|
881
|
+
cacheHit: cacheLevel(cacheHit),
|
|
882
|
+
cacheSkipped: Boolean(cacheSkipped),
|
|
883
|
+
durationMs,
|
|
884
|
+
appPath,
|
|
885
|
+
bundleId,
|
|
886
|
+
startedAt,
|
|
887
|
+
status
|
|
888
|
+
};
|
|
889
|
+
if (errorCode) record.errorCode = errorCode;
|
|
890
|
+
return record;
|
|
891
|
+
}
|
|
892
|
+
function iosFacts({ udid, deviceName, deviceType = null, runtime = null, fingerprint, configuration = null, scheme = null, cacheKey, cacheHit, cacheSkipped = false, compilationCache = COMPILATION_CACHE_NOT_RUN, waitedForBuild = null, appPath, bundleId, installSkipped = false, metroPort, logsDir, durationMs, launched = true, webPreviewUrl = null, lease }) {
|
|
893
|
+
return {
|
|
894
|
+
platform: "ios",
|
|
895
|
+
udid,
|
|
896
|
+
deviceName: deviceName ?? null,
|
|
897
|
+
deviceType: deviceType ?? null,
|
|
898
|
+
runtime: runtime ?? null,
|
|
899
|
+
fingerprint,
|
|
900
|
+
configuration: configuration ?? null,
|
|
901
|
+
...scheme ? { scheme } : {},
|
|
902
|
+
cacheKey,
|
|
903
|
+
cacheHit: cacheLevel(cacheHit),
|
|
904
|
+
cacheSkipped: Boolean(cacheSkipped),
|
|
905
|
+
compilationCache,
|
|
906
|
+
waitedForBuild: waitedForBuild ? {
|
|
907
|
+
pid: waitedForBuild.pid ?? null,
|
|
908
|
+
ms: waitedForBuild.ms ?? 0
|
|
909
|
+
} : null,
|
|
910
|
+
appPath,
|
|
911
|
+
bundleId,
|
|
912
|
+
installSkipped: Boolean(installSkipped),
|
|
913
|
+
launched: launched === "unverified" || launched === "bundling" ? launched : Boolean(launched),
|
|
914
|
+
metroPort,
|
|
915
|
+
logs: { dir: logsDir },
|
|
916
|
+
durationMs,
|
|
917
|
+
...webPreviewUrl ? { webPreviewUrl } : {},
|
|
918
|
+
...lease === void 0 ? {} : { lease }
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
function writeLastBuild(root, record, { write = writeWorkspaceState } = {}) {
|
|
922
|
+
try {
|
|
923
|
+
write(root, { lastBuild: record });
|
|
924
|
+
} catch {}
|
|
925
|
+
return record;
|
|
926
|
+
}
|
|
927
|
+
async function finishIosUpload(uploadPending, remote, phase, note) {
|
|
928
|
+
if (!uploadPending) return false;
|
|
929
|
+
const upload = await uploadPending;
|
|
930
|
+
if (upload?.uploaded) phase("cache", `uploaded (${remote?.name})`);
|
|
931
|
+
else if (upload?.timedOut) {
|
|
932
|
+
note(chalk.yellow(phaseLine("cache", `${remote?.name} upload still running after ${formatDuration(UPLOAD_TIMEOUT_MS)}; not waiting`)));
|
|
933
|
+
return true;
|
|
934
|
+
} else if (upload?.failed) {
|
|
935
|
+
const authNote = remote?.name === "eas" && isEasAuthFailureText(upload.failed) ? easAuthNote({
|
|
936
|
+
code: "logged-out",
|
|
937
|
+
reason: upload.failed,
|
|
938
|
+
phase: "upload"
|
|
939
|
+
}) : null;
|
|
940
|
+
note(chalk.yellow(phaseLine("cache", authNote || `${remote?.name} upload failed: ${upload.failed}`)));
|
|
941
|
+
}
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
function reportIosResult({ d, root, json, release, configuration, buildScheme = null, metroCheck, metroPort, logsDir, device, udid, appPath, bundleId, installSkipped, elapsed, startedAt, storeHash, storeKey, cacheHit, compilationCache, useBuildCache, waitedForBuild, launchState, launchWarning, remote, providerName, closeWriter, webPreviewUrl, lease, recordRun }) {
|
|
945
|
+
const durationMs = elapsed();
|
|
946
|
+
recordRun({
|
|
947
|
+
failed: false,
|
|
948
|
+
cacheHit,
|
|
949
|
+
waited: waitedForBuild,
|
|
950
|
+
durationMs
|
|
951
|
+
});
|
|
952
|
+
writeLastBuild(root, lastBuildRecord({
|
|
953
|
+
fingerprint: storeHash,
|
|
954
|
+
cacheKey: storeKey,
|
|
955
|
+
cacheHit,
|
|
956
|
+
cacheSkipped: !useBuildCache,
|
|
957
|
+
durationMs,
|
|
958
|
+
appPath,
|
|
959
|
+
bundleId,
|
|
960
|
+
startedAt,
|
|
961
|
+
status: "ok"
|
|
962
|
+
}), { write: d.writeWorkspaceState });
|
|
963
|
+
closeWriter();
|
|
964
|
+
const facts = iosFacts({
|
|
965
|
+
udid,
|
|
966
|
+
deviceName: device?.deviceName ?? null,
|
|
967
|
+
deviceType: device?.deviceType,
|
|
968
|
+
runtime: device?.runtime,
|
|
969
|
+
fingerprint: storeHash,
|
|
970
|
+
configuration,
|
|
971
|
+
scheme: buildScheme,
|
|
972
|
+
cacheKey: storeKey,
|
|
973
|
+
cacheHit,
|
|
974
|
+
compilationCache,
|
|
975
|
+
cacheSkipped: !useBuildCache,
|
|
976
|
+
waitedForBuild,
|
|
977
|
+
appPath,
|
|
978
|
+
bundleId,
|
|
979
|
+
installSkipped,
|
|
980
|
+
metroPort,
|
|
981
|
+
logsDir,
|
|
982
|
+
durationMs,
|
|
983
|
+
launched: launchState,
|
|
984
|
+
webPreviewUrl,
|
|
985
|
+
lease
|
|
986
|
+
});
|
|
987
|
+
if (json) console.log(JSON.stringify(facts));
|
|
988
|
+
else {
|
|
989
|
+
const summary = `${launchWarning ? "WARNING" : "OK"}: ${bundleId} on ${deviceLabel(device, udid)}, ` + (release ? `${configuration} (embedded JS, no Metro)` : `Metro port ${metroPort}`) + ` (${cacheDescription(cacheHit, remote?.name ?? providerName)}, ${formatDuration(durationMs)})`;
|
|
990
|
+
const outcome = launchWarning ? chalk.yellow(`${summary} -- ${launchWarning}`) : launchState === "unverified" ? chalk.yellow(`${summary} -- launch UNVERIFIED`) : launchState === "bundling" ? chalk.green(`${summary} -- bundle requested, still building`) : chalk.green(summary);
|
|
991
|
+
const deviceName = device?.deviceName ?? device?.name ?? udid;
|
|
992
|
+
const cacheResult = useBuildCache ? cacheDescription(cacheHit, remote?.name ?? providerName) : "bypassed; built";
|
|
993
|
+
const metroResult = release ? `embedded (${configuration})` : !metroCheck ? `check skipped on port ${metroPort}` : launchState === "unverified" ? `state unverified on port ${metroPort}` : `running on port ${metroPort}`;
|
|
994
|
+
console.log([
|
|
995
|
+
outcome,
|
|
996
|
+
phaseLine("device", `${deviceName} (${udid})`),
|
|
997
|
+
phaseLine("app", bundleId),
|
|
998
|
+
phaseLine("metro", metroResult),
|
|
999
|
+
phaseLine("cache", cacheResult),
|
|
1000
|
+
...compilationCache.status === "not-run" ? [phaseLine("compilation cache", compilationCacheActivityLine(compilationCache))] : [],
|
|
1001
|
+
phaseLine("logs", logsDir)
|
|
1002
|
+
].join("\n"));
|
|
1003
|
+
if (facts.webPreviewUrl) console.error(chalk.dim(`Watch this device: ${facts.webPreviewUrl}`));
|
|
1004
|
+
}
|
|
1005
|
+
return facts;
|
|
1006
|
+
}
|
|
1007
|
+
function cacheDescription(cacheHit, providerName = null) {
|
|
1008
|
+
if (cacheHit === "remote") return `from ${providerName || "the remote cache"}`;
|
|
1009
|
+
if (cacheHit === "local") return "from cache";
|
|
1010
|
+
return "built";
|
|
1011
|
+
}
|
|
1012
|
+
//#endregion
|
|
1013
|
+
//#region src/commands/ios/launch.ts
|
|
1014
|
+
function missingCrashReportHint({ physical, remote, crashed }) {
|
|
1015
|
+
return crashed && !physical && !remote ? `No attributable native crash report captured yet. ${IOS_CRASH_REPORT_RETRY}` : "No attributable native crash report captured. Read `stim logs --source device` for available output.";
|
|
1016
|
+
}
|
|
1017
|
+
async function verifyIosRun({ root, appPath, d, release, launched, configuration, phase, note, metroCheck, logsDir, launchedAt, metroPort, isExpo, bundleId, udid, scheme, physical, appName, lanAddress, lanOrigin, remoteDevice, metroOrigin }) {
|
|
1018
|
+
const readNativeCrashes = () => remoteDevice ? [] : captureNativeCrashes({
|
|
1019
|
+
root,
|
|
1020
|
+
platform: "ios",
|
|
1021
|
+
deviceId: udid,
|
|
1022
|
+
appId: bundleId,
|
|
1023
|
+
since: launchedAt,
|
|
1024
|
+
appPath,
|
|
1025
|
+
physical
|
|
1026
|
+
}, logsDir);
|
|
1027
|
+
const deviceProcess = () => {
|
|
1028
|
+
const pid = d.iosDeviceProcess({
|
|
1029
|
+
udid,
|
|
1030
|
+
appName: appName ?? bundleId
|
|
1031
|
+
});
|
|
1032
|
+
return pid === void 0 ? null : pid !== null;
|
|
1033
|
+
};
|
|
1034
|
+
if (release) {
|
|
1035
|
+
const processCheck = physical ? await d.verifyIosDeviceReleaseLaunch({
|
|
1036
|
+
udid,
|
|
1037
|
+
appName: appName ?? bundleId
|
|
1038
|
+
}) : await d.verifyReleaseLaunch({ pid: launched?.pid ?? null });
|
|
1039
|
+
const crashes = readNativeCrashes();
|
|
1040
|
+
if (processCheck?.verified && !crashes.length) {
|
|
1041
|
+
phase("verify", `process alive ${formatDuration(processCheck.waitedMs ?? 0)} after launch (${configuration}: no bundle fetch to observe)`);
|
|
1042
|
+
return { state: true };
|
|
1043
|
+
}
|
|
1044
|
+
for (const line of launchErrorPreview(crashes, root)) note(chalk.red(phaseLine("launch", line)));
|
|
1045
|
+
if (!crashes.length) note(phaseLine("logs", missingCrashReportHint({
|
|
1046
|
+
physical,
|
|
1047
|
+
remote: Boolean(remoteDevice),
|
|
1048
|
+
crashed: processCheck?.reason === "exited"
|
|
1049
|
+
})));
|
|
1050
|
+
phase("verify", chalk.yellow(crashes.length ? "FATAL: the app reported a native crash" : processCheck?.reason === "exited" ? `FATAL: the app process exited within ${formatDuration(processCheck.waitedMs ?? 0)} of launch` : physical ? `UNVERIFIED: devicectl could not read ${udid}'s process list` : "UNVERIFIED: simctl launch reported no process id to check"));
|
|
1051
|
+
note(chalk.yellow(phaseLine("", "Release readiness was not established. Run `stim logs --errors` for captured crash reports, or `stim logs --source device` for the full device output.")));
|
|
1052
|
+
return { state: crashes.length || processCheck?.reason === "exited" ? LAUNCH_FATAL : LAUNCH_UNVERIFIED };
|
|
1053
|
+
}
|
|
1054
|
+
const verification = metroCheck ? await d.verifyLaunch({
|
|
1055
|
+
onReadinessPending: () => phase("readiness", "waiting for app readiness (up to 30s after bundle load)"),
|
|
1056
|
+
logsDir,
|
|
1057
|
+
since: launchedAt,
|
|
1058
|
+
metroPort,
|
|
1059
|
+
platform: "ios",
|
|
1060
|
+
mode: isExpo ? MODE_EXPO : MODE_BARE,
|
|
1061
|
+
readNativeCrashes,
|
|
1062
|
+
processAlive: remoteDevice ? null : physical ? deviceProcess : () => {
|
|
1063
|
+
if (launched?.pid) return d.pidExists(launched.pid);
|
|
1064
|
+
const pid = iosAppProcess(udid, bundleId);
|
|
1065
|
+
return pid === void 0 ? null : pid !== null;
|
|
1066
|
+
}
|
|
1067
|
+
}) : {
|
|
1068
|
+
verified: false,
|
|
1069
|
+
skipped: true
|
|
1070
|
+
};
|
|
1071
|
+
const nativeCrashes = verification.errors?.some((record) => record.event === "native_crash") ? [] : readNativeCrashes();
|
|
1072
|
+
if (nativeCrashes.length) verification.fatal = true;
|
|
1073
|
+
verification.errors = await errorDiagnostics([...verification.errors ?? [], ...nativeCrashes], {
|
|
1074
|
+
root,
|
|
1075
|
+
logsDir,
|
|
1076
|
+
port: metroPort,
|
|
1077
|
+
allowRequest: true
|
|
1078
|
+
});
|
|
1079
|
+
if (verification.readiness) phase("readiness", appReadinessMessage(verification.readiness, verification.waitedMs ?? 0));
|
|
1080
|
+
if (verification?.fatal) {
|
|
1081
|
+
const nativeFatal = verification.errors?.some((record) => record.event === "native_crash");
|
|
1082
|
+
const deliveryFailed = verification.record?.event === "bundle_response_failed";
|
|
1083
|
+
const reason = nativeFatal ? "the app reported a native crash" : verification.processAlive === false ? "the app process exited" : deliveryFailed ? "Metro bundle delivery failed" : "Metro could not build the bundle";
|
|
1084
|
+
phase("verify", chalk.red(`FATAL after ${formatDuration(verification.waitedMs ?? 0)}: ${reason}`));
|
|
1085
|
+
for (const line of launchErrorPreview(verification.errors ?? [], root)) note(chalk.red(phaseLine("", line)));
|
|
1086
|
+
if (verification.processAlive === false && !verification.errors?.some((record) => record.event === "native_crash")) note(phaseLine("logs", missingCrashReportHint({
|
|
1087
|
+
physical,
|
|
1088
|
+
remote: Boolean(remoteDevice),
|
|
1089
|
+
crashed: true
|
|
1090
|
+
})));
|
|
1091
|
+
if (nativeFatal || verification.processAlive === false) note(chalk.yellow(phaseLine("remedy", "Fix the crash, then run `stim ios` again. A Metro reload cannot restart an exited app.")));
|
|
1092
|
+
else if (verification.processAlive === true && metroPort !== null) {
|
|
1093
|
+
const reloadRemedy = `press Reload on the app's own error screen -- run \`agent-device snapshot -i --platform ios --udid ${udid}\` in your existing automation session to reach it. Neither \`stim reload ios\` nor \`agent-device metro reload\` can: this app never connected to Metro.`;
|
|
1094
|
+
note(chalk.yellow(phaseLine("remedy", `The native app is still running. ${deliveryFailed ? "Check the Metro logs and device connection, then" : "Fix the JavaScript or TypeScript error, then"} ${reloadRemedy} Do not run \`stim ios\` unless native inputs changed or the app process exits.`)));
|
|
1095
|
+
}
|
|
1096
|
+
return { state: LAUNCH_FATAL };
|
|
1097
|
+
}
|
|
1098
|
+
if (verification?.verified) {
|
|
1099
|
+
phase("verify", `bundle loaded` + (verification.processAlive === true ? ", process alive" : "") + (verification.readiness ? "" : ", stable for 3s -- the first screen may still be rendering") + ` (${formatDuration(verification.waitedMs ?? 0)} total)`);
|
|
1100
|
+
const hasAppErrors = reportLaunchErrors(verification.errors ?? [], note, root);
|
|
1101
|
+
if (hasAppErrors && verification.processAlive === true && metroPort !== null) {
|
|
1102
|
+
const reloadRemedy = physical || remoteDevice ? `run \`agent-device metro reload --metro-port ${metroPort}\`.` : "run `stim reload ios`.";
|
|
1103
|
+
note(chalk.yellow(phaseLine("remedy", `The native app is still running. Fix the JavaScript or TypeScript error; Fast Refresh should apply the edit. If the error screen remains, ${reloadRemedy} Do not run \`stim ios\` unless native inputs changed or the app process exits.`)));
|
|
1104
|
+
}
|
|
1105
|
+
return {
|
|
1106
|
+
state: true,
|
|
1107
|
+
warning: hasAppErrors ? "app errors detected; inspect the error above" : verification.readiness === "timed-out" || verification.readiness === "error" ? "app readiness not confirmed; inspect the UI and logs" : void 0
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
if (verification?.skipped) {
|
|
1111
|
+
phase("verify", "skipped (--no-metro-check): the launch is reported as unverified");
|
|
1112
|
+
return { state: LAUNCH_UNVERIFIED };
|
|
1113
|
+
}
|
|
1114
|
+
if (verification?.requested) {
|
|
1115
|
+
phase("verify", `BUNDLING: the app asked port ${metroPort} for its bundle; build or delivery was still pending after ${formatDuration(verification.waitedMs ?? 0)} (a cold bundle on a large graph outlasts this window)`);
|
|
1116
|
+
note(chalk.dim(phaseLine("", "Nothing to do: `stim logs --source metro` shows the build finishing, usually within a minute.")));
|
|
1117
|
+
return { state: LAUNCH_BUNDLING };
|
|
1118
|
+
}
|
|
1119
|
+
phase("verify", chalk.yellow("UNVERIFIED: no bundle request reached this workspace's Metro"));
|
|
1120
|
+
for (const line of unverifiedLaunchLines({
|
|
1121
|
+
platform: "ios",
|
|
1122
|
+
metroPort: metroPort ?? 8081,
|
|
1123
|
+
waitedMs: verification?.waitedMs,
|
|
1124
|
+
bundleId,
|
|
1125
|
+
udid,
|
|
1126
|
+
devClientUrl: scheme ? devClientUrl(scheme, metroPort ?? 8081, lanAddress ?? void 0) : null,
|
|
1127
|
+
mode: isExpo ? MODE_EXPO : MODE_BARE,
|
|
1128
|
+
remote: remoteDevice,
|
|
1129
|
+
physical,
|
|
1130
|
+
devClient: Boolean(scheme),
|
|
1131
|
+
lanOrigin,
|
|
1132
|
+
metroOrigin,
|
|
1133
|
+
localNetworkPending: physical && localNetworkPending(readCollectorRecords(logsDir), {
|
|
1134
|
+
since: launchedAt,
|
|
1135
|
+
pid: launched?.pid ?? null,
|
|
1136
|
+
lanOrigin
|
|
1137
|
+
})
|
|
1138
|
+
})) note(chalk.yellow(phaseLine("", line)));
|
|
1139
|
+
return { state: LAUNCH_UNVERIFIED };
|
|
1140
|
+
}
|
|
1141
|
+
function reportLaunchErrors(errors, note, root) {
|
|
1142
|
+
const report = launchErrorReport(errors, root);
|
|
1143
|
+
if (report.summary) note(chalk.dim(phaseLine("launch", report.summary)));
|
|
1144
|
+
for (const line of report.lines) note(chalk.yellow(phaseLine("launch", line)));
|
|
1145
|
+
return report.lines.length > 0;
|
|
1146
|
+
}
|
|
1147
|
+
function cleanAdoptedIosApps({ d, root, udid, bundleId, phase, note }) {
|
|
1148
|
+
const swept = d.clearOtherUserApps({
|
|
1149
|
+
udid,
|
|
1150
|
+
keep: bundleId
|
|
1151
|
+
});
|
|
1152
|
+
if (swept.removed.length) phase("install", `removed ${swept.removed.join(", ")}, left by the previous workspace`);
|
|
1153
|
+
if (swept.listed && swept.failed.length === 0) {
|
|
1154
|
+
d.clearIosAdoptionPending(root);
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
if (!swept.listed) return "Could not list apps left by the previous workspace.";
|
|
1158
|
+
for (const failure of swept.failed) note(chalk.yellow(phaseLine("install", `could not remove ${failure}, left by the previous workspace`)));
|
|
1159
|
+
return `Could not remove ${swept.failed.join(", ")}, left by the previous workspace.`;
|
|
1160
|
+
}
|
|
1161
|
+
function resolveRunBundleId(d, root, appPath, bundleId) {
|
|
1162
|
+
if (!appPath || bundleId) return bundleId;
|
|
1163
|
+
return d.readBundleId(appPath) || d.detectBundleId(root);
|
|
1164
|
+
}
|
|
1165
|
+
function removeSwapDirectory(swapDir) {
|
|
1166
|
+
if (!swapDir) return;
|
|
1167
|
+
try {
|
|
1168
|
+
rmSync(swapDir, {
|
|
1169
|
+
recursive: true,
|
|
1170
|
+
force: true
|
|
1171
|
+
});
|
|
1172
|
+
} catch {}
|
|
1173
|
+
}
|
|
1174
|
+
function readRunExecutable(d, appPath, note) {
|
|
1175
|
+
const executable = appPath ? d.readBundleExecutable(appPath) : null;
|
|
1176
|
+
if (appPath && !executable) note(chalk.dim(`Could not read CFBundleExecutable from ${appPath}; the device log predicate falls back to the .app basename.`));
|
|
1177
|
+
return executable;
|
|
1178
|
+
}
|
|
1179
|
+
function recordIosReloadTarget({ d, root, physical, remoteDevice, bundleId, udid, metroPort, release, launchedAt, note }) {
|
|
1180
|
+
if (physical || remoteDevice) return;
|
|
1181
|
+
try {
|
|
1182
|
+
d.writeWorkspaceLaunch(root, "ios", {
|
|
1183
|
+
appId: bundleId,
|
|
1184
|
+
deviceId: udid,
|
|
1185
|
+
metroPort,
|
|
1186
|
+
release,
|
|
1187
|
+
launchedAt: new Date(launchedAt).toISOString()
|
|
1188
|
+
});
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
note(chalk.yellow(phaseLine("state", `could not record iOS launch: ${error?.message || error}`)));
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
async function finishIosRun({ d, root, json, release, configuration, buildScheme, isExpo, metroCheck, metroPort, logsDir, logFile, device, udid, physical, lanAddress, lanOriginUrl, remoteDevice, bootPromise, bootDuration, appPath, bundleId: initialBundleId, swapDir, buildFailure, fail, phase, note, logWriter, uploadPending, providerUpload, providerName, remote, abandonedRemote: remoteWasAbandoned, elapsed, startedAt, storeHash, storeKey, cacheHit, compilationCache, useBuildCache, waitedForBuild, closeWriter, lease, releaseLease, recordRun }) {
|
|
1194
|
+
let bundleId = initialBundleId;
|
|
1195
|
+
let leaseWarned = false;
|
|
1196
|
+
const raiseLeaseFor = (boundMs, beforeInstall) => {
|
|
1197
|
+
const step = lease?.raise(boundMs);
|
|
1198
|
+
if (!step || step.ok) return null;
|
|
1199
|
+
if (beforeInstall) {
|
|
1200
|
+
const refusal = lostRefusal(step.holder, step.expiresAt, d.now());
|
|
1201
|
+
return {
|
|
1202
|
+
code: refusal.code,
|
|
1203
|
+
message: refusal.message,
|
|
1204
|
+
remedy: refusal.remedy,
|
|
1205
|
+
lease: refusal.lease
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
if (!leaseWarned) {
|
|
1209
|
+
leaseWarned = true;
|
|
1210
|
+
note(chalk.yellow(phaseLine("lease", lostLine(step.holder, step.expiresAt, d.now()))));
|
|
1211
|
+
}
|
|
1212
|
+
return null;
|
|
1213
|
+
};
|
|
1214
|
+
bundleId = resolveRunBundleId(d, root, appPath, bundleId);
|
|
1215
|
+
if (appPath && !bundleId) return fail({
|
|
1216
|
+
code: "STIM_INSTALL_FAILED",
|
|
1217
|
+
message: `Could not read a bundle identifier from the cached app at ${appPath}.`,
|
|
1218
|
+
remedy: "Remove the cache entry (`stim gc`) and run again to rebuild it.",
|
|
1219
|
+
build: {
|
|
1220
|
+
...buildFailure,
|
|
1221
|
+
appPath
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
if (bundleId) d.upsertProject(root, { bundleId });
|
|
1225
|
+
const booted = await bootPromise;
|
|
1226
|
+
if (!booted?.ok) return fail({
|
|
1227
|
+
code: booted?.code || "STIM_NO_DEVICE",
|
|
1228
|
+
message: booted?.reason || "The owned simulator could not be booted.",
|
|
1229
|
+
remedy: booted?.remedy || "Run `stim ios` again to re-establish an owned simulator for this workspace."
|
|
1230
|
+
});
|
|
1231
|
+
const deviceOutcome = physical ? "connected" : `${device?.adopted ? "adopted" : "booted"} ${bootDuration()}`;
|
|
1232
|
+
phase("device", `${deviceLabel(device, udid)} ${deviceOutcome}`);
|
|
1233
|
+
const scheme = release ? void 0 : d.devClientScheme(root, appPath);
|
|
1234
|
+
const appName = appNameFromPath(appPath);
|
|
1235
|
+
const appExecutable = readRunExecutable(d, appPath, note);
|
|
1236
|
+
const dropSwapDir = () => removeSwapDirectory(swapDir);
|
|
1237
|
+
let installSkipped = false;
|
|
1238
|
+
let launched = null;
|
|
1239
|
+
let launchedAt = d.now();
|
|
1240
|
+
if (physical) {
|
|
1241
|
+
const lostBeforeInstall = raiseLeaseFor(DEVICECTL_INSTALL_TIMEOUT_MS, true);
|
|
1242
|
+
if (lostBeforeInstall) return fail(lostBeforeInstall);
|
|
1243
|
+
await d.stopPreviousCollector({
|
|
1244
|
+
root,
|
|
1245
|
+
note
|
|
1246
|
+
});
|
|
1247
|
+
const installTimer = stepTimer(d.now);
|
|
1248
|
+
const installed = d.installIosDeviceApp({
|
|
1249
|
+
udid,
|
|
1250
|
+
appPath,
|
|
1251
|
+
bundleId
|
|
1252
|
+
});
|
|
1253
|
+
if (installed?.failed) {
|
|
1254
|
+
dropSwapDir();
|
|
1255
|
+
return fail({
|
|
1256
|
+
code: installed.code || "STIM_INSTALL_FAILED",
|
|
1257
|
+
message: installed.reason ?? `devicectl could not install ${appPath} on ${udid}.`,
|
|
1258
|
+
remedy: installed.remedy ?? null,
|
|
1259
|
+
build: {
|
|
1260
|
+
...buildFailure,
|
|
1261
|
+
appPath,
|
|
1262
|
+
bundleId
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
phase("install", `${basename(appPath)} -> ${deviceLabel(device, udid)} ${installTimer()}`);
|
|
1267
|
+
if (installed?.note) {
|
|
1268
|
+
note(chalk.yellow(phaseLine("install", installed.note)));
|
|
1269
|
+
logWriter().write({
|
|
1270
|
+
src: "build",
|
|
1271
|
+
level: "warn",
|
|
1272
|
+
event: "install_uninstalled_first",
|
|
1273
|
+
msg: installed.note
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
dropSwapDir();
|
|
1277
|
+
raiseLeaseFor(COLLECTOR_EXIT_WAIT_MS + LAUNCH_PROBE_TIMEOUT_MS, false);
|
|
1278
|
+
const payloadUrl = scheme && metroPort !== null && lanAddress ? devClientUrl(scheme, metroPort, lanAddress) : null;
|
|
1279
|
+
const launchTimer = stepTimer(d.now);
|
|
1280
|
+
launchedAt = d.now();
|
|
1281
|
+
logWriter().write({
|
|
1282
|
+
src: "build",
|
|
1283
|
+
level: "info",
|
|
1284
|
+
marker: true,
|
|
1285
|
+
event: "launch_attempt",
|
|
1286
|
+
ts: launchedAt,
|
|
1287
|
+
platform: "ios",
|
|
1288
|
+
appId: bundleId,
|
|
1289
|
+
deviceId: udid,
|
|
1290
|
+
appPath,
|
|
1291
|
+
physical: true,
|
|
1292
|
+
msg: `launching ${bundleId} on ${udid}`
|
|
1293
|
+
});
|
|
1294
|
+
const collector = await d.replaceCollector({
|
|
1295
|
+
root,
|
|
1296
|
+
udid,
|
|
1297
|
+
bundleId,
|
|
1298
|
+
appName,
|
|
1299
|
+
physical: true,
|
|
1300
|
+
payloadUrl,
|
|
1301
|
+
note
|
|
1302
|
+
});
|
|
1303
|
+
if (!collector?.pid) return fail({
|
|
1304
|
+
code: "STIM_LAUNCH_FAILED",
|
|
1305
|
+
message: `The device log collector, which is what launches ${bundleId} on a phone, could not be started.`,
|
|
1306
|
+
remedy: `Check ${logFile} and the workspace collector log, then run the command again.`,
|
|
1307
|
+
build: {
|
|
1308
|
+
...buildFailure,
|
|
1309
|
+
appPath,
|
|
1310
|
+
bundleId
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
const started = await d.awaitIosDeviceLaunch({
|
|
1314
|
+
udid,
|
|
1315
|
+
bundleId,
|
|
1316
|
+
appName: appName ?? bundleId,
|
|
1317
|
+
collectorPid: collector.pid,
|
|
1318
|
+
readRecords: () => readCollectorRecords(logsDir).filter((entry) => Number(entry.ts) >= launchedAt)
|
|
1319
|
+
});
|
|
1320
|
+
if (started.failed || !started.pid) return fail({
|
|
1321
|
+
code: "STIM_LAUNCH_FAILED",
|
|
1322
|
+
message: started.reason ?? `${bundleId} did not start on ${udid}.`,
|
|
1323
|
+
remedy: started.remedy ?? null,
|
|
1324
|
+
lines: started.lines ?? [],
|
|
1325
|
+
logPath: logsDir,
|
|
1326
|
+
build: {
|
|
1327
|
+
...buildFailure,
|
|
1328
|
+
appPath,
|
|
1329
|
+
bundleId
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
launched = {
|
|
1333
|
+
ok: true,
|
|
1334
|
+
mode: payloadUrl ? "payload-url" : "launch",
|
|
1335
|
+
pid: started.pid,
|
|
1336
|
+
...payloadUrl ? { url: payloadUrl } : {},
|
|
1337
|
+
...lanOriginUrl ? { jsLocation: lanOriginUrl } : {}
|
|
1338
|
+
};
|
|
1339
|
+
phase("launch", `${bundleId} pid ${started.pid} ${launchTimer()}`);
|
|
1340
|
+
} else {
|
|
1341
|
+
const adopting = Boolean(device?.adoptionPending);
|
|
1342
|
+
if (adopting) {
|
|
1343
|
+
const cleanupFailure = cleanAdoptedIosApps({
|
|
1344
|
+
d,
|
|
1345
|
+
root,
|
|
1346
|
+
udid,
|
|
1347
|
+
bundleId,
|
|
1348
|
+
phase,
|
|
1349
|
+
note
|
|
1350
|
+
});
|
|
1351
|
+
if (cleanupFailure) return fail({
|
|
1352
|
+
code: "STIM_INSTALL_FAILED",
|
|
1353
|
+
message: `${cleanupFailure} Stim kept the adoption cleanup pending and did not install or launch the app.`,
|
|
1354
|
+
remedy: "Run `stim ios` again after simulator tooling is responsive.",
|
|
1355
|
+
build: {
|
|
1356
|
+
...buildFailure,
|
|
1357
|
+
appPath,
|
|
1358
|
+
bundleId
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
const installTimer = stepTimer(d.now);
|
|
1363
|
+
const installed = d.installIosApp({
|
|
1364
|
+
udid,
|
|
1365
|
+
appPath,
|
|
1366
|
+
bundleId,
|
|
1367
|
+
devClientScheme: scheme,
|
|
1368
|
+
proveInstalled: !adopting || device?.parkedCacheKey === storeKey
|
|
1369
|
+
}, { now: d.now });
|
|
1370
|
+
if (installed?.failed) return fail({
|
|
1371
|
+
code: installed.code || "STIM_INSTALL_FAILED",
|
|
1372
|
+
message: installed.reason,
|
|
1373
|
+
remedy: "Check that the simulator is booted and that the app was built for the simulator SDK.",
|
|
1374
|
+
build: {
|
|
1375
|
+
...buildFailure,
|
|
1376
|
+
appPath,
|
|
1377
|
+
bundleId
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
installSkipped = Boolean(installed?.skipped);
|
|
1381
|
+
const artifactDuration = installed?.artifactDurationMs === void 0 ? installTimer() : `(${formatDuration(installed.artifactDurationMs)})`;
|
|
1382
|
+
phase("install", installSkipped ? `unchanged (${deviceShortName(device, udid)} already has this build) ${artifactDuration}` : `${basename(appPath)} -> ${deviceLabel(device, udid)} ${artifactDuration}`);
|
|
1383
|
+
if (!remoteDevice && installed?.devClientPreparationDurationMs !== void 0) phase("install", `dev client prepared (${formatDuration(installed.devClientPreparationDurationMs)})`);
|
|
1384
|
+
dropSwapDir();
|
|
1385
|
+
if (!remoteDevice) await d.replaceCollector({
|
|
1386
|
+
root,
|
|
1387
|
+
udid,
|
|
1388
|
+
bundleId,
|
|
1389
|
+
appName,
|
|
1390
|
+
appExecutable,
|
|
1391
|
+
note
|
|
1392
|
+
});
|
|
1393
|
+
const launchTimer = stepTimer(d.now);
|
|
1394
|
+
launchedAt = d.now();
|
|
1395
|
+
logWriter().write({
|
|
1396
|
+
src: "build",
|
|
1397
|
+
level: "info",
|
|
1398
|
+
marker: true,
|
|
1399
|
+
event: "launch_attempt",
|
|
1400
|
+
ts: launchedAt,
|
|
1401
|
+
platform: "ios",
|
|
1402
|
+
appId: bundleId,
|
|
1403
|
+
deviceId: udid,
|
|
1404
|
+
appPath,
|
|
1405
|
+
remote: Boolean(remoteDevice),
|
|
1406
|
+
msg: `launching ${bundleId} on ${udid}`
|
|
1407
|
+
});
|
|
1408
|
+
launched = d.launchIosApp({
|
|
1409
|
+
udid,
|
|
1410
|
+
bundleId,
|
|
1411
|
+
metroPort,
|
|
1412
|
+
devClientScheme: scheme,
|
|
1413
|
+
consolePaths: simulatorConsolePaths({
|
|
1414
|
+
deviceId: udid,
|
|
1415
|
+
appId: bundleId,
|
|
1416
|
+
since: launchedAt
|
|
1417
|
+
}, true, Boolean(remoteDevice))
|
|
1418
|
+
});
|
|
1419
|
+
if (launched?.failed) {
|
|
1420
|
+
printNativeCrashReport({
|
|
1421
|
+
root,
|
|
1422
|
+
platform: "ios",
|
|
1423
|
+
deviceId: udid,
|
|
1424
|
+
appId: bundleId,
|
|
1425
|
+
since: launchedAt,
|
|
1426
|
+
appPath
|
|
1427
|
+
}, logsDir, (line) => note(chalk.red(phaseLine("launch", line))), Boolean(remoteDevice));
|
|
1428
|
+
return fail({
|
|
1429
|
+
code: launched.code || "STIM_LAUNCH_FAILED",
|
|
1430
|
+
message: launched.reason,
|
|
1431
|
+
remedy: `Run \`xcrun simctl launch --console ${udid} ${bundleId}\` to see what the app reports, and check ${logFile}.`,
|
|
1432
|
+
build: {
|
|
1433
|
+
...buildFailure,
|
|
1434
|
+
appPath,
|
|
1435
|
+
bundleId
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
phase("launch", `${bundleId} ${launchTimer()}`);
|
|
1440
|
+
}
|
|
1441
|
+
recordIosReloadTarget({
|
|
1442
|
+
d,
|
|
1443
|
+
root,
|
|
1444
|
+
physical,
|
|
1445
|
+
remoteDevice: Boolean(remoteDevice),
|
|
1446
|
+
bundleId,
|
|
1447
|
+
udid,
|
|
1448
|
+
metroPort,
|
|
1449
|
+
release,
|
|
1450
|
+
launchedAt,
|
|
1451
|
+
note
|
|
1452
|
+
});
|
|
1453
|
+
logWriter().write({
|
|
1454
|
+
src: "build",
|
|
1455
|
+
level: "info",
|
|
1456
|
+
event: "launch",
|
|
1457
|
+
msg: release ? `launched ${bundleId} on ${udid} (${configuration}, embedded JS bundle, no Metro)` : `launched ${bundleId} on ${udid} against Metro ${lanOriginUrl ?? `port ${metroPort}`}` + (launched?.mode === "openurl" || launched?.mode === "payload-url" ? " (expo-dev-client)" : "")
|
|
1458
|
+
});
|
|
1459
|
+
if (remoteDevice) await d.replaceCollector({
|
|
1460
|
+
root,
|
|
1461
|
+
udid,
|
|
1462
|
+
bundleId,
|
|
1463
|
+
appName,
|
|
1464
|
+
appExecutable,
|
|
1465
|
+
note
|
|
1466
|
+
});
|
|
1467
|
+
if (physical) raiseLeaseFor(release ? RELEASE_VERIFY_WAIT_MS : DEBUG_VERIFY_STEP_MS, false);
|
|
1468
|
+
const { state: launchState, warning: launchWarning } = await verifyIosRun({
|
|
1469
|
+
root,
|
|
1470
|
+
appPath,
|
|
1471
|
+
d,
|
|
1472
|
+
release,
|
|
1473
|
+
launched,
|
|
1474
|
+
configuration,
|
|
1475
|
+
phase,
|
|
1476
|
+
note,
|
|
1477
|
+
metroCheck,
|
|
1478
|
+
logsDir,
|
|
1479
|
+
launchedAt,
|
|
1480
|
+
metroPort,
|
|
1481
|
+
isExpo,
|
|
1482
|
+
bundleId,
|
|
1483
|
+
udid,
|
|
1484
|
+
scheme,
|
|
1485
|
+
physical,
|
|
1486
|
+
appName,
|
|
1487
|
+
lanAddress,
|
|
1488
|
+
lanOrigin: lanOriginUrl,
|
|
1489
|
+
remoteDevice: Boolean(remoteDevice),
|
|
1490
|
+
metroOrigin: typeof launched?.jsLocation === "string" ? launched.jsLocation : null
|
|
1491
|
+
});
|
|
1492
|
+
if (launchState === "fatal") return fail({
|
|
1493
|
+
code: "STIM_LAUNCH_FAILED",
|
|
1494
|
+
message: "The app failed its launch readiness check.",
|
|
1495
|
+
remedy: `Read the launch error above or run \`stim logs --errors\`. The full timeline is in ${logsDir}.`,
|
|
1496
|
+
logPath: logsDir,
|
|
1497
|
+
build: {
|
|
1498
|
+
...buildFailure,
|
|
1499
|
+
appPath,
|
|
1500
|
+
bundleId
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
logWriter().write(launchOutcomeRecord({
|
|
1504
|
+
launchState,
|
|
1505
|
+
release,
|
|
1506
|
+
bundleId,
|
|
1507
|
+
configuration,
|
|
1508
|
+
metroPort
|
|
1509
|
+
}));
|
|
1510
|
+
const leaseFacts = lease?.facts() ?? null;
|
|
1511
|
+
releaseLease();
|
|
1512
|
+
const uploadWasAbandoned = await finishIosUpload(uploadPending, remote, phase, note);
|
|
1513
|
+
const providerOutcome = providerUploadOutcome(providerUpload ? await providerUpload : null, providerName);
|
|
1514
|
+
if (providerOutcome) {
|
|
1515
|
+
if (providerOutcome.warn) note(chalk.yellow(phaseLine("cache", providerOutcome.line)));
|
|
1516
|
+
else phase("cache", providerOutcome.line);
|
|
1517
|
+
}
|
|
1518
|
+
const facts = reportIosResult({
|
|
1519
|
+
d,
|
|
1520
|
+
root,
|
|
1521
|
+
json,
|
|
1522
|
+
release,
|
|
1523
|
+
configuration,
|
|
1524
|
+
buildScheme,
|
|
1525
|
+
metroCheck,
|
|
1526
|
+
metroPort,
|
|
1527
|
+
logsDir,
|
|
1528
|
+
device,
|
|
1529
|
+
udid,
|
|
1530
|
+
appPath,
|
|
1531
|
+
bundleId,
|
|
1532
|
+
installSkipped,
|
|
1533
|
+
elapsed,
|
|
1534
|
+
startedAt,
|
|
1535
|
+
storeHash,
|
|
1536
|
+
storeKey,
|
|
1537
|
+
cacheHit,
|
|
1538
|
+
compilationCache,
|
|
1539
|
+
useBuildCache,
|
|
1540
|
+
waitedForBuild,
|
|
1541
|
+
launchState,
|
|
1542
|
+
launchWarning,
|
|
1543
|
+
remote,
|
|
1544
|
+
providerName,
|
|
1545
|
+
closeWriter,
|
|
1546
|
+
webPreviewUrl: remoteDevice?.webPreviewUrl() ?? null,
|
|
1547
|
+
lease: physical ? leaseFacts : void 0,
|
|
1548
|
+
recordRun
|
|
1549
|
+
});
|
|
1550
|
+
if (remoteWasAbandoned || uploadWasAbandoned) exitAfterFlush(0);
|
|
1551
|
+
return facts;
|
|
1552
|
+
}
|
|
1553
|
+
//#endregion
|
|
1554
|
+
//#region src/commands/ios.ts
|
|
1555
|
+
function writeNote(line) {
|
|
1556
|
+
console.error(line);
|
|
1557
|
+
}
|
|
1558
|
+
function writePhase(name, text) {
|
|
1559
|
+
console.error(phaseLine(name, text));
|
|
1560
|
+
}
|
|
1561
|
+
const GENERIC_SIM_DESTINATION = "generic/platform=iOS Simulator";
|
|
1562
|
+
const IPHONEOS_SDK = "iphoneos";
|
|
1563
|
+
const PROVIDER_SKIPPED_ON_DEVICE = "a device build is local-tier only: its cache key names the iphoneos slice, and a remote or provider entry is keyed for the simulator";
|
|
1564
|
+
function iosCommand(program) {
|
|
1565
|
+
registerIos(program);
|
|
1566
|
+
}
|
|
1567
|
+
function registerIos(program, deps = {}) {
|
|
1568
|
+
program.command("ios").description("Build (or restore from the fingerprint cache), install and launch this workspace's app on its owned simulator, wired to the reserved Metro port. Requires a running dev server (`stim start`).").option("--json", "Emit the facts as a single JSON line on stdout; every other line goes to stderr").option("--scheme <name>", "Shared Xcode app scheme to build; overrides automatic scheme selection, not the app URL scheme").option("--no-metro-check", "Skip the \"is this workspace's dev server running?\" gate and build anyway").option("--no-build-cache", "Build fresh, ignoring cached artifacts (local and the project's build-cache provider); the fresh build still replaces the cache entry").option("--configuration <name>", "Xcode configuration to build (e.g. Release). A non-Debug configuration embeds the JS bundle and skips Metro entirely. Overrides the ios.configuration setting. Default: Debug").option("--device-type <name>", "Simulator model to create this workspace's owned sim as, exactly as `xcrun simctl list devicetypes` names it (e.g. \"iPad Pro 13-inch (M4)\"). Overrides the ios.deviceType setting for this invocation. A model no installed runtime can create refuses with STIM_BAD_ARG and prints the models they do offer.").option("--runtime <version>", "Simulator runtime to create this workspace's owned sim on, as a version (\"18.5\") or a runtime's full name (\"iOS 18.5\"); nothing else matches. Overrides the ios.runtime setting for this invocation. An unknown version refuses with STIM_BAD_ARG and prints the installed runtimes.").option("--device [udid]", "Build the iphoneos slice for a connected iPhone, install it, and launch it, instead of using this workspace's owned simulator. With no UDID, the first connected device this workspace can lease is used. In Debug the app is wired to this workspace's Metro over the LAN. Stim never creates, boots, or deletes a physical device.").option("--remote <backend>", "Install and launch on a remote device with proxy or EAS. The build still happens here.", (value) => {
|
|
1569
|
+
if (REMOTE_DEVICE_BACKENDS.includes(value)) return value;
|
|
1570
|
+
throw new InvalidArgumentError(`expected one of: ${REMOTE_DEVICE_BACKENDS.join(", ")}`);
|
|
1571
|
+
}).option("--wait <seconds>", "How long to wait for another workspace to release the phone it leases, before refusing with STIM_DEVICE_BUSY (default 60, 0 refuses at once). Only with --device.").option("--no-wait", "Install on a phone another workspace leases instead of waiting: this run takes no lease and, when both workspaces build the same app id, the install terminates the holder's running app. Only with --device.").action(async (opts) => {
|
|
1572
|
+
await runIos({
|
|
1573
|
+
...opts,
|
|
1574
|
+
waitConflict: waitFlagConflict(process.argv)
|
|
1575
|
+
}, deps);
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
function explicitSchemeRefusal(root, scheme, isExpo, d) {
|
|
1579
|
+
if (scheme === void 0) return null;
|
|
1580
|
+
if (!scheme.trim()) return {
|
|
1581
|
+
code: "STIM_BAD_ARG",
|
|
1582
|
+
message: "--scheme must name a non-empty shared Xcode app scheme.",
|
|
1583
|
+
remedy: "Pass the exact scheme name shown by xcodebuild -list."
|
|
1584
|
+
};
|
|
1585
|
+
if (d.needsPrebuild(root, "ios", isExpo)) return null;
|
|
1586
|
+
const project = d.discoverXcodeProject(root);
|
|
1587
|
+
if (project.error) return project.error;
|
|
1588
|
+
return d.resolveScheme(project, { scheme }).error ?? null;
|
|
1589
|
+
}
|
|
1590
|
+
async function runIos(opts = {}, overrides = {}) {
|
|
1591
|
+
let d = {
|
|
1592
|
+
...DEFAULT_DEPS,
|
|
1593
|
+
...overrides
|
|
1594
|
+
};
|
|
1595
|
+
const json = Boolean(opts.json);
|
|
1596
|
+
const metroCheck = opts.metroCheck !== false;
|
|
1597
|
+
let useBuildCache = opts.buildCache !== false;
|
|
1598
|
+
const phase = writePhase;
|
|
1599
|
+
const note = writeNote;
|
|
1600
|
+
const started = d.now();
|
|
1601
|
+
const startedAt = new Date(started).toISOString();
|
|
1602
|
+
const elapsed = () => d.now() - started;
|
|
1603
|
+
const foundRoot = d.findProjectRoot(process.cwd());
|
|
1604
|
+
if (!foundRoot) {
|
|
1605
|
+
note(chalk.red("Not in a React Native project (no package.json found)."));
|
|
1606
|
+
process.exit(1);
|
|
1607
|
+
return null;
|
|
1608
|
+
}
|
|
1609
|
+
const root = foundRoot;
|
|
1610
|
+
const projectProblem = appProjectProblem(root);
|
|
1611
|
+
if (projectProblem) {
|
|
1612
|
+
const { message, remedy } = projectProblem;
|
|
1613
|
+
note(chalk.red(phaseLine("error", message)));
|
|
1614
|
+
note(chalk.dim(phaseLine("remedy", remedy)));
|
|
1615
|
+
note(chalk.red(phaseLine("failed", "STIM_NO_PROJECT")));
|
|
1616
|
+
if (json) console.log(JSON.stringify({
|
|
1617
|
+
code: "STIM_NO_PROJECT",
|
|
1618
|
+
message,
|
|
1619
|
+
remedy
|
|
1620
|
+
}));
|
|
1621
|
+
process.exit(1);
|
|
1622
|
+
return null;
|
|
1623
|
+
}
|
|
1624
|
+
try {
|
|
1625
|
+
await d.ensureWorkspaceStorage(root, { note });
|
|
1626
|
+
} catch (error) {
|
|
1627
|
+
const code = error?.code || "STIM_WORKSPACE_STATE";
|
|
1628
|
+
const message = `Could not prepare this workspace's Stim state: ${error?.message || error}`;
|
|
1629
|
+
note(chalk.red(`${code}: ${message}`));
|
|
1630
|
+
note(chalk.dim("Check that STIM_HOME is writable and has free space. An EPERM on a directory you can write is a sandbox: allow writes to STIM_HOME, or run Stim with the sandbox disabled (`stim guide errors sandbox`)."));
|
|
1631
|
+
if (json) console.log(JSON.stringify({
|
|
1632
|
+
code,
|
|
1633
|
+
message,
|
|
1634
|
+
remedy: "Check that STIM_HOME is writable and has free space."
|
|
1635
|
+
}));
|
|
1636
|
+
process.exitCode = 1;
|
|
1637
|
+
return null;
|
|
1638
|
+
}
|
|
1639
|
+
const logsDir = workspaceLogsDir(root);
|
|
1640
|
+
const logFile = buildLogFile(root);
|
|
1641
|
+
let writer = null;
|
|
1642
|
+
const logWriter = () => writer ||= d.createWriter(logFile, { truncate: true });
|
|
1643
|
+
let buildLock = null;
|
|
1644
|
+
const releaseLock = () => {
|
|
1645
|
+
if (!buildLock) return;
|
|
1646
|
+
const held = buildLock;
|
|
1647
|
+
buildLock = null;
|
|
1648
|
+
try {
|
|
1649
|
+
d.releaseBuildLock(held);
|
|
1650
|
+
} catch (e) {
|
|
1651
|
+
note(chalk.dim(`Could not release the build lock at ${held.path}: ${e?.message || e}`));
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
let leaseHandle = null;
|
|
1655
|
+
let stopLeaseSignals = null;
|
|
1656
|
+
const releaseLease = () => {
|
|
1657
|
+
const held = leaseHandle;
|
|
1658
|
+
const stopSignals = stopLeaseSignals;
|
|
1659
|
+
leaseHandle = null;
|
|
1660
|
+
stopLeaseSignals = null;
|
|
1661
|
+
stopSignals?.();
|
|
1662
|
+
try {
|
|
1663
|
+
held?.release();
|
|
1664
|
+
} catch (e) {
|
|
1665
|
+
note(chalk.dim(`Could not release this run's device lease: ${e?.message || e}`));
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
let buildSlot = null;
|
|
1669
|
+
const releaseSlot = () => {
|
|
1670
|
+
if (!buildSlot) return;
|
|
1671
|
+
const held = buildSlot;
|
|
1672
|
+
buildSlot = null;
|
|
1673
|
+
try {
|
|
1674
|
+
d.releaseBuildSlot(held);
|
|
1675
|
+
} catch (e) {
|
|
1676
|
+
note(chalk.dim(`Could not release the build slot: ${e?.message || e}`));
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
const stats = createRunRecorder({
|
|
1680
|
+
platform: "ios",
|
|
1681
|
+
write: (statsRun, at) => d.recordStats(statsRun, at),
|
|
1682
|
+
now: () => d.now(),
|
|
1683
|
+
note: (line) => note(chalk.dim(line))
|
|
1684
|
+
});
|
|
1685
|
+
const recordRun = stats.record;
|
|
1686
|
+
let compilationCache = COMPILATION_CACHE_NOT_RUN;
|
|
1687
|
+
const fail = ({ code, message, remedy = null, lines = [], logPath = null, build = null, lease }) => {
|
|
1688
|
+
releaseLock();
|
|
1689
|
+
releaseSlot();
|
|
1690
|
+
releaseLease();
|
|
1691
|
+
if (message) note(chalk.red(phaseLine("error", message)));
|
|
1692
|
+
for (const line of lines) note(chalk.dim(phaseLine("", line)));
|
|
1693
|
+
if (remedy) note(chalk.dim(phaseLine("remedy", remedy)));
|
|
1694
|
+
if (logPath) note(chalk.dim(phaseLine("log", logPath)));
|
|
1695
|
+
if (build) writeLastBuild(root, lastBuildRecord({
|
|
1696
|
+
...build,
|
|
1697
|
+
startedAt,
|
|
1698
|
+
status: "failed",
|
|
1699
|
+
errorCode: code,
|
|
1700
|
+
durationMs: elapsed()
|
|
1701
|
+
}), { write: d.writeWorkspaceState });
|
|
1702
|
+
note(chalk.red(phaseLine("failed", code)));
|
|
1703
|
+
recordRun({
|
|
1704
|
+
failed: true,
|
|
1705
|
+
durationMs: elapsed()
|
|
1706
|
+
});
|
|
1707
|
+
if (json) console.log(JSON.stringify({
|
|
1708
|
+
code,
|
|
1709
|
+
message: message ?? null,
|
|
1710
|
+
remedy: remedy ?? null,
|
|
1711
|
+
...compilationCache.status === "not-run" ? {} : { compilationCache },
|
|
1712
|
+
...lease === void 0 ? {} : { lease }
|
|
1713
|
+
}));
|
|
1714
|
+
writer?.close?.();
|
|
1715
|
+
process.exit(1);
|
|
1716
|
+
return null;
|
|
1717
|
+
};
|
|
1718
|
+
const settingsRepoRoot = d.repoRoot(root);
|
|
1719
|
+
const settingsContext = {
|
|
1720
|
+
projectPath: root,
|
|
1721
|
+
gitCommonDir: d.gitCommonDir(root),
|
|
1722
|
+
repoRoot: settingsRepoRoot
|
|
1723
|
+
};
|
|
1724
|
+
const projectKey = statsProjectKey({
|
|
1725
|
+
root,
|
|
1726
|
+
commonDir: settingsContext.gitCommonDir,
|
|
1727
|
+
repoRoot: settingsRepoRoot
|
|
1728
|
+
});
|
|
1729
|
+
stats.setProject(projectKey);
|
|
1730
|
+
let estimatesRead = null;
|
|
1731
|
+
const estimates = () => estimatesRead ??= d.readEstimates({
|
|
1732
|
+
projectKey,
|
|
1733
|
+
platform: "ios"
|
|
1734
|
+
});
|
|
1735
|
+
const settings = d.resolveSettings(settingsContext);
|
|
1736
|
+
const [shapeError, ...moreShapeErrors] = settingShapeErrors(settings);
|
|
1737
|
+
if (shapeError) return fail({
|
|
1738
|
+
code: "STIM_BAD_ARG",
|
|
1739
|
+
message: shapeError,
|
|
1740
|
+
lines: moreShapeErrors,
|
|
1741
|
+
remedy: SETTING_SHAPE_REMEDY
|
|
1742
|
+
});
|
|
1743
|
+
let optimizations;
|
|
1744
|
+
try {
|
|
1745
|
+
optimizations = resolveOptimizations(settings);
|
|
1746
|
+
} catch (error) {
|
|
1747
|
+
return fail({
|
|
1748
|
+
code: "STIM_BAD_ARG",
|
|
1749
|
+
message: error.message,
|
|
1750
|
+
remedy: SETTING_SHAPE_REMEDY
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
const buildProfile = optimizationBuildProfile("ios", optimizations);
|
|
1754
|
+
const cacheProviderConfig = d.resolveCacheProviderConfig(settingsContext);
|
|
1755
|
+
for (const key of unknownSettingKeys(settings)) note(phaseLine("setting", chalk.yellow(`Warning: setting "${key}" is not read by Stim and will be ignored.`)));
|
|
1756
|
+
const cacheProviderError = cacheProviderSettingError(settings);
|
|
1757
|
+
if (cacheProviderError) note(chalk.yellow(phaseLine("cache", `${cacheProviderError} Using the local cache.`)));
|
|
1758
|
+
const remoteSettingError = remoteDeviceSettingError(settings);
|
|
1759
|
+
if (remoteSettingError) return fail({
|
|
1760
|
+
code: "STIM_BAD_ARG",
|
|
1761
|
+
message: remoteSettingError,
|
|
1762
|
+
remedy: `Set ios.remote and android.remote to one of: ${REMOTE_DEVICE_BACKENDS.join(", ")}.`
|
|
1763
|
+
});
|
|
1764
|
+
const poolError = parkedMaxSetting("ios").error;
|
|
1765
|
+
if (poolError) return fail({
|
|
1766
|
+
code: "STIM_BAD_ARG",
|
|
1767
|
+
message: poolError,
|
|
1768
|
+
remedy: POOL_SETTING_REMEDY
|
|
1769
|
+
});
|
|
1770
|
+
for (const settingError of [
|
|
1771
|
+
iosSigningIdentitySettingError(settings),
|
|
1772
|
+
iosSigningIdentitySha1SettingError(settings),
|
|
1773
|
+
iosLanHostSettingError(settings)
|
|
1774
|
+
]) if (settingError) return fail({
|
|
1775
|
+
code: "STIM_BAD_ARG",
|
|
1776
|
+
message: settingError,
|
|
1777
|
+
remedy: SETTING_SHAPE_REMEDY
|
|
1778
|
+
});
|
|
1779
|
+
const configuration = resolveConfiguration(opts.configuration, settings);
|
|
1780
|
+
const buildScheme = opts.scheme;
|
|
1781
|
+
const release = isReleaseConfiguration(configuration);
|
|
1782
|
+
const cachePolicy = artifactCachePolicy(optimizations, useBuildCache, release);
|
|
1783
|
+
useBuildCache = cachePolicy.read;
|
|
1784
|
+
const deviceType = resolveDeviceType(opts.deviceType, settings);
|
|
1785
|
+
const runtime = resolveRuntime(opts.runtime, settings);
|
|
1786
|
+
const deviceFlag = opts.device;
|
|
1787
|
+
const physical = deviceFlag !== null && deviceFlag !== void 0 && deviceFlag !== false;
|
|
1788
|
+
if (physical && deviceFlag === "") return fail({
|
|
1789
|
+
code: "STIM_BAD_ARG",
|
|
1790
|
+
message: "--device was given an empty UDID.",
|
|
1791
|
+
remedy: "Pass `--device` on its own to take the first connected device this workspace can lease, or `--device <udid>` to name one."
|
|
1792
|
+
});
|
|
1793
|
+
if (physical && opts.remote) return fail({
|
|
1794
|
+
code: "STIM_BAD_ARG",
|
|
1795
|
+
message: "--device builds for a phone cabled to this machine, and --remote installs on a remote one.",
|
|
1796
|
+
remedy: "Pass only one of --device and --remote."
|
|
1797
|
+
});
|
|
1798
|
+
const noWait = opts.wait === false;
|
|
1799
|
+
const waitFlagged = opts.wait !== void 0;
|
|
1800
|
+
if (opts.waitConflict) return fail({
|
|
1801
|
+
code: "STIM_BAD_ARG",
|
|
1802
|
+
message: "--wait and --no-wait ask for opposite things.",
|
|
1803
|
+
remedy: "Pass `--wait <seconds>` to wait for the lease, or `--no-wait` to install without one."
|
|
1804
|
+
});
|
|
1805
|
+
if (waitFlagged && !physical) return fail({
|
|
1806
|
+
code: "STIM_BAD_ARG",
|
|
1807
|
+
message: "--wait and --no-wait only apply to a `--device` run.",
|
|
1808
|
+
remedy: "This workspace owns its simulator, so nothing contends for it. Drop the flag, or pass `--device`."
|
|
1809
|
+
});
|
|
1810
|
+
const waitParsed = parseDeviceWait(noWait ? void 0 : opts.wait);
|
|
1811
|
+
if ("error" in waitParsed) return fail({
|
|
1812
|
+
code: "STIM_BAD_ARG",
|
|
1813
|
+
message: waitParsed.error,
|
|
1814
|
+
remedy: "Pass a whole number of seconds, e.g. --wait 90. `--wait 0` refuses a leased device at once."
|
|
1815
|
+
});
|
|
1816
|
+
const waitSeconds = waitParsed.seconds;
|
|
1817
|
+
const isExpo = d.detectIsExpo(root);
|
|
1818
|
+
const schemeRefusal = explicitSchemeRefusal(root, buildScheme, isExpo, d);
|
|
1819
|
+
if (schemeRefusal) return fail(schemeRefusal);
|
|
1820
|
+
const remoteBackend = physical ? null : opts.remote ?? remoteIosSetting(settings);
|
|
1821
|
+
const modelRefusal = deviceModelRefusal({
|
|
1822
|
+
deviceTypeFlag: opts.deviceType,
|
|
1823
|
+
runtimeFlag: opts.runtime,
|
|
1824
|
+
deviceType,
|
|
1825
|
+
runtime,
|
|
1826
|
+
physical,
|
|
1827
|
+
remoteBackend,
|
|
1828
|
+
listRuntimes: d.listIosRuntimes
|
|
1829
|
+
});
|
|
1830
|
+
if (modelRefusal) return fail(modelRefusal);
|
|
1831
|
+
const registerProject = () => d.upsertProject(root, {
|
|
1832
|
+
bundleId: d.detectBundleId(root) ?? void 0,
|
|
1833
|
+
isExpo
|
|
1834
|
+
});
|
|
1835
|
+
if (remoteBackend !== "eas") registerProject();
|
|
1836
|
+
const proj = d.getProject(root);
|
|
1837
|
+
const label = d.projectShortcut(root, proj);
|
|
1838
|
+
let remoteDevice = null;
|
|
1839
|
+
if (remoteBackend) {
|
|
1840
|
+
const resolved = await d.resolveRemoteContext({
|
|
1841
|
+
root,
|
|
1842
|
+
label,
|
|
1843
|
+
backend: remoteBackend,
|
|
1844
|
+
easBin: d.resolveEasCliBin(root)?.file ?? null
|
|
1845
|
+
});
|
|
1846
|
+
if ("failed" in resolved) return fail({
|
|
1847
|
+
code: resolved.code ?? "STIM_NO_REMOTE_SESSION",
|
|
1848
|
+
message: resolved.failed,
|
|
1849
|
+
remedy: resolved.remedy
|
|
1850
|
+
});
|
|
1851
|
+
remoteDevice = d.remoteIosDeps(resolved.ctx);
|
|
1852
|
+
d = {
|
|
1853
|
+
...d,
|
|
1854
|
+
checkDeviceCapacity: remoteDevice.checkDeviceCapacity,
|
|
1855
|
+
ensureOwnedDevice: remoteDevice.ensureOwnedDevice,
|
|
1856
|
+
ensureBooted: remoteDevice.ensureBooted,
|
|
1857
|
+
installIosApp: remoteDevice.installIosApp,
|
|
1858
|
+
launchIosApp: remoteDevice.launchIosApp
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
const limits = d.getConcurrencyLimits();
|
|
1862
|
+
let physicalDevice = null;
|
|
1863
|
+
if (physical && typeof deviceFlag !== "string") {
|
|
1864
|
+
const pooled = await d.selectFromPool({
|
|
1865
|
+
root,
|
|
1866
|
+
platform: "ios",
|
|
1867
|
+
idLabel: "udid",
|
|
1868
|
+
list: () => iosPoolCandidates(d.listIosDevices()).map((entry) => ({
|
|
1869
|
+
id: entry.udid,
|
|
1870
|
+
name: entry.name
|
|
1871
|
+
})),
|
|
1872
|
+
noCandidates: () => {
|
|
1873
|
+
const resolved = iosPoolNoCandidatesRefusal(d.listIosDevices());
|
|
1874
|
+
return {
|
|
1875
|
+
message: resolved.error,
|
|
1876
|
+
remedy: resolved.remedy
|
|
1877
|
+
};
|
|
1878
|
+
},
|
|
1879
|
+
waitSeconds,
|
|
1880
|
+
noWait,
|
|
1881
|
+
now: d.now,
|
|
1882
|
+
warn: (line) => note(chalk.yellow(phaseLine("lease", line)))
|
|
1883
|
+
});
|
|
1884
|
+
if (pooled.status === "refused") return fail({
|
|
1885
|
+
code: pooled.refusal.code,
|
|
1886
|
+
message: pooled.refusal.message,
|
|
1887
|
+
remedy: pooled.refusal.remedy,
|
|
1888
|
+
...pooled.refusal.lease === null ? {} : { lease: pooled.refusal.lease }
|
|
1889
|
+
});
|
|
1890
|
+
physicalDevice = {
|
|
1891
|
+
udid: pooled.candidate.id,
|
|
1892
|
+
name: pooled.candidate.name ?? pooled.candidate.id
|
|
1893
|
+
};
|
|
1894
|
+
} else if (physical) {
|
|
1895
|
+
const resolved = resolveIosPhysicalDevice(typeof deviceFlag === "string" ? deviceFlag : null, d.listIosDevices());
|
|
1896
|
+
if (!resolved.udid) return fail({
|
|
1897
|
+
code: "STIM_NO_DEVICE",
|
|
1898
|
+
message: resolved.error,
|
|
1899
|
+
remedy: resolved.remedy
|
|
1900
|
+
});
|
|
1901
|
+
physicalDevice = {
|
|
1902
|
+
udid: resolved.udid,
|
|
1903
|
+
name: resolved.name ?? resolved.udid
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
if (!physical) {
|
|
1907
|
+
const capacity = d.checkDeviceCapacity({
|
|
1908
|
+
platform: "ios",
|
|
1909
|
+
project: proj,
|
|
1910
|
+
max: limits.maxDevices
|
|
1911
|
+
});
|
|
1912
|
+
if (capacity) return fail(capacity);
|
|
1913
|
+
}
|
|
1914
|
+
let metroPort = proj?.metroPort ?? null;
|
|
1915
|
+
let lanAddress = null;
|
|
1916
|
+
let lanOriginUrl = null;
|
|
1917
|
+
if (!await resolveMetroPort()) return null;
|
|
1918
|
+
let device;
|
|
1919
|
+
if (physicalDevice) device = {
|
|
1920
|
+
deviceUdid: physicalDevice.udid,
|
|
1921
|
+
deviceName: physicalDevice.name,
|
|
1922
|
+
owned: false
|
|
1923
|
+
};
|
|
1924
|
+
else {
|
|
1925
|
+
const prepare = stepClock(d.now);
|
|
1926
|
+
try {
|
|
1927
|
+
device = await d.ensureOwnedDevice({
|
|
1928
|
+
platform: "ios",
|
|
1929
|
+
project: proj,
|
|
1930
|
+
projectPath: root,
|
|
1931
|
+
settingsRoot: root,
|
|
1932
|
+
settings,
|
|
1933
|
+
flags: {
|
|
1934
|
+
deviceType,
|
|
1935
|
+
runtime
|
|
1936
|
+
},
|
|
1937
|
+
note,
|
|
1938
|
+
out: note
|
|
1939
|
+
});
|
|
1940
|
+
} catch (e) {
|
|
1941
|
+
return fail({
|
|
1942
|
+
code: "STIM_NO_DEVICE",
|
|
1943
|
+
message: `Could not ensure an owned iOS simulator: ${e?.message || e}`,
|
|
1944
|
+
remedy: "Run `stim doctor` to check the simulator toolchain, then try again."
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
const prepareMs = prepare();
|
|
1948
|
+
if (device.created || prepareMs >= 2e3) phase("device", `${deviceLabel(device, device.deviceUdid)} ${device.created ? "created" : "prepared"} (${formatDuration(prepareMs)})`);
|
|
1949
|
+
}
|
|
1950
|
+
let bootDuration = "";
|
|
1951
|
+
let bootPromise;
|
|
1952
|
+
let udid = "";
|
|
1953
|
+
let fingerprint = "";
|
|
1954
|
+
let fingerprintSources = [];
|
|
1955
|
+
let cacheKey = "";
|
|
1956
|
+
let storeHash = null;
|
|
1957
|
+
let storeKey = null;
|
|
1958
|
+
let storeSources = [];
|
|
1959
|
+
let appPath = null;
|
|
1960
|
+
let bundleId = null;
|
|
1961
|
+
let cacheHit = false;
|
|
1962
|
+
let remote = null;
|
|
1963
|
+
let abandonedRemote = false;
|
|
1964
|
+
let uploadPending = null;
|
|
1965
|
+
let providerUpload = null;
|
|
1966
|
+
let providerName = null;
|
|
1967
|
+
let providerLoad = null;
|
|
1968
|
+
const cacheWarn = createWarnOnce((line) => note(chalk.yellow(phaseLine("cache", line))));
|
|
1969
|
+
const loadProvider = cachePolicy.remote && cacheProviderConfig && !physical ? () => providerLoad ??= d.loadCacheProvider({
|
|
1970
|
+
projectRoot: root,
|
|
1971
|
+
config: cacheProviderConfig
|
|
1972
|
+
}) : null;
|
|
1973
|
+
if (cacheProviderConfig && physical) note(chalk.dim(phaseLine("cache", PROVIDER_SKIPPED_ON_DEVICE)));
|
|
1974
|
+
let waitedForBuild = null;
|
|
1975
|
+
let releasedWait = null;
|
|
1976
|
+
let swapDir = null;
|
|
1977
|
+
let swapFellBack = false;
|
|
1978
|
+
let buildFailure = {};
|
|
1979
|
+
async function resolveMetroPort() {
|
|
1980
|
+
if (release) {
|
|
1981
|
+
metroPort = null;
|
|
1982
|
+
phase("metro", `skipped (${configuration}: the JS bundle is embedded, no dev server is used)`);
|
|
1983
|
+
} else if (metroCheck) {
|
|
1984
|
+
if (!metroPort) {
|
|
1985
|
+
fail({
|
|
1986
|
+
code: "STIM_NO_METRO",
|
|
1987
|
+
message: "No Metro port is reserved for this workspace, so there is no dev server to build against.",
|
|
1988
|
+
remedy: "Run `stim start` first, or pass --no-metro-check."
|
|
1989
|
+
});
|
|
1990
|
+
return false;
|
|
1991
|
+
}
|
|
1992
|
+
const resolution = await d.resolveMetroWithRetry(d.resolveProjectMetro, metroPort, root, { onRetry: ({ delayMs }) => note(chalk.dim(phaseLine("metro", `port ${metroPort} did not verify yet; retrying in ${Math.round(delayMs / 1e3)}s (Metro may still be indexing)`))) });
|
|
1993
|
+
if (!resolution?.metro) {
|
|
1994
|
+
const supervisor = d.readWorkspaceState(root)?.supervisor ?? null;
|
|
1995
|
+
const supervisorAlive = Boolean(supervisor?.pid && d.pidExists(supervisor.pid));
|
|
1996
|
+
fail({
|
|
1997
|
+
code: "STIM_NO_METRO",
|
|
1998
|
+
message: noMetroMessage({
|
|
1999
|
+
port: metroPort,
|
|
2000
|
+
resolution,
|
|
2001
|
+
supervisor,
|
|
2002
|
+
supervisorAlive
|
|
2003
|
+
}),
|
|
2004
|
+
remedy: noMetroRemedy({
|
|
2005
|
+
port: metroPort,
|
|
2006
|
+
supervisor,
|
|
2007
|
+
supervisorAlive
|
|
2008
|
+
})
|
|
2009
|
+
});
|
|
2010
|
+
return false;
|
|
2011
|
+
}
|
|
2012
|
+
} else if (!metroPort) {
|
|
2013
|
+
metroPort = DEFAULT_METRO_PORT;
|
|
2014
|
+
note(chalk.yellow(`No Metro port is reserved for this workspace; wiring the app to ${metroPort}.`));
|
|
2015
|
+
}
|
|
2016
|
+
if (physical && metroPort !== null && !await resolveLanOrigin()) return false;
|
|
2017
|
+
if (remoteDevice && metroPort !== null) {
|
|
2018
|
+
const reachable = await d.ensureMetroReachable({
|
|
2019
|
+
ctx: remoteDevice.ctx,
|
|
2020
|
+
metroPort,
|
|
2021
|
+
isExpo,
|
|
2022
|
+
tunnelMode: tunnelModeSetting(settings) ?? void 0,
|
|
2023
|
+
publicUrl: publicUrlSetting(settings),
|
|
2024
|
+
available: d.detectProviders(binOnPath)
|
|
2025
|
+
});
|
|
2026
|
+
if ("failed" in reachable) {
|
|
2027
|
+
fail({
|
|
2028
|
+
code: reachable.code ?? "STIM_NO_REMOTE_SESSION",
|
|
2029
|
+
message: reachable.failed,
|
|
2030
|
+
remedy: reachable.remedy
|
|
2031
|
+
});
|
|
2032
|
+
return false;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
return true;
|
|
2036
|
+
}
|
|
2037
|
+
async function resolveLanOrigin() {
|
|
2038
|
+
const port = metroPort;
|
|
2039
|
+
const chosen = chooseLanAddress({
|
|
2040
|
+
pinned: iosLanHostSetting(settings),
|
|
2041
|
+
candidates: d.hostLanCandidates()
|
|
2042
|
+
});
|
|
2043
|
+
if (!chosen) {
|
|
2044
|
+
fail({
|
|
2045
|
+
code: "STIM_NO_LAN_ADDRESS",
|
|
2046
|
+
message: "A Debug run on a phone needs an address the phone can reach, and this Mac has no non-internal IPv4 interface.",
|
|
2047
|
+
remedy: "The phone reaches Metro over the network you share, because USB carries no reverse forward. Join a Wi-Fi or Ethernet network, or connect this Mac by cable, then run the command again."
|
|
2048
|
+
});
|
|
2049
|
+
return false;
|
|
2050
|
+
}
|
|
2051
|
+
lanAddress = chosen.address;
|
|
2052
|
+
lanOriginUrl = lanOriginUrlFor(chosen.address, port);
|
|
2053
|
+
const source = chosen.pinned ? "ios.lanHost" : `${chosen.interfaceName ?? "interface"}${chosen.candidates > 1 ? ` of ${chosen.candidates} candidates` : ""}`;
|
|
2054
|
+
phase("lan", `${lanOriginUrl} (${source})`);
|
|
2055
|
+
if (publicUrlSetting(settings) || tunnelModeSetting(settings)) note(chalk.dim(phaseLine("lan", "metro.publicUrl and metro.tunnel are ignored on --device: neither channel to a phone carries a URL, only a host and a port. They still apply to --remote.")));
|
|
2056
|
+
if (!metroCheck) return true;
|
|
2057
|
+
const reachable = await d.ensureLanReachable({
|
|
2058
|
+
origin: lanOriginUrl,
|
|
2059
|
+
metroPort: port,
|
|
2060
|
+
root,
|
|
2061
|
+
isExpo,
|
|
2062
|
+
logsDir
|
|
2063
|
+
});
|
|
2064
|
+
if ("failed" in reachable) {
|
|
2065
|
+
fail({
|
|
2066
|
+
code: "STIM_LAN_METRO_UNREACHABLE",
|
|
2067
|
+
message: reachable.failed,
|
|
2068
|
+
remedy: reachable.remedy
|
|
2069
|
+
});
|
|
2070
|
+
return false;
|
|
2071
|
+
}
|
|
2072
|
+
phase("lan", `gated: ${lanOriginUrl} answered as this workspace's Metro`);
|
|
2073
|
+
return true;
|
|
2074
|
+
}
|
|
2075
|
+
async function resolveInitialFingerprint() {
|
|
2076
|
+
const bootTimer = stepTimer(d.now);
|
|
2077
|
+
const boot = () => physicalDevice ? Promise.resolve({
|
|
2078
|
+
ok: true,
|
|
2079
|
+
udid: physicalDevice.udid
|
|
2080
|
+
}) : Promise.resolve(d.ensureBooted({
|
|
2081
|
+
platform: "ios",
|
|
2082
|
+
device,
|
|
2083
|
+
out: note
|
|
2084
|
+
})).catch((e) => ({
|
|
2085
|
+
ok: false,
|
|
2086
|
+
reason: String(e?.message || e)
|
|
2087
|
+
}));
|
|
2088
|
+
bootPromise = (remoteDevice?.ctx.backend === "eas" ? d.ensureRemoteBootOwned({
|
|
2089
|
+
root,
|
|
2090
|
+
platform: "ios",
|
|
2091
|
+
sessionName: ownedSessionName(remoteDevice.ctx.label),
|
|
2092
|
+
startedAt,
|
|
2093
|
+
boot,
|
|
2094
|
+
createdSessionId: remoteDevice.createdSessionId,
|
|
2095
|
+
abandonCreatedSession: remoteDevice.abandonCreatedSession,
|
|
2096
|
+
writeState: d.writeWorkspaceState,
|
|
2097
|
+
register: registerProject
|
|
2098
|
+
}) : boot()).then((result) => {
|
|
2099
|
+
bootDuration = bootTimer();
|
|
2100
|
+
return result;
|
|
2101
|
+
});
|
|
2102
|
+
udid = device.deviceUdid ?? (await bootPromise)?.udid ?? "";
|
|
2103
|
+
const fingerprintTimer = stepTimer(d.now);
|
|
2104
|
+
let computedFingerprint;
|
|
2105
|
+
try {
|
|
2106
|
+
const computed = await d.fingerprintProject(root, { platform: "ios" });
|
|
2107
|
+
computedFingerprint = computed?.hash ?? null;
|
|
2108
|
+
fingerprintSources = computed?.sources ?? [];
|
|
2109
|
+
} catch (e) {
|
|
2110
|
+
computedFingerprint = null;
|
|
2111
|
+
note(chalk.dim(`Fingerprinting failed: ${e?.message || e}`));
|
|
2112
|
+
}
|
|
2113
|
+
if (!computedFingerprint) {
|
|
2114
|
+
fail({
|
|
2115
|
+
code: "STIM_NO_FINGERPRINT",
|
|
2116
|
+
message: `Could not fingerprint ${root}: @expo/fingerprint produced no hash for it.`,
|
|
2117
|
+
remedy: "Check the project native inputs and the @expo/fingerprint error above, then retry."
|
|
2118
|
+
});
|
|
2119
|
+
return false;
|
|
2120
|
+
}
|
|
2121
|
+
fingerprint = computedFingerprint;
|
|
2122
|
+
cacheKey = buildCacheKey("ios", fingerprint, {
|
|
2123
|
+
scheme: buildScheme,
|
|
2124
|
+
...configuration ? { configuration } : {},
|
|
2125
|
+
isSimulator: !physical,
|
|
2126
|
+
...buildProfile ? { buildProfile } : {}
|
|
2127
|
+
});
|
|
2128
|
+
stats.setCacheKey(cacheKey);
|
|
2129
|
+
storeHash = fingerprint;
|
|
2130
|
+
storeKey = cacheKey;
|
|
2131
|
+
storeSources = fingerprintSources;
|
|
2132
|
+
const found = await resolveTieredBuild({
|
|
2133
|
+
local: filesystemBuildCapability({
|
|
2134
|
+
resolve: d.resolveBuild,
|
|
2135
|
+
store: d.storeBuild,
|
|
2136
|
+
sources: fingerprintSources
|
|
2137
|
+
}),
|
|
2138
|
+
loadProvider,
|
|
2139
|
+
target: {
|
|
2140
|
+
projectRoot: root,
|
|
2141
|
+
platform: "ios",
|
|
2142
|
+
key: cacheKey
|
|
2143
|
+
},
|
|
2144
|
+
destinationDir: providerDownloadPath(workspaceDir(root)),
|
|
2145
|
+
ensureDestination: prepareProviderDownloadDir,
|
|
2146
|
+
skipRead: !useBuildCache,
|
|
2147
|
+
warn: cacheWarn
|
|
2148
|
+
});
|
|
2149
|
+
const cached = found?.tier === "local" ? found.path : null;
|
|
2150
|
+
cacheHit = cached ? "local" : false;
|
|
2151
|
+
let missDiff = "";
|
|
2152
|
+
let missUntracked = null;
|
|
2153
|
+
if (!cached) {
|
|
2154
|
+
const lastBuild = d.readWorkspaceState(root)?.lastBuild ?? null;
|
|
2155
|
+
const miss = describeFingerprintMiss({
|
|
2156
|
+
platform: "ios",
|
|
2157
|
+
current: {
|
|
2158
|
+
hash: fingerprint,
|
|
2159
|
+
sources: fingerprintSources
|
|
2160
|
+
},
|
|
2161
|
+
lastBuild
|
|
2162
|
+
});
|
|
2163
|
+
if (miss) {
|
|
2164
|
+
missDiff = fingerprintDiffSuffix(miss.changed);
|
|
2165
|
+
logWriter().write(fingerprintDiffRecord({
|
|
2166
|
+
changed: miss.changed,
|
|
2167
|
+
previousHash: miss.previousHash,
|
|
2168
|
+
hash: fingerprint
|
|
2169
|
+
}));
|
|
2170
|
+
} else if (useBuildCache) missUntracked = untrackedMissLine(d.untrackedNativeFiles({ projectRoot: root }));
|
|
2171
|
+
}
|
|
2172
|
+
phase("fingerprint", `${shortHash(fingerprint)} ${cached ? "hit" : "miss"}${useBuildCache ? "" : opts.buildCache === false ? " (--no-build-cache)" : " (cache reuse off in config)"} ${fingerprintTimer()}${missDiff}`);
|
|
2173
|
+
if (missUntracked) note(chalk.dim(phaseLine("fingerprint", missUntracked)));
|
|
2174
|
+
if (found?.tier === "provider") {
|
|
2175
|
+
cacheHit = "remote";
|
|
2176
|
+
providerName = found.providerName ?? null;
|
|
2177
|
+
phase("cache", `provider hit (${providerName})${found.storedLocally ? " -> stored locally" : ""}`);
|
|
2178
|
+
}
|
|
2179
|
+
appPath = found?.path ?? null;
|
|
2180
|
+
return true;
|
|
2181
|
+
}
|
|
2182
|
+
async function resolveRemoteArtifact() {
|
|
2183
|
+
if (physical || !cachePolicy.remote || buildProfile || buildScheme) return;
|
|
2184
|
+
if (!appPath) {
|
|
2185
|
+
const loaded = await d.loadProjectProvider(root, { isExpo });
|
|
2186
|
+
if (loaded?.unavailable) note(chalk.yellow(phaseLine("cache", `provider not usable: ${loaded.unavailable}`)));
|
|
2187
|
+
else if (loaded?.provider) remote = loaded;
|
|
2188
|
+
if (remote?.name === "eas") {
|
|
2189
|
+
const auth = d.checkEasAuth({
|
|
2190
|
+
projectRoot: root,
|
|
2191
|
+
owner: loaded?.owner || null
|
|
2192
|
+
});
|
|
2193
|
+
const authNote = easAuthNote(auth);
|
|
2194
|
+
if (authNote) note(chalk.yellow(phaseLine("cache", authNote)));
|
|
2195
|
+
if (auth?.code === "logged-out") remote = null;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
if (remote && useBuildCache) {
|
|
2199
|
+
const remoteTimer = stepTimer(d.now);
|
|
2200
|
+
const hit = await d.resolveRemote({
|
|
2201
|
+
logWriter: logWriter(),
|
|
2202
|
+
provider: remote.provider,
|
|
2203
|
+
platform: "ios",
|
|
2204
|
+
projectRoot: root,
|
|
2205
|
+
fingerprintHash: fingerprint,
|
|
2206
|
+
runOptions: configuration ? { configuration } : null
|
|
2207
|
+
});
|
|
2208
|
+
if (hit?.appPath) {
|
|
2209
|
+
let stored = null;
|
|
2210
|
+
try {
|
|
2211
|
+
stored = d.storeBuild("ios", cacheKey, hit.appPath, { sources: fingerprintSources });
|
|
2212
|
+
} catch (e) {
|
|
2213
|
+
note(chalk.yellow(phaseLine("cache", `remote hit could not be stored locally: ${e?.message || e}`)));
|
|
2214
|
+
}
|
|
2215
|
+
appPath = stored || hit.appPath;
|
|
2216
|
+
cacheHit = "remote";
|
|
2217
|
+
phase("cache", `remote hit (${remote.name})${stored ? " -> stored locally" : ""} ${remoteTimer()}`);
|
|
2218
|
+
} else if (hit?.timedOut) {
|
|
2219
|
+
abandonedRemote = true;
|
|
2220
|
+
note(chalk.yellow(phaseLine("cache", `${remote.name} did not answer within ${formatDuration(RESOLVE_TIMEOUT_MS)}; building instead`)));
|
|
2221
|
+
} else if (hit?.failed) {
|
|
2222
|
+
const authNote = remote.name === "eas" && isEasAuthFailureText(hit.failed) ? easAuthNote({
|
|
2223
|
+
code: "logged-out",
|
|
2224
|
+
reason: hit.failed
|
|
2225
|
+
}) : null;
|
|
2226
|
+
note(chalk.yellow(phaseLine("cache", authNote || `${remote.name} could not be used: ${hit.failed}; building instead`)));
|
|
2227
|
+
} else phase("cache", `remote miss (${remote.name}) ${remoteTimer()}`);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
async function waitForSharedBuild() {
|
|
2231
|
+
if (!useBuildCache) return true;
|
|
2232
|
+
const waitStarted = d.now();
|
|
2233
|
+
let failedHolder;
|
|
2234
|
+
while (!appPath) {
|
|
2235
|
+
let attempt = null;
|
|
2236
|
+
try {
|
|
2237
|
+
attempt = d.acquireBuildLock({
|
|
2238
|
+
platform: "ios",
|
|
2239
|
+
key: cacheKey,
|
|
2240
|
+
root,
|
|
2241
|
+
logFile
|
|
2242
|
+
});
|
|
2243
|
+
} catch (e) {
|
|
2244
|
+
const refusal = claimFailure(e, "stim ios");
|
|
2245
|
+
if (refusal) {
|
|
2246
|
+
fail({
|
|
2247
|
+
code: refusal.code,
|
|
2248
|
+
message: refusal.message,
|
|
2249
|
+
remedy: refusal.remedy,
|
|
2250
|
+
build: {
|
|
2251
|
+
fingerprint,
|
|
2252
|
+
cacheKey,
|
|
2253
|
+
cacheHit,
|
|
2254
|
+
cacheSkipped: !useBuildCache
|
|
2255
|
+
}
|
|
2256
|
+
});
|
|
2257
|
+
return false;
|
|
2258
|
+
}
|
|
2259
|
+
note(chalk.yellow(phaseLine("build", `could not take the build lock: ${e?.message || e}; building anyway`)));
|
|
2260
|
+
}
|
|
2261
|
+
if (attempt?.acquired) {
|
|
2262
|
+
buildLock = attempt;
|
|
2263
|
+
const previous = attempt.tookOver ?? failedHolder;
|
|
2264
|
+
if (previous) note(chalk.yellow(phaseLine("build", takeoverLine(previous))));
|
|
2265
|
+
break;
|
|
2266
|
+
} else if (attempt?.held) {
|
|
2267
|
+
releasedWait = null;
|
|
2268
|
+
const held = attempt.held;
|
|
2269
|
+
const who = held.projectRoot || "another workspace";
|
|
2270
|
+
phase("build", `${who} is already building ${shortHash(fingerprint)} (pid ${held.pid})${held.logFile ? ` -- tail ${held.logFile}` : ""}`);
|
|
2271
|
+
let waited = null;
|
|
2272
|
+
try {
|
|
2273
|
+
const ceilingMs = WAIT_CEILING_MS - (d.now() - waitStarted);
|
|
2274
|
+
if (ceilingMs <= 0) throw Object.assign(/* @__PURE__ */ new Error(`Waited ${formatDuration(d.now() - waitStarted)} for shared builds without an artifact; ${who} (pid ${held.pid}) holds ${attempt.path}.`), {
|
|
2275
|
+
code: "STIM_BUILD_WAIT_TIMEOUT",
|
|
2276
|
+
lockPath: attempt.path
|
|
2277
|
+
});
|
|
2278
|
+
waited = await d.waitForBuild({
|
|
2279
|
+
platform: "ios",
|
|
2280
|
+
key: cacheKey,
|
|
2281
|
+
out: note,
|
|
2282
|
+
ceilingMs
|
|
2283
|
+
});
|
|
2284
|
+
} catch (e) {
|
|
2285
|
+
const refusal = claimFailure(e, "stim ios");
|
|
2286
|
+
if (refusal) {
|
|
2287
|
+
fail({
|
|
2288
|
+
code: refusal.code,
|
|
2289
|
+
message: refusal.message,
|
|
2290
|
+
remedy: refusal.remedy,
|
|
2291
|
+
build: {
|
|
2292
|
+
fingerprint,
|
|
2293
|
+
cacheKey,
|
|
2294
|
+
cacheHit,
|
|
2295
|
+
cacheSkipped: !useBuildCache
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
return false;
|
|
2299
|
+
}
|
|
2300
|
+
const err = e;
|
|
2301
|
+
if (err?.code !== "STIM_BUILD_WAIT_TIMEOUT") throw e;
|
|
2302
|
+
fail({
|
|
2303
|
+
code: "STIM_BUILD_WAIT_TIMEOUT",
|
|
2304
|
+
message: err.message,
|
|
2305
|
+
remedy: `Check pid ${held.pid}; if it is not really building, remove ${err.lockPath} and run \`stim ios\` again.`,
|
|
2306
|
+
build: {
|
|
2307
|
+
fingerprint,
|
|
2308
|
+
cacheKey,
|
|
2309
|
+
cacheHit,
|
|
2310
|
+
cacheSkipped: !useBuildCache
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
return false;
|
|
2314
|
+
}
|
|
2315
|
+
if (waited?.hit) {
|
|
2316
|
+
appPath = waited.hit ?? null;
|
|
2317
|
+
cacheHit = "local";
|
|
2318
|
+
waitedForBuild = {
|
|
2319
|
+
pid: held.pid,
|
|
2320
|
+
ms: waited.waitedMs
|
|
2321
|
+
};
|
|
2322
|
+
phase("build", `waited ${formatDuration(waited.waitedMs)} for ${who}'s build -> installed from cache`);
|
|
2323
|
+
} else if (waited?.lockReleased) {
|
|
2324
|
+
failedHolder = void 0;
|
|
2325
|
+
releasedWait = {
|
|
2326
|
+
facts: {
|
|
2327
|
+
pid: held.pid,
|
|
2328
|
+
ms: waited.waitedMs
|
|
2329
|
+
},
|
|
2330
|
+
who
|
|
2331
|
+
};
|
|
2332
|
+
phase("build", `${who}'s build lock was released; rechecking this workspace before building`);
|
|
2333
|
+
} else {
|
|
2334
|
+
note(chalk.yellow(phaseLine("build", `${who}'s build ended without an artifact (${waited?.builderFailed}); retrying the build lock`)));
|
|
2335
|
+
failedHolder = held;
|
|
2336
|
+
}
|
|
2337
|
+
} else break;
|
|
2338
|
+
}
|
|
2339
|
+
return true;
|
|
2340
|
+
}
|
|
2341
|
+
const prepareDeviceApp = async (path, { fresh }) => {
|
|
2342
|
+
const refuse = (code, reason, remedy) => {
|
|
2343
|
+
if (fresh) {
|
|
2344
|
+
fail({
|
|
2345
|
+
code,
|
|
2346
|
+
message: reason,
|
|
2347
|
+
remedy,
|
|
2348
|
+
build: {
|
|
2349
|
+
...buildFailure,
|
|
2350
|
+
appPath: path
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
return null;
|
|
2354
|
+
}
|
|
2355
|
+
note(chalk.yellow(phaseLine("cache", `${reason} -- building fresh instead`)));
|
|
2356
|
+
note(chalk.dim(phaseLine("", remedy)));
|
|
2357
|
+
swapFellBack = true;
|
|
2358
|
+
return null;
|
|
2359
|
+
};
|
|
2360
|
+
const gateProfile = () => {
|
|
2361
|
+
const gate = d.gateProfileForDevice({
|
|
2362
|
+
appPath: path,
|
|
2363
|
+
udid,
|
|
2364
|
+
configuration
|
|
2365
|
+
});
|
|
2366
|
+
return gate.ok ? path : refuse(gate.code, gate.reason, gate.remedy);
|
|
2367
|
+
};
|
|
2368
|
+
if (release) {
|
|
2369
|
+
if (!fresh) {
|
|
2370
|
+
note(chalk.yellow(phaseLine("cache", `a cached ${configuration} device app carries its builder's JS, and the device JS swap lands with phase 6 of appandflow/stim#178 -- building fresh instead, which bakes in this workspace's JS`)));
|
|
2371
|
+
swapFellBack = true;
|
|
2372
|
+
return null;
|
|
2373
|
+
}
|
|
2374
|
+
return gateProfile();
|
|
2375
|
+
}
|
|
2376
|
+
if (d.devClientScheme(root, path)) return gateProfile();
|
|
2377
|
+
let copy;
|
|
2378
|
+
try {
|
|
2379
|
+
copy = copyAppAside(path);
|
|
2380
|
+
} catch (e) {
|
|
2381
|
+
return refuse("STIM_INSTALL_FAILED", `Could not copy ${path} aside to write its ip.txt: ${e?.message || e}`, "Free space in the temporary directory and run the command again.");
|
|
2382
|
+
}
|
|
2383
|
+
writeIpTxt(copy.appPath, lanAddress, metroPort);
|
|
2384
|
+
const sealed = d.sealAppForDevice({
|
|
2385
|
+
appPath: copy.appPath,
|
|
2386
|
+
udid,
|
|
2387
|
+
configuration,
|
|
2388
|
+
pinnedName: iosSigningIdentitySetting(settings),
|
|
2389
|
+
pinnedSha1: iosSigningIdentitySha1Setting(settings)
|
|
2390
|
+
});
|
|
2391
|
+
if (!sealed.ok) {
|
|
2392
|
+
try {
|
|
2393
|
+
rmSync(copy.tmpDir, {
|
|
2394
|
+
recursive: true,
|
|
2395
|
+
force: true
|
|
2396
|
+
});
|
|
2397
|
+
} catch {}
|
|
2398
|
+
for (const line of sealed.lastLines ?? []) note(chalk.dim(phaseLine("", line)));
|
|
2399
|
+
return refuse(sealed.code, sealed.reason, sealed.remedy);
|
|
2400
|
+
}
|
|
2401
|
+
if (swapDir) try {
|
|
2402
|
+
rmSync(swapDir, {
|
|
2403
|
+
recursive: true,
|
|
2404
|
+
force: true
|
|
2405
|
+
});
|
|
2406
|
+
} catch {}
|
|
2407
|
+
swapDir = copy.tmpDir;
|
|
2408
|
+
phase("ip.txt", `${lanAddress}:${metroPort} written into the install copy and re-sealed with "${sealed.identity.name}"${sealed.mode === "preserve-metadata" ? "" : ` (${sealed.mode})`}`);
|
|
2409
|
+
return copy.appPath;
|
|
2410
|
+
};
|
|
2411
|
+
const installableCachedApp = async (cachedPath) => {
|
|
2412
|
+
if (physical) return prepareDeviceApp(cachedPath, { fresh: false });
|
|
2413
|
+
if (!release) return cachedPath;
|
|
2414
|
+
phase("swap", `regenerating this workspace's JS for the cached ${configuration} app`);
|
|
2415
|
+
const swap = await d.swapJsBundle({
|
|
2416
|
+
root,
|
|
2417
|
+
isExpo,
|
|
2418
|
+
cachedAppPath: cachedPath,
|
|
2419
|
+
logWriter: logWriter()
|
|
2420
|
+
});
|
|
2421
|
+
if (swap?.ok && swap.appPath) {
|
|
2422
|
+
if (swap.note) note(chalk.yellow(phaseLine("swap", swap.note)));
|
|
2423
|
+
swapDir = swap.tmpDir ?? null;
|
|
2424
|
+
phase("swap", `${swap.hermes ? "hermes bytecode" : "plain JS"} + assets replaced, re-signed (${formatDuration(swap.durationMs ?? 0)})`);
|
|
2425
|
+
return swap.appPath;
|
|
2426
|
+
}
|
|
2427
|
+
note(chalk.yellow(phaseLine("swap", `failed at ${swap?.step || "unknown step"}: ${swap?.reason || "unknown reason"} -- building fresh instead (a cached ${configuration} app carries its builder's JS; it is never installed after a failed swap)`)));
|
|
2428
|
+
for (const line of swap?.lastLines ?? []) note(chalk.dim(phaseLine("", line)));
|
|
2429
|
+
swapFellBack = true;
|
|
2430
|
+
return null;
|
|
2431
|
+
};
|
|
2432
|
+
async function prepareCachedArtifact() {
|
|
2433
|
+
if (appPath && cacheHit) {
|
|
2434
|
+
const prepared = await installableCachedApp(appPath);
|
|
2435
|
+
appPath = prepared;
|
|
2436
|
+
if (!prepared) {
|
|
2437
|
+
cacheHit = false;
|
|
2438
|
+
waitedForBuild = null;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
async function buildArtifact() {
|
|
2443
|
+
buildFailure = {
|
|
2444
|
+
fingerprint,
|
|
2445
|
+
cacheKey,
|
|
2446
|
+
cacheHit,
|
|
2447
|
+
cacheSkipped: !useBuildCache
|
|
2448
|
+
};
|
|
2449
|
+
if (!appPath) try {
|
|
2450
|
+
if (limits.maxBuilds) try {
|
|
2451
|
+
buildSlot = await d.acquireBuildSlot({
|
|
2452
|
+
max: limits.maxBuilds,
|
|
2453
|
+
root,
|
|
2454
|
+
logFile,
|
|
2455
|
+
out: note
|
|
2456
|
+
});
|
|
2457
|
+
} catch (e) {
|
|
2458
|
+
const refusal = claimFailure(e, "stim ios");
|
|
2459
|
+
if (refusal) {
|
|
2460
|
+
fail({
|
|
2461
|
+
code: refusal.code,
|
|
2462
|
+
message: refusal.message,
|
|
2463
|
+
remedy: refusal.remedy,
|
|
2464
|
+
build: buildFailure
|
|
2465
|
+
});
|
|
2466
|
+
return false;
|
|
2467
|
+
}
|
|
2468
|
+
note(chalk.yellow(phaseLine("build", `could not take a build slot: ${e?.message || e}; building anyway`)));
|
|
2469
|
+
}
|
|
2470
|
+
const mutatingSteps = [];
|
|
2471
|
+
if (d.needsPrebuild(root, "ios", isExpo)) {
|
|
2472
|
+
const result = await d.runPrebuild(root, "ios", logWriter());
|
|
2473
|
+
if (result?.failed) {
|
|
2474
|
+
phase("prebuild", "FAILED");
|
|
2475
|
+
fail({
|
|
2476
|
+
code: result.code || "STIM_PREBUILD_FAILED",
|
|
2477
|
+
message: result.reason || "expo prebuild failed.",
|
|
2478
|
+
remedy: result.remedy || `See ${logFile} for the transcript.`,
|
|
2479
|
+
lines: (result.lastLines || []).slice(-5),
|
|
2480
|
+
build: buildFailure
|
|
2481
|
+
});
|
|
2482
|
+
return false;
|
|
2483
|
+
}
|
|
2484
|
+
phase("prebuild", `ios/ absent -> generated (${formatDuration(result?.durationMs ?? 0)})`);
|
|
2485
|
+
mutatingSteps.push("prebuild");
|
|
2486
|
+
}
|
|
2487
|
+
const podState = d.readPodState(root);
|
|
2488
|
+
const action = podAction(podState, d.podsAreStale(podState.lockText, podState.manifestText));
|
|
2489
|
+
if (action.install) {
|
|
2490
|
+
const result = await d.runPodInstall(root, logWriter(), { estimateMs: estimates().podsMs });
|
|
2491
|
+
const podCommand = result?.command || "pod install";
|
|
2492
|
+
for (const line of result?.notes || []) note(chalk.dim(phaseLine("pods", line)));
|
|
2493
|
+
if (result?.failed) {
|
|
2494
|
+
phase("pods", "FAILED");
|
|
2495
|
+
fail({
|
|
2496
|
+
code: result.code || "STIM_DEPS_FAILED",
|
|
2497
|
+
message: result.reason || "`pod install` failed.",
|
|
2498
|
+
remedy: result.remedy || `See ${logFile} for the transcript.`,
|
|
2499
|
+
lines: result.diagnosticLines?.length ? result.diagnosticLines : (result.lastLines || []).slice(-5),
|
|
2500
|
+
build: buildFailure
|
|
2501
|
+
});
|
|
2502
|
+
return false;
|
|
2503
|
+
}
|
|
2504
|
+
stats.setPodsMs(result?.durationMs ?? 0);
|
|
2505
|
+
phase("pods", `${action.reason} -> installed with \`${podCommand}\` (${formatDuration(result?.durationMs ?? 0)})`);
|
|
2506
|
+
mutatingSteps.push(podCommand);
|
|
2507
|
+
}
|
|
2508
|
+
if (mutatingSteps.length) {
|
|
2509
|
+
const after = await refingerprintAfterMutation({
|
|
2510
|
+
projectRoot: root,
|
|
2511
|
+
platform: "ios",
|
|
2512
|
+
previousHash: fingerprint,
|
|
2513
|
+
fingerprint: d.fingerprintProject
|
|
2514
|
+
});
|
|
2515
|
+
if (!after) {
|
|
2516
|
+
storeHash = null;
|
|
2517
|
+
storeKey = null;
|
|
2518
|
+
buildFailure = {
|
|
2519
|
+
...buildFailure,
|
|
2520
|
+
fingerprint: null,
|
|
2521
|
+
cacheKey: null
|
|
2522
|
+
};
|
|
2523
|
+
note(chalk.yellow(phaseLine("fingerprint", `unavailable after ${mutatingSteps.join(", ")}; the build will be installed but not cached`)));
|
|
2524
|
+
} else if (after.moved) {
|
|
2525
|
+
storeHash = after.hash;
|
|
2526
|
+
storeSources = after.sources;
|
|
2527
|
+
storeKey = buildCacheKey("ios", after.hash, {
|
|
2528
|
+
scheme: buildScheme,
|
|
2529
|
+
...configuration ? { configuration } : {},
|
|
2530
|
+
isSimulator: !physical,
|
|
2531
|
+
...buildProfile ? { buildProfile } : {}
|
|
2532
|
+
});
|
|
2533
|
+
note(chalk.dim(phaseLine("fingerprint", `${shortHash(fingerprint)} -> ${shortHash(storeHash)} (after ${mutatingSteps.join(", ")})`)));
|
|
2534
|
+
const late = useBuildCache ? d.resolveBuild("ios", storeKey) : null;
|
|
2535
|
+
if (late) {
|
|
2536
|
+
const prepared = await installableCachedApp(late);
|
|
2537
|
+
if (prepared) {
|
|
2538
|
+
appPath = prepared;
|
|
2539
|
+
cacheHit = "local";
|
|
2540
|
+
phase("cache", `hit ${shortHash(storeHash)} (post-${mutatingSteps.join("/")} key)`);
|
|
2541
|
+
if (releasedWait) {
|
|
2542
|
+
waitedForBuild = releasedWait.facts;
|
|
2543
|
+
phase("build", `waited ${formatDuration(waitedForBuild.ms)} for ${releasedWait.who}'s build -> installed from cache`);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
if (!appPath) {
|
|
2550
|
+
phase("build", `compiling ${configuration || "Debug"} with xcodebuild`);
|
|
2551
|
+
const result = await d.buildIos({
|
|
2552
|
+
root,
|
|
2553
|
+
scheme: buildScheme,
|
|
2554
|
+
udid,
|
|
2555
|
+
destination: remoteDevice ? GENERIC_SIM_DESTINATION : null,
|
|
2556
|
+
...physical ? { sdk: IPHONEOS_SDK } : {},
|
|
2557
|
+
logWriter: logWriter(),
|
|
2558
|
+
...configuration ? { configuration } : {},
|
|
2559
|
+
estimateMs: estimates().coldBuildMs,
|
|
2560
|
+
optimizations: optimizations.ios
|
|
2561
|
+
});
|
|
2562
|
+
compilationCache = result.compilationCache ?? COMPILATION_CACHE_UNAVAILABLE;
|
|
2563
|
+
phase("cache", `compilation cache ${compilationCacheActivityLine(compilationCache)}`);
|
|
2564
|
+
if (result?.failed) {
|
|
2565
|
+
phase("build", `FAILED after ${formatDuration(result.durationMs)}`);
|
|
2566
|
+
printDiagnostics(note, result);
|
|
2567
|
+
const report = xcodeFailureReport(result, logFile);
|
|
2568
|
+
fail({
|
|
2569
|
+
code: result.code || "STIM_BUILD_FAILED",
|
|
2570
|
+
message: report.message,
|
|
2571
|
+
remedy: report.remedy,
|
|
2572
|
+
logPath: logFile,
|
|
2573
|
+
build: buildFailure
|
|
2574
|
+
});
|
|
2575
|
+
return false;
|
|
2576
|
+
}
|
|
2577
|
+
stats.setBuildMs(result.durationMs ?? 0);
|
|
2578
|
+
phase("build", `ok (${formatDuration(result.durationMs)})`);
|
|
2579
|
+
appPath = result.appPath ?? null;
|
|
2580
|
+
bundleId = result.bundleId ?? null;
|
|
2581
|
+
if (storeKey && cachePolicy.write) try {
|
|
2582
|
+
const stored = await storeTieredBuild({
|
|
2583
|
+
local: filesystemBuildCapability({
|
|
2584
|
+
resolve: d.resolveBuild,
|
|
2585
|
+
store: d.storeBuild,
|
|
2586
|
+
sources: storeSources
|
|
2587
|
+
}),
|
|
2588
|
+
loadProvider,
|
|
2589
|
+
target: {
|
|
2590
|
+
projectRoot: root,
|
|
2591
|
+
platform: "ios",
|
|
2592
|
+
key: storeKey
|
|
2593
|
+
},
|
|
2594
|
+
sourcePath: appPath,
|
|
2595
|
+
overwrite: !useBuildCache || swapFellBack,
|
|
2596
|
+
warn: cacheWarn
|
|
2597
|
+
});
|
|
2598
|
+
providerUpload = stored.providerUpload;
|
|
2599
|
+
providerName = stored.providerName ?? providerName;
|
|
2600
|
+
} catch (e) {
|
|
2601
|
+
note(chalk.yellow(`Could not store the build in the shared cache: ${e?.message || e}`));
|
|
2602
|
+
}
|
|
2603
|
+
if (physical) {
|
|
2604
|
+
const prepared = await prepareDeviceApp(appPath, { fresh: true });
|
|
2605
|
+
if (!prepared) return false;
|
|
2606
|
+
appPath = prepared;
|
|
2607
|
+
}
|
|
2608
|
+
if (remote && !physical && storeHash) uploadPending = d.uploadRemote({
|
|
2609
|
+
logWriter: logWriter(),
|
|
2610
|
+
provider: remote.provider,
|
|
2611
|
+
platform: "ios",
|
|
2612
|
+
projectRoot: root,
|
|
2613
|
+
fingerprintHash: storeHash,
|
|
2614
|
+
buildPath: appPath,
|
|
2615
|
+
runOptions: configuration ? { configuration } : null
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
} finally {
|
|
2619
|
+
releaseLock();
|
|
2620
|
+
releaseSlot();
|
|
2621
|
+
}
|
|
2622
|
+
return true;
|
|
2623
|
+
}
|
|
2624
|
+
try {
|
|
2625
|
+
if (!await resolveInitialFingerprint()) return null;
|
|
2626
|
+
await resolveRemoteArtifact();
|
|
2627
|
+
if (!await waitForSharedBuild()) return null;
|
|
2628
|
+
await prepareCachedArtifact();
|
|
2629
|
+
if (!await buildArtifact()) return null;
|
|
2630
|
+
if (physicalDevice) {
|
|
2631
|
+
const acquired = await d.acquireRunLease({
|
|
2632
|
+
root,
|
|
2633
|
+
platform: "ios",
|
|
2634
|
+
id: physicalDevice.udid,
|
|
2635
|
+
deviceName: physicalDevice.name,
|
|
2636
|
+
idLabel: "udid",
|
|
2637
|
+
waitSeconds,
|
|
2638
|
+
noWait,
|
|
2639
|
+
installBoundMs: DEVICECTL_INSTALL_TIMEOUT_MS,
|
|
2640
|
+
appId: bundleId ?? proj?.bundleId ?? null,
|
|
2641
|
+
holderAppId: (holder) => d.getProject(holder)?.bundleId ?? null,
|
|
2642
|
+
now: d.now,
|
|
2643
|
+
warn: (line) => note(chalk.yellow(phaseLine("lease", line)))
|
|
2644
|
+
});
|
|
2645
|
+
if (acquired.status === "refused") return fail({
|
|
2646
|
+
code: acquired.refusal.code,
|
|
2647
|
+
message: acquired.refusal.message,
|
|
2648
|
+
remedy: acquired.refusal.remedy,
|
|
2649
|
+
lease: acquired.refusal.lease
|
|
2650
|
+
});
|
|
2651
|
+
leaseHandle = d.runLease({
|
|
2652
|
+
root,
|
|
2653
|
+
platform: "ios",
|
|
2654
|
+
kind: acquired.status === "leased" ? acquired.kind : null,
|
|
2655
|
+
expiresAt: acquired.status === "leased" ? acquired.expiresAt : null
|
|
2656
|
+
});
|
|
2657
|
+
if (acquired.status === "leased") {
|
|
2658
|
+
stopLeaseSignals = d.releaseLeaseOnSignal(releaseLease);
|
|
2659
|
+
phase("lease", `${acquired.kind} lease on ${physicalDevice.udid} until ${leaseExpiryText(acquired.expiresAt, d.now())}`);
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
try {
|
|
2663
|
+
return await finishIosRun({
|
|
2664
|
+
d,
|
|
2665
|
+
root,
|
|
2666
|
+
json,
|
|
2667
|
+
release,
|
|
2668
|
+
configuration,
|
|
2669
|
+
buildScheme,
|
|
2670
|
+
isExpo,
|
|
2671
|
+
metroCheck,
|
|
2672
|
+
metroPort,
|
|
2673
|
+
logsDir,
|
|
2674
|
+
logFile,
|
|
2675
|
+
device,
|
|
2676
|
+
udid,
|
|
2677
|
+
physical,
|
|
2678
|
+
lanAddress,
|
|
2679
|
+
lanOriginUrl,
|
|
2680
|
+
remoteDevice,
|
|
2681
|
+
bootPromise,
|
|
2682
|
+
bootDuration: () => bootDuration,
|
|
2683
|
+
appPath,
|
|
2684
|
+
bundleId,
|
|
2685
|
+
swapDir,
|
|
2686
|
+
buildFailure,
|
|
2687
|
+
fail,
|
|
2688
|
+
phase,
|
|
2689
|
+
note,
|
|
2690
|
+
logWriter,
|
|
2691
|
+
uploadPending,
|
|
2692
|
+
providerUpload,
|
|
2693
|
+
providerName,
|
|
2694
|
+
remote,
|
|
2695
|
+
abandonedRemote,
|
|
2696
|
+
elapsed,
|
|
2697
|
+
startedAt,
|
|
2698
|
+
storeHash,
|
|
2699
|
+
storeKey,
|
|
2700
|
+
cacheHit,
|
|
2701
|
+
compilationCache,
|
|
2702
|
+
useBuildCache,
|
|
2703
|
+
waitedForBuild,
|
|
2704
|
+
closeWriter: () => writer?.close?.(),
|
|
2705
|
+
lease: leaseHandle,
|
|
2706
|
+
releaseLease,
|
|
2707
|
+
recordRun
|
|
2708
|
+
});
|
|
2709
|
+
} finally {
|
|
2710
|
+
releaseLease();
|
|
2711
|
+
}
|
|
2712
|
+
} catch (error) {
|
|
2713
|
+
recordRun({
|
|
2714
|
+
failed: true,
|
|
2715
|
+
durationMs: elapsed()
|
|
2716
|
+
});
|
|
2717
|
+
throw error;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
//#endregion
|
|
2721
|
+
export { appNameFromPath, buildLogFile, cacheDescription, collectorEntry, iosCommand as default, devClientScheme, deviceLabel, ensureWorkspaceStorageSafely, formatDuration, gateShouldRetry, iosConfigurationSetting, iosFacts, isReleaseConfiguration, lastBuildRecord, noMetroMessage, phaseLine, pickDevClientScheme, podAction, registerIos, replaceCollector, resolveConfiguration, resolveDeviceType, resolveMetroWithRetry, resolveRuntime, schemesFromInfoPlist, shortHash, shortUdid, writeLastBuild };
|