Skip to content

Commit db59990

Browse files
committed
fix(build-ios): Use BUILD_DIR instead of CONFIGURATION_BUILD_DIR
Passing `CONFIGURATION_BUILD_DIR` to `xcodebuild` causes the build errors with projects having `nativescript-plugin-firebase` when using Xcode 10's new build system similar to the following: ``` Build system information error: Multiple commands produce '<PbxCp <project-path>/platforms/ios/build/src/core/ext/filters/client_channel/backup_poller.h>': 1) Target 'gRPC-Core' (project 'Pods') has copy command from '<project-path>/platforms/ios/Pods/gRPC-Core/src/core/ext/filters/client_channel/backup_poller.h' to '<project-path>/platforms/ios/build/src/core/ext/filters/client_channel/backup_poller.h' 2) Target 'gRPC-C++' (project 'Pods') has copy command from '<project-path>/platforms/ios/Pods/gRPC-C++/src/core/ext/filters/client_channel/backup_poller.h' to '<project-path>/platforms/ios/build/src/core/ext/filters/client_channel/backup_poller.h' ```
1 parent 7d97c85 commit db59990

File tree

8 files changed

+37
-28
lines changed

8 files changed

+37
-28
lines changed

lib/definitions/platform.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
8484
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IRelease, outputPath?: string): Promise<boolean>;
8585

8686
/**
87-
*
87+
*
8888
* @param {Mobile.IDevice} device The device where the application should be installed.
8989
* @param {IProjectData} projectData DTO with information about the project.
9090
* @param {string} @optional outputPath Directory containing build information and artifacts.
@@ -259,9 +259,8 @@ interface IPlatformData {
259259
projectRoot: string;
260260
normalizedPlatformName: string;
261261
appDestinationDirectoryPath: string;
262-
deviceBuildOutputPath: string;
262+
getBuildOutputPath(options: IBuildOutputOptions): string;
263263
bundleBuildOutputPath?: string;
264-
emulatorBuildOutputPath?: string;
265264
getValidBuildOutputData(buildOptions: IBuildOutputOptions): IValidBuildOutputData;
266265
frameworkFilesExtensions: string[];
267266
frameworkDirectoriesExtensions?: string[];
@@ -315,7 +314,7 @@ interface INodeModulesDependenciesBuilder {
315314
interface IBuildInfo {
316315
prepareTime: string;
317316
buildTime: string;
318-
/**
317+
/**
319318
* Currently it is used only for iOS.
320319
* As `xcrun` command does not throw an error when IPHONEOS_DEPLOYMENT_TARGET is provided in `xcconfig` file and
321320
* the simulator's version does not match IPHONEOS_DEPLOYMENT_TARGET's value, we need to save it to buildInfo file

lib/services/android-project-service.ts

Lines changed: 2 additions & 2 deletions
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

Lines changed: 18 additions & 9 deletions
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) {
@@ -209,7 +218,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
209218
const projectRoot = this.getPlatformData(projectData).projectRoot;
210219
const archivePath = options && options.archivePath ? path.resolve(options.archivePath) : path.join(projectRoot, "/build/archive/", projectData.projectName + ".xcarchive");
211220
let args = ["archive", "-archivePath", archivePath, "-configuration",
212-
(!buildConfig || buildConfig.release) ? "Release" : "Debug"]
221+
getConfigurationName(!buildConfig || buildConfig.release)]
213222
.concat(this.xcbuildProjectArgs(projectRoot, projectData, "scheme"));
214223

215224
if (options && options.additionalArgs) {
@@ -282,7 +291,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
282291
const platformData = this.getPlatformData(projectData);
283292
const projectRoot = platformData.projectRoot;
284293
const archivePath = options.archivePath;
285-
const buildOutputPath = path.join(projectRoot, "build", "device");
294+
const buildOutputPath = path.join(projectRoot, "build");
286295
const exportOptionsMethod = await this.getExportOptionsMethod(projectData);
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">
@@ -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, "build")
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, "build"),
581590
"CODE_SIGN_IDENTITY=",
582591
])
583592
.concat(this.xcbuildProjectArgs(projectRoot, projectData));

lib/services/platform-service.ts

Lines changed: 7 additions & 8 deletions
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/platform-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PlatformData implements IPlatformData {
3939
}
4040
};
4141
projectRoot = "";
42-
deviceBuildOutputPath = "";
42+
getBuildOutputPath = () => "";
4343
getValidBuildOutputData = (buildOptions: IBuildOutputOptions) => ({ packageNames: [""] });
4444
validPackageNamesForDevice: string[] = [];
4545
frameworkFilesExtensions = [".jar", ".dat"];

test/platform-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe('Platform Service Tests', () => {
264264
projectRoot: "",
265265
normalizedPlatformName: "",
266266
appDestinationDirectoryPath: "",
267-
deviceBuildOutputPath: "",
267+
getBuildOutputPath: () => "",
268268
getValidBuildOutputData: (buildOptions: IBuildOutputOptions) => ({ packageNames: [] }),
269269
frameworkFilesExtensions: [],
270270
relativeToFrameworkConfigurationFilePath: "",
@@ -981,6 +981,7 @@ describe('Platform Service Tests', () => {
981981
return {
982982
deviceBuildOutputPath: "",
983983
normalizedPlatformName: "",
984+
getBuildOutputPath: () => "",
984985
platformProjectService: {
985986
buildProject: () => Promise.resolve(),
986987
on: () => ({}),

test/services/android-project-service.ts

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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)