forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetBuildSettings.ts
More file actions
77 lines (68 loc) · 2.12 KB
/
getBuildSettings.ts
File metadata and controls
77 lines (68 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {CLIError, logger} from '@react-native-community/cli-tools';
import {IOSProjectInfo} from '@react-native-community/cli-types';
import pico from 'picocolors';
import child_process from 'child_process';
export type BuildSettings = {
TARGET_BUILD_DIR: string;
INFOPLIST_PATH: string;
EXECUTABLE_FOLDER_PATH: string;
FULL_PRODUCT_NAME: string;
};
export async function getBuildSettings(
xcodeProject: IOSProjectInfo,
mode: string,
buildOutput: string,
scheme: string,
target?: string,
): Promise<BuildSettings | null> {
const buildSettings = child_process.execFileSync(
'xcodebuild',
[
xcodeProject.isWorkspace ? '-workspace' : '-project',
xcodeProject.name,
'-scheme',
scheme,
'-sdk',
getPlatformName(buildOutput),
'-configuration',
mode,
'-showBuildSettings',
'-json',
],
{encoding: 'utf8'},
);
const settings = JSON.parse(buildSettings);
// Find all 'app' targets in the build settings
const applicationTargets = settings
.filter((setting: any) => setting.buildSettings.WRAPPER_EXTENSION === 'app')
.map(({target: settingsTarget}: any) => settingsTarget);
if (applicationTargets.length === 0) {
return null;
}
let selectedTarget = applicationTargets[0];
if (target) {
if (!applicationTargets.includes(target)) {
logger.info(
`Target ${pico.bold(target)} not found for scheme ${pico.bold(
scheme,
)}, automatically selected target ${pico.bold(selectedTarget)}`,
);
} else {
selectedTarget = target;
}
}
const targetIndex = applicationTargets.indexOf(selectedTarget);
return settings[targetIndex].buildSettings;
}
function getPlatformName(buildOutput: string) {
// Xcode can sometimes escape `=` with a backslash or put the value in quotes
const platformNameMatch = /export PLATFORM_NAME\\?="?(\w+)"?$/m.exec(
buildOutput,
);
if (!platformNameMatch) {
throw new CLIError(
'Couldn\'t find "PLATFORM_NAME" variable in xcodebuild output. Please report this issue and run your project with Xcode instead.',
);
}
return platformNameMatch[1];
}