-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathxcodebuild-args-service.ts
119 lines (98 loc) · 4.28 KB
/
xcodebuild-args-service.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as path from "path";
import * as constants from "../../constants";
import { Configurations } from "../../common/constants";
const DevicePlatformSdkName = "iphoneos";
const SimulatorPlatformSdkName = "iphonesimulator";
enum ProductArgs {
target = "target",
scheme = "scheme"
}
export class XcodebuildArgsService implements IXcodebuildArgsService {
constructor(
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $devicesService: Mobile.IDevicesService,
private $fs: IFileSystem,
private $iOSWatchAppService: IIOSWatchAppService,
private $logger: ILogger
) { }
public async getBuildForSimulatorArgs(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<string[]> {
let args = await this.getArchitecturesArgs(buildConfig);
let productType: ProductArgs;
if (this.$iOSWatchAppService.hasWatchApp(platformData, projectData)) {
productType = ProductArgs.scheme;
args = args.concat(["-destination", "generic/platform=iOS Simulator", "CODE_SIGNING_ALLOWED=NO"]);
} else {
args = args.concat(["CODE_SIGN_IDENTITY="]);
}
args = args
.concat([
"build",
"-configuration", buildConfig.release ? Configurations.Release : Configurations.Debug
])
.concat(this.getBuildCommonArgs(platformData, projectData, SimulatorPlatformSdkName))
.concat(this.getBuildLoggingArgs())
.concat(this.getXcodeProjectArgs(platformData.projectRoot, projectData, productType));
return args;
}
public async getBuildForDeviceArgs(platformData: IPlatformData, projectData: IProjectData, buildConfig: IBuildConfig): Promise<string[]> {
const architectures = await this.getArchitecturesArgs(buildConfig);
const archivePath = path.join(platformData.getBuildOutputPath(buildConfig), projectData.projectName + ".xcarchive");
const args = [
"archive",
"-archivePath", archivePath,
"-configuration", buildConfig.release ? Configurations.Release : Configurations.Debug,
'-allowProvisioningUpdates'
]
.concat(this.getXcodeProjectArgs(platformData.projectRoot, projectData, ProductArgs.scheme))
.concat(architectures)
.concat(this.getBuildCommonArgs(platformData, projectData, DevicePlatformSdkName))
.concat(this.getBuildLoggingArgs());
return args;
}
private async getArchitecturesArgs(buildConfig: IBuildConfig): Promise<string[]> {
const args = [];
const devicesArchitectures = buildConfig.buildForDevice ? await this.getArchitecturesFromConnectedDevices(buildConfig) : [];
if (!buildConfig.buildForDevice || devicesArchitectures.length > 1) {
args.push("ONLY_ACTIVE_ARCH=NO");
}
return args;
}
private getXcodeProjectArgs(projectRoot: string, projectData: IProjectData, product?: ProductArgs): string[] {
const xcworkspacePath = path.join(projectRoot, `${projectData.projectName}.xcworkspace`);
if (this.$fs.exists(xcworkspacePath)) {
return [ "-workspace", xcworkspacePath, "-scheme", projectData.projectName ];
}
const xcodeprojPath = path.join(projectRoot, `${projectData.projectName}.xcodeproj`);
return [ "-project", xcodeprojPath, product ? "-" + product : "-target", projectData.projectName ];
}
private getBuildLoggingArgs(): string[] {
return this.$logger.getLevel() === "INFO" ? ["-quiet"] : [];
}
private getBuildCommonArgs(platformData: IPlatformData, projectData: IProjectData, platformSdkName: string): string[] {
let args: string[] = [];
if (!this.$iOSWatchAppService.hasWatchApp(platformData, projectData)) {
args = args.concat([ "-sdk", platformSdkName ]);
}
args = args.concat([
"BUILD_DIR=" + path.join(platformData.projectRoot, constants.BUILD_DIR),
'SHARED_PRECOMPS_DIR=' + path.join(platformData.projectRoot, constants.BUILD_DIR, 'sharedpch')
]);
return args;
}
private async getArchitecturesFromConnectedDevices(buildConfig: IiOSBuildConfig): Promise<string[]> {
const platform = this.$devicePlatformsConstants.iOS.toLowerCase();
await this.$devicesService.initialize({
platform,
deviceId: buildConfig.device,
skipEmulatorStart: true
});
const instances = this.$devicesService.getDevicesForPlatform(platform);
const architectures = _(instances)
.map(d => d.deviceInfo.activeArchitecture)
.filter(d => !!d)
.uniq()
.value();
return architectures;
}
}
$injector.register("xcodebuildArgsService", XcodebuildArgsService);