Skip to content

Commit 495d067

Browse files
grabbouthymikee
andauthored
feat: better platform name detection (#1326)
* feat: better platform name detection * chore: code * Update packages/platform-ios/src/commands/runIOS/index.ts Co-authored-by: Michał Pierzchała <[email protected]> * fix: ci * chore: fix lint Co-authored-by: Michał Pierzchała <[email protected]>
1 parent b52fc00 commit 495d067

File tree

1 file changed

+16
-22
lines changed
  • packages/platform-ios/src/commands/runIOS

1 file changed

+16
-22
lines changed

packages/platform-ios/src/commands/runIOS/index.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ async function runOnSimulator(
190190
bootSimulator(selectedSimulator);
191191
}
192192

193-
const appName = await buildProject(
193+
const buildOutput = await buildProject(
194194
xcodeProject,
195195
selectedSimulator.udid,
196196
scheme,
@@ -200,8 +200,7 @@ async function runOnSimulator(
200200
const appPath = getBuildPath(
201201
xcodeProject,
202202
args.configuration,
203-
appName,
204-
false,
203+
buildOutput,
205204
scheme,
206205
);
207206

@@ -257,7 +256,7 @@ async function runOnDevice(
257256
);
258257
}
259258

260-
const appName = await buildProject(
259+
const buildOutput = await buildProject(
261260
xcodeProject,
262261
selectedDevice.udid,
263262
scheme,
@@ -266,7 +265,7 @@ async function runOnDevice(
266265

267266
const iosDeployInstallArgs = [
268267
'--bundle',
269-
getBuildPath(xcodeProject, args.configuration, appName, true, scheme),
268+
getBuildPath(xcodeProject, args.configuration, buildOutput, scheme),
270269
'--id',
271270
selectedDevice.udid,
272271
'--justlaunch',
@@ -367,7 +366,7 @@ function buildProject(
367366
return;
368367
}
369368
logger.success('Successfully built the app');
370-
resolve(getProductName(buildOutput) || scheme);
369+
resolve(buildOutput);
371370
});
372371
});
373372
}
@@ -408,20 +407,9 @@ function getTargetPaths(buildSettings: string) {
408407
function getBuildPath(
409408
xcodeProject: ProjectInfo,
410409
configuration: string,
411-
appName: string,
412-
isDevice: boolean,
410+
buildOutput: string,
413411
scheme: string,
414412
) {
415-
let device;
416-
417-
if (isDevice) {
418-
device = 'iphoneos';
419-
} else if (appName.toLowerCase().includes('tvos')) {
420-
device = 'appletvsimulator';
421-
} else {
422-
device = 'iphonesimulator';
423-
}
424-
425413
const buildSettings = child_process.execFileSync(
426414
'xcodebuild',
427415
[
@@ -430,7 +418,7 @@ function getBuildPath(
430418
'-scheme',
431419
scheme,
432420
'-sdk',
433-
device,
421+
getPlatformName(buildOutput),
434422
'-configuration',
435423
configuration,
436424
'-showBuildSettings',
@@ -451,11 +439,17 @@ function getBuildPath(
451439
return `${targetBuildDir}/${executableFolderPath}`;
452440
}
453441

454-
function getProductName(buildOutput: string) {
455-
const productNameMatch = /export FULL_PRODUCT_NAME="?(.+).app"?$/m.exec(
442+
function getPlatformName(buildOutput: string) {
443+
// Xcode can sometimes escape `=` with a backslash or put the value in quotes
444+
const platformNameMatch = /export PLATFORM_NAME\\?="?(\w+)"?$/m.exec(
456445
buildOutput,
457446
);
458-
return productNameMatch ? productNameMatch[1] : null;
447+
if (!platformNameMatch) {
448+
throw new CLIError(
449+
'Couldn\'t find "PLATFORM_NAME" variable in xcodebuild output. Please report this issue and run your project with Xcode instead.',
450+
);
451+
}
452+
return platformNameMatch[1];
459453
}
460454

461455
function xcprettyAvailable() {

0 commit comments

Comments
 (0)