Skip to content

Commit a141247

Browse files
authored
chore: don't require full build output (#204)
* chore: don't require full build output * changeset
1 parent b87265a commit a141247

File tree

7 files changed

+56
-38
lines changed

7 files changed

+56
-38
lines changed

.changeset/forty-clouds-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rnef/platform-apple-helpers': patch
3+
---
4+
5+
chore: don't require full build output

packages/platform-apple-helpers/src/lib/commands/run/getBuildSettings.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { color, logger, spawn } from '@rnef/tools';
22
import type { XcodeProjectInfo } from '../../types/index.js';
3+
import type { PlatformSDK } from '../../utils/getPlatformInfo.js';
34

45
export type BuildSettings = {
56
TARGET_BUILD_DIR: string;
@@ -12,7 +13,7 @@ export async function getBuildSettings(
1213
xcodeProject: XcodeProjectInfo,
1314
sourceDir: string,
1415
configuration: string,
15-
buildOutput: string,
16+
platformSDK: PlatformSDK,
1617
scheme: string,
1718
target?: string
1819
): Promise<BuildSettings | null> {
@@ -24,7 +25,7 @@ export async function getBuildSettings(
2425
'-scheme',
2526
scheme,
2627
'-sdk',
27-
getPlatformName(buildOutput),
28+
platformSDK,
2829
'-configuration',
2930
configuration,
3031
'-showBuildSettings',
@@ -67,16 +68,3 @@ export async function getBuildSettings(
6768

6869
return null;
6970
}
70-
71-
function getPlatformName(buildOutput: string) {
72-
// Xcode can sometimes escape `=` with a backslash or put the value in quotes
73-
const platformNameMatch = /export PLATFORM_NAME\\?="?(\w+)"?$/m.exec(
74-
buildOutput
75-
);
76-
if (!platformNameMatch) {
77-
throw new Error(
78-
'Couldn\'t find "PLATFORM_NAME" variable in xcodebuild output. Please report this issue and run your project with Xcode instead.'
79-
);
80-
}
81-
return platformNameMatch[1];
82-
}

packages/platform-apple-helpers/src/lib/commands/run/installApp.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path';
22
import { logger, RnefError, spawn, type SubprocessError } from '@rnef/tools';
33
import type { ApplePlatform, XcodeProjectInfo } from '../../types/index.js';
4+
import { getSimulatorPlatformSDK } from '../../utils/getPlatformInfo.js';
45
import { readKeyFromPlist } from '../../utils/plist.js';
56
import { getBuildPath } from './getBuildPath.js';
67
import { getBuildSettings } from './getBuildSettings.js';
@@ -35,7 +36,7 @@ export default async function installApp({
3536
xcodeProject,
3637
sourceDir,
3738
configuration,
38-
`export PLATFORM_NAME=${getPlatformSDK(platform)}`, // simulate build output
39+
getSimulatorPlatformSDK(platform),
3940
scheme,
4041
target
4142
);
@@ -84,15 +85,4 @@ export default async function installApp({
8485
}
8586
}
8687

87-
export function getPlatformSDK(platform: ApplePlatform) {
88-
switch (platform) {
89-
case 'ios':
90-
return 'iphonesimulator';
91-
case 'macos':
92-
return 'macosx';
93-
case 'tvos':
94-
return 'appletvsimulator';
95-
case 'visionos':
96-
return 'xrsimulator';
97-
}
98-
}
88+

packages/platform-apple-helpers/src/lib/commands/run/runOnDevice.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
Device,
66
XcodeProjectInfo,
77
} from '../../types/index.js';
8+
import { getDevicePlatformSDK } from '../../utils/getPlatformInfo.js';
89
import { buildProject } from '../build/buildProject.js';
910
import { getBuildPath } from './getBuildPath.js';
1011
import { getBuildSettings } from './getBuildSettings.js';
@@ -19,9 +20,9 @@ export async function runOnDevice(
1920
sourceDir: string,
2021
args: RunFlags
2122
) {
22-
let buildOutput, appPath;
23+
let appPath;
2324
if (!args.binaryPath) {
24-
buildOutput = await buildProject(
25+
await buildProject(
2526
xcodeProject,
2627
sourceDir,
2728
platform,
@@ -35,7 +36,7 @@ export async function runOnDevice(
3536
xcodeProject,
3637
sourceDir,
3738
configuration,
38-
buildOutput,
39+
getDevicePlatformSDK(platform),
3940
scheme
4041
);
4142

packages/platform-apple-helpers/src/lib/commands/run/runOnMac.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { color, logger, RnefError, spawn } from '@rnef/tools';
22
import type { XcodeProjectInfo } from '../../types/index.js';
3+
import { getSimulatorPlatformSDK } from '../../utils/getPlatformInfo.js';
34
import { buildProject } from '../build/buildProject.js';
45
import { getBuildPath } from './getBuildPath.js';
56
import { getBuildSettings } from './getBuildSettings.js';
@@ -12,7 +13,7 @@ export async function runOnMac(
1213
scheme: string,
1314
args: RunFlags
1415
) {
15-
const buildOutput = await buildProject(
16+
await buildProject(
1617
xcodeProject,
1718
sourceDir,
1819
'macos',
@@ -23,7 +24,6 @@ export async function runOnMac(
2324
);
2425

2526
await openApp({
26-
buildOutput,
2727
xcodeProject,
2828
sourceDir,
2929
configuration,
@@ -34,7 +34,6 @@ export async function runOnMac(
3434
}
3535

3636
type Options = {
37-
buildOutput: string;
3837
xcodeProject: XcodeProjectInfo;
3938
sourceDir: string;
4039
configuration: string;
@@ -44,7 +43,6 @@ type Options = {
4443
};
4544

4645
async function openApp({
47-
buildOutput,
4846
xcodeProject,
4947
sourceDir,
5048
configuration,
@@ -58,7 +56,7 @@ async function openApp({
5856
xcodeProject,
5957
sourceDir,
6058
configuration,
61-
buildOutput,
59+
getSimulatorPlatformSDK('macos'),
6260
scheme,
6361
target
6462
);

packages/platform-apple-helpers/src/lib/commands/run/runOnMacCatalyst.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { spawn } from '@rnef/tools';
22
import type { ApplePlatform, XcodeProjectInfo } from '../../types/index.js';
3+
import { getSimulatorPlatformSDK } from '../../utils/getPlatformInfo.js';
34
import { buildProject } from '../build/buildProject.js';
45
import { getBuildPath } from './getBuildPath.js';
56
import { getBuildSettings } from './getBuildSettings.js';
@@ -18,7 +19,7 @@ export async function runOnMacCatalyst(
1819
'The "--binary-path" flag is not supported for Mac Catalyst device.'
1920
);
2021
}
21-
const buildOutput = await buildProject(
22+
await buildProject(
2223
xcodeProject,
2324
sourceDir,
2425
platform,
@@ -32,7 +33,7 @@ export async function runOnMacCatalyst(
3233
xcodeProject,
3334
sourceDir,
3435
configuration,
35-
buildOutput,
36+
getSimulatorPlatformSDK(platform),
3637
scheme
3738
);
3839

packages/platform-apple-helpers/src/lib/utils/getPlatformInfo.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,38 @@ export function getPlatformInfo(platform: ApplePlatform): PlatformInfo {
2929
};
3030
}
3131
}
32+
33+
export type PlatformSDK =
34+
| 'iphonesimulator'
35+
| 'macosx'
36+
| 'appletvsimulator'
37+
| 'xrsimulator'
38+
| 'iphoneos'
39+
| 'appletvos'
40+
| 'xr';
41+
42+
export function getSimulatorPlatformSDK(platform: ApplePlatform): PlatformSDK {
43+
switch (platform) {
44+
case 'ios':
45+
return 'iphonesimulator';
46+
case 'macos':
47+
return 'macosx';
48+
case 'tvos':
49+
return 'appletvsimulator';
50+
case 'visionos':
51+
return 'xrsimulator';
52+
}
53+
}
54+
55+
export function getDevicePlatformSDK(platform: ApplePlatform): PlatformSDK {
56+
switch (platform) {
57+
case 'ios':
58+
return 'iphoneos';
59+
case 'macos':
60+
return 'macosx';
61+
case 'tvos':
62+
return 'appletvos';
63+
case 'visionos':
64+
return 'xr';
65+
}
66+
}

0 commit comments

Comments
 (0)