Skip to content

Commit a2285cf

Browse files
author
Fatme
authored
Merge pull request #4310 from NativeScript/bektchiev/fix-ios-build-with-firebase
fix(build-ios): Use BUILD_DIR instead of CONFIGURATION_BUILD_DIR
2 parents fd68fbc + e0e2557 commit a2285cf

9 files changed

+43
-34
lines changed

lib/definitions/platform.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ interface IPlatformData {
239239
projectRoot: string;
240240
normalizedPlatformName: string;
241241
appDestinationDirectoryPath: string;
242-
deviceBuildOutputPath: string;
242+
getBuildOutputPath(options: IBuildOutputOptions): string;
243243
bundleBuildOutputPath?: string;
244-
emulatorBuildOutputPath?: string;
245244
getValidBuildOutputData(buildOptions: IBuildOutputOptions): IValidBuildOutputData;
246245
frameworkFilesExtensions: string[];
247246
frameworkDirectoriesExtensions?: string[];

lib/services/android-project-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
7474
appDestinationDirectoryPath: path.join(...appDestinationDirectoryArr),
7575
platformProjectService: this,
7676
projectRoot: projectRoot,
77-
deviceBuildOutputPath: path.join(...deviceBuildOutputArr),
77+
getBuildOutputPath: () => path.join(...deviceBuildOutputArr),
7878
bundleBuildOutputPath: path.join(projectRoot, constants.APP_FOLDER_NAME, constants.BUILD_DIR, constants.OUTPUTS_DIR, constants.BUNDLE_DIR),
7979
getValidBuildOutputData: (buildOptions: IBuildOutputOptions): IValidBuildOutputData => {
8080
const buildMode = buildOptions.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase();
@@ -332,7 +332,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
332332
const gradleArgs = this.getGradleBuildOptions(buildConfig, projectData);
333333
const baseTask = buildConfig.androidBundle ? "bundle" : "assemble";
334334
const platformData = this.getPlatformData(projectData);
335-
const outputPath = buildConfig.androidBundle ? platformData.bundleBuildOutputPath : platformData.deviceBuildOutputPath;
335+
const outputPath = buildConfig.androidBundle ? platformData.bundleBuildOutputPath : platformData.getBuildOutputPath(buildConfig);
336336
if (this.$logger.getLevel() === "TRACE") {
337337
gradleArgs.unshift("--stacktrace");
338338
gradleArgs.unshift("--debug");

lib/services/ios-project-service.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from "path";
22
import * as shell from "shelljs";
33
import * as semver from "semver";
44
import * as constants from "../constants";
5+
import { Configurations } from "../common/constants";
56
import * as helpers from "../common/helpers";
67
import { attachAwaitDetach } from "../common/helpers";
78
import * as projectServiceBaseLib from "./platform-project-service-base";
@@ -21,6 +22,12 @@ interface INativeSourceCodeGroup {
2122
files: string[];
2223
}
2324

25+
const DevicePlatformSdkName = "iphoneos";
26+
const SimulatorPlatformSdkName = "iphonesimulator";
27+
28+
const getPlatformSdkName = (forDevice: boolean): string => forDevice ? DevicePlatformSdkName : SimulatorPlatformSdkName;
29+
const getConfigurationName = (release: boolean): string => release ? Configurations.Release : Configurations.Debug;
30+
2431
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
2532
private static XCODEBUILD_MIN_VERSION = "6.0";
2633
private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__";
@@ -67,8 +74,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
6774
appDestinationDirectoryPath: path.join(projectRoot, projectData.projectName),
6875
platformProjectService: this,
6976
projectRoot: projectRoot,
70-
deviceBuildOutputPath: path.join(projectRoot, constants.BUILD_DIR, "device"),
71-
emulatorBuildOutputPath: path.join(projectRoot, constants.BUILD_DIR, "emulator"),
77+
getBuildOutputPath: (options : IBuildOutputOptions): string => {
78+
const config = getConfigurationName(!options || options.release);
79+
return path.join(projectRoot, constants.BUILD_DIR, `${config}-${getPlatformSdkName(!options || options.buildForDevice)}`);
80+
},
7281
getValidBuildOutputData: (buildOptions: IBuildOutputOptions): IValidBuildOutputData => {
7382
const forDevice = !buildOptions || !!buildOptions.buildForDevice;
7483
if (forDevice) {
@@ -206,10 +215,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
206215
* Returns the path to the .xcarchive.
207216
*/
208217
public async archive(projectData: IProjectData, buildConfig?: IBuildConfig, options?: { archivePath?: string, additionalArgs?: string[] }): Promise<string> {
218+
const platformData = this.getPlatformData(projectData);
209219
const projectRoot = this.getPlatformData(projectData).projectRoot;
210-
const archivePath = options && options.archivePath ? path.resolve(options.archivePath) : path.join(projectRoot, "/build/archive/", projectData.projectName + ".xcarchive");
220+
const archivePath = options && options.archivePath ? path.resolve(options.archivePath) : path.join(platformData.getBuildOutputPath(buildConfig), projectData.projectName + ".xcarchive");
211221
let args = ["archive", "-archivePath", archivePath, "-configuration",
212-
(!buildConfig || buildConfig.release) ? "Release" : "Debug"]
222+
getConfigurationName(!buildConfig || buildConfig.release)]
213223
.concat(this.xcbuildProjectArgs(projectRoot, projectData, "scheme"));
214224

215225
if (options && options.additionalArgs) {
@@ -278,12 +288,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
278288
/**
279289
* Exports .xcarchive for a development device.
280290
*/
281-
private async exportDevelopmentArchive(projectData: IProjectData, buildConfig: IBuildConfig, options: { archivePath: string, exportDir?: string, teamID?: string, provision?: string }): Promise<string> {
291+
private async exportDevelopmentArchive(projectData: IProjectData, buildConfig: IBuildConfig, options: { archivePath: string, provision?: string }): Promise<string> {
282292
const platformData = this.getPlatformData(projectData);
283293
const projectRoot = platformData.projectRoot;
284294
const archivePath = options.archivePath;
285-
const buildOutputPath = path.join(projectRoot, "build", "device");
286-
const exportOptionsMethod = await this.getExportOptionsMethod(projectData);
295+
const exportOptionsMethod = await this.getExportOptionsMethod(projectData, archivePath);
287296
let plistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
288297
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
289298
<plist version="1.0">
@@ -311,7 +320,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
311320
this.$fs.writeFile(exportOptionsPlist, plistTemplate);
312321

313322
// The xcodebuild exportPath expects directory and writes the <project-name>.ipa at that directory.
314-
const exportPath = path.resolve(options.exportDir || buildOutputPath);
323+
const exportPath = path.resolve(path.dirname(archivePath));
315324
const exportFile = path.join(exportPath, projectData.projectName + ".ipa");
316325

317326
await this.xcodebuild(
@@ -407,8 +416,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
407416
args = args.concat((buildConfig && buildConfig.architectures) || this.getBuildArchitectures(projectData, buildConfig, ["armv7", "arm64"]));
408417

409418
args = args.concat([
410-
"-sdk", "iphoneos",
411-
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device")
419+
"-sdk", DevicePlatformSdkName,
420+
"BUILD_DIR=" + path.join(projectRoot, constants.BUILD_DIR)
412421
]);
413422

414423
const xcodeBuildVersion = await this.getXcodeVersion();
@@ -574,10 +583,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
574583
.concat(architectures)
575584
.concat([
576585
"build",
577-
"-configuration", buildConfig.release ? "Release" : "Debug",
578-
"-sdk", "iphonesimulator",
586+
"-configuration", getConfigurationName(buildConfig.release),
587+
"-sdk", SimulatorPlatformSdkName,
579588
"ONLY_ACTIVE_ARCH=NO",
580-
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"),
589+
"BUILD_DIR=" + path.join(projectRoot, constants.BUILD_DIR),
581590
"CODE_SIGN_IDENTITY=",
582591
])
583592
.concat(this.xcbuildProjectArgs(projectRoot, projectData));
@@ -1390,8 +1399,8 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
13901399
}
13911400
}
13921401

1393-
private getExportOptionsMethod(projectData: IProjectData): string {
1394-
const embeddedMobileProvisionPath = path.join(this.getPlatformData(projectData).projectRoot, "build", "archive", `${projectData.projectName}.xcarchive`, 'Products', 'Applications', `${projectData.projectName}.app`, "embedded.mobileprovision");
1402+
private getExportOptionsMethod(projectData: IProjectData, archivePath: string): string {
1403+
const embeddedMobileProvisionPath = path.join(archivePath, 'Products', 'Applications', `${projectData.projectName}.app`, "embedded.mobileprovision");
13951404
const provision = mobileprovision.provision.readFromFile(embeddedMobileProvisionPath);
13961405

13971406
return {

lib/services/platform-service.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
376376
}
377377

378378
const platformData = this.$platformsData.getPlatformData(platform, projectData);
379-
const forDevice = !buildConfig || !!buildConfig.buildForDevice;
380-
outputPath = outputPath || (forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath);
379+
outputPath = outputPath || platformData.getBuildOutputPath(buildConfig);
381380
if (!this.$fs.exists(outputPath)) {
382381
return true;
383382
}
@@ -533,7 +532,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
533532
}
534533

535534
let hashes = {};
536-
const hashesFilePath = path.join(outputFilePath || platformData.deviceBuildOutputPath, constants.HASHES_FILE_NAME);
535+
const hashesFilePath = path.join(outputFilePath || platformData.getBuildOutputPath(null), constants.HASHES_FILE_NAME);
537536
if (this.$fs.exists(hashesFilePath)) {
538537
hashes = this.$fs.readJson(hashesFilePath);
539538
}
@@ -618,10 +617,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
618617
}
619618

620619
if (platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
621-
return options.buildForDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
620+
return platformData.getBuildOutputPath(options);
622621
}
623622

624-
return platformData.deviceBuildOutputPath;
623+
return platformData.getBuildOutputPath(options);
625624
}
626625

627626
private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
@@ -904,13 +903,13 @@ export class PlatformService extends EventEmitter implements IPlatformService {
904903
}
905904

906905
public getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
907-
return this.getLatestApplicationPackage(outputPath || platformData.deviceBuildOutputPath, platformData.getValidBuildOutputData({ buildForDevice: true, release: buildConfig.release, androidBundle: buildConfig.androidBundle }));
906+
return this.getLatestApplicationPackage(outputPath || platformData.getBuildOutputPath(buildConfig), platformData.getValidBuildOutputData({ buildForDevice: true, release: buildConfig.release, androidBundle: buildConfig.androidBundle }));
908907
}
909908

910909
public getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
910+
outputPath = outputPath || this.getBuildOutputPath(platformData.normalizedPlatformName.toLowerCase(), platformData, buildConfig);
911911
const buildOutputOptions: IBuildOutputOptions = { buildForDevice: false, release: buildConfig.release, androidBundle: buildConfig.androidBundle };
912-
outputPath = outputPath || this.getBuildOutputPath(platformData.normalizedPlatformName.toLowerCase(), platformData, buildOutputOptions);
913-
return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidBuildOutputData(buildOutputOptions));
912+
return this.getLatestApplicationPackage(outputPath || platformData.getBuildOutputPath(buildConfig), platformData.getValidBuildOutputData(buildOutputOptions));
914913
}
915914

916915
private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise<void> {

test/ios-project-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ describe("iOSProjectService", () => {
201201
if (hasCustomArchivePath) {
202202
archivePath = path.resolve(options.archivePath);
203203
} else {
204-
archivePath = path.join(projectPath, "platforms", "ios", "build", "archive", projectName + ".xcarchive");
204+
archivePath = path.join(projectPath, "platforms", "ios", "build", "Release-iphoneos", projectName + ".xcarchive");
205205
}
206206

207207
assert.ok(args.indexOf("archive") >= 0, "Expected xcodebuild to be executed with archive param.");
208208

209-
expectOption(args, "-archivePath", archivePath, hasCustomArchivePath ? "Wrong path passed to xcarchive" : "Default xcarchive path is wrong.");
209+
expectOption(args, "-archivePath", archivePath, hasCustomArchivePath ? "Wrong path passed to xcarchive" : "exports xcodearchive to platforms/ios/build/archive.");
210210
expectOption(args, "-project", path.join(projectPath, "platforms", "ios", projectName + ".xcodeproj"), "Path to Xcode project is wrong.");
211211
expectOption(args, "-scheme", projectName, "The provided scheme is wrong.");
212212

test/platform-commands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PlatformData implements IPlatformData {
3737
}
3838
};
3939
projectRoot = "";
40-
deviceBuildOutputPath = "";
40+
getBuildOutputPath = () => "";
4141
getValidBuildOutputData = (buildOptions: IBuildOutputOptions) => ({ packageNames: [""] });
4242
validPackageNamesForDevice: string[] = [];
4343
frameworkFilesExtensions = [".jar", ".dat"];

test/platform-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ describe('Platform Service Tests', () => {
259259
projectRoot: "",
260260
normalizedPlatformName: "",
261261
appDestinationDirectoryPath: "",
262-
deviceBuildOutputPath: "",
262+
getBuildOutputPath: () => "",
263263
getValidBuildOutputData: (buildOptions: IBuildOutputOptions) => ({ packageNames: [] }),
264264
frameworkFilesExtensions: [],
265265
relativeToFrameworkConfigurationFilePath: "",
@@ -976,6 +976,7 @@ describe('Platform Service Tests', () => {
976976
return {
977977
deviceBuildOutputPath: "",
978978
normalizedPlatformName: "",
979+
getBuildOutputPath: () => "",
979980
platformProjectService: {
980981
buildProject: () => Promise.resolve(),
981982
on: () => ({}),

test/services/android-project-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ describe("androidDeviceDebugService", () => {
7676
const getPlatformDataStub: sinon.SinonStub = sandbox.stub(androidProjectService, "getPlatformData");
7777
getPlatformDataStub.callsFake(() => {
7878
return {
79-
configurationFilePath: ""
79+
configurationFilePath: "",
80+
getBuildOutputPath: () => ""
8081
};
8182
});
8283
});

test/stubs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
379379
normalizedPlatformName: "",
380380
platformProjectService: this,
381381
projectRoot: "",
382-
deviceBuildOutputPath: "",
382+
getBuildOutputPath: () => "",
383383
getValidBuildOutputData: (buildOptions: IBuildOutputOptions) => ({ packageNames: [] }),
384384
frameworkFilesExtensions: [],
385385
appDestinationDirectoryPath: "",
@@ -490,7 +490,7 @@ export class PlatformsDataStub extends EventEmitter implements IPlatformsData {
490490
projectRoot: "",
491491
normalizedPlatformName: "",
492492
appDestinationDirectoryPath: "",
493-
deviceBuildOutputPath: "",
493+
getBuildOutputPath: () => "",
494494
getValidBuildOutputData: (buildOptions: IBuildOutputOptions) => ({ packageNames: [] }),
495495
frameworkFilesExtensions: [],
496496
relativeToFrameworkConfigurationFilePath: "",

0 commit comments

Comments
 (0)