Skip to content

Commit c5b1129

Browse files
Pass buildConfig when getting path to last build output
Pass the whole buildConfig object when getting the path to the last build output. This required changes in debug services and TestExecutionService. Also change the args of cleanProject method - the `options` passed to `gradle` are now determined in the method itself instead of passing them from the caller. This way we'll not require "android-23" (the default one set in build.gradle) when we miss to pass the required options.
1 parent 957f603 commit c5b1129

19 files changed

+120
-112
lines changed

lib/commands/appstore-upload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class PublishIOS implements ICommand {
7373
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
7474
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
7575
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
76-
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice, isReleaseBuild: iOSBuildConfig.release }, this.$projectData);
76+
ipaFilePath = this.$platformService.lastOutputPath(platform, iOSBuildConfig, this.$projectData);
7777
} else {
7878
this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission.");
7979
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });

lib/commands/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class BuildCommandBase {
2626
};
2727
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
2828
if (this.$options.copyTo) {
29-
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice, isReleaseBuild: buildConfig.release }, this.$projectData);
29+
this.$platformService.copyLastOutput(platform, this.$options.copyTo, buildConfig, this.$projectData);
3030
}
3131
}
3232
}

lib/commands/debug.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
}
1717

1818
public async execute(args: string[]): Promise<void> {
19-
if (this.$options.start) {
20-
return this.debugService.debug(this.$projectData);
21-
}
22-
23-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
2419
const deployOptions: IDeployPlatformOptions = {
2520
clean: this.$options.clean,
2621
device: this.$options.device,
@@ -31,6 +26,15 @@
3126
provision: this.$options.provision,
3227
teamId: this.$options.teamId
3328
};
29+
30+
const buildConfig: IBuildConfig = _.merge({ buildForDevice: this.$options.forDevice }, deployOptions);
31+
32+
if (this.$options.start) {
33+
return this.debugService.debug(this.$projectData, buildConfig);
34+
}
35+
36+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
37+
3438
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
3539
this.$config.debugLivesync = true;
3640
let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
@@ -45,7 +49,7 @@
4549

4650
await deviceAppData.device.applicationManager.stopApplication(applicationId);
4751

48-
await this.debugService.debug(this.$projectData);
52+
await this.debugService.debug(this.$projectData, buildConfig);
4953
};
5054
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction);
5155
}

lib/common

lib/definitions/debug.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interface IDebugService {
2-
debug(projectData: IProjectData): Promise<void>;
3-
debugStart(projectData: IProjectData): Promise<void>;
2+
debug(projectData: IProjectData, buildConfig: IBuildConfig): Promise<void>;
3+
debugStart(projectData: IProjectData, buildConfig: IBuildConfig): Promise<void>;
44
debugStop(): Promise<void>
55
platform: string;
66
}

lib/definitions/platform.d.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interface IPlatformService extends NodeJS.EventEmitter {
22
cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, framework?: string): Promise<void>;
3-
3+
44
addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, frameworkPath?: string): Promise<void>;
55

66
/**
@@ -143,30 +143,37 @@ interface IPlatformService extends NodeJS.EventEmitter {
143143
/**
144144
* Returns information about the latest built application for device in the current project.
145145
* @param {IPlatformData} platformData Data describing the current platform.
146-
* @param {any} buildOptions Defines if the build is for release configuration.
146+
* @param {IBuildConfig} buildConfig Defines if the build is for release configuration.
147147
* @returns {IApplicationPackage} Information about latest built application.
148148
*/
149-
getLatestApplicationPackageForDevice(platformData: IPlatformData, buildOptions: { isReleaseBuild: boolean }): IApplicationPackage;
149+
getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig): IApplicationPackage;
150150

151151
/**
152152
* Returns information about the latest built application for simulator in the current project.
153153
* @param {IPlatformData} platformData Data describing the current platform.
154-
* @param {any} buildOptions Defines if the build is for release configuration.
154+
* @param {IBuildConfig} buildConfig Defines if the build is for release configuration.
155155
* @returns {IApplicationPackage} Information about latest built application.
156156
*/
157-
getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildOptions: { isReleaseBuild: boolean }): IApplicationPackage;
157+
getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig): IApplicationPackage;
158158

159159
/**
160160
* Copies latest build output to a specified location.
161161
* @param {string} platform Mobile platform - Android, iOS.
162162
* @param {string} targetPath Destination where the build artifact should be copied.
163-
* @param {{isForDevice: boolean, isReleaseBuild: boolean}} settings Defines if the searched artifact should be for simulator and is it built for release.
163+
* @param {IBuildConfig} buildConfig Defines if the searched artifact should be for simulator and is it built for release.
164164
* @param {IProjectData} projectData DTO with information about the project.
165165
* @returns {void}
166166
*/
167-
copyLastOutput(platform: string, targetPath: string, settings: { isForDevice: boolean, isReleaseBuild: boolean }, projectData: IProjectData): void;
167+
copyLastOutput(platform: string, targetPath: string, buildConfig: IBuildConfig, projectData: IProjectData): void;
168168

169-
lastOutputPath(platform: string, settings: { isForDevice: boolean, isReleaseBuild: boolean }, projectData: IProjectData): string;
169+
/**
170+
* Gets the latest build output.
171+
* @param {string} platform Mobile platform - Android, iOS.
172+
* @param {IBuildConfig} buildConfig Defines if the searched artifact should be for simulator and is it built for release.
173+
* @param {IProjectData} projectData DTO with information about the project.
174+
* @returns {string} The path to latest built artifact.
175+
*/
176+
lastOutputPath(platform: string, buildConfig: IBuildConfig, projectData: IProjectData): string;
170177

171178
/**
172179
* Reads contents of a file on device.

lib/definitions/project.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,10 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
254254
/**
255255
* Removes build artifacts specific to the platform
256256
* @param {string} projectRoot The root directory of the native project.
257-
* @param {string[]} options Options that can be passed to clean command.
258257
* @param {IProjectData} projectData DTO with information about the project.
259258
* @returns {void}
260259
*/
261-
cleanProject(projectRoot: string, options: string[], projectData: IProjectData): Promise<void>
260+
cleanProject(projectRoot: string, projectData: IProjectData): Promise<void>
262261
}
263262

264263
interface IAndroidProjectPropertiesManager {

lib/project-data.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class ProjectData implements IProjectData {
4242
private $errors: IErrors,
4343
private $projectHelper: IProjectHelper,
4444
private $staticConfig: IStaticConfig,
45-
private $options: IOptions) { }
45+
private $options: IOptions,
46+
private $logger: ILogger) { }
4647

4748
public initializeProjectData(projectDir?: string): void {
4849
projectDir = projectDir || this.$projectHelper.projectDir;
@@ -51,15 +52,14 @@ export class ProjectData implements IProjectData {
5152
const projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
5253
let data: any = null;
5354

54-
if (projectFilePath) {
55+
if (this.$fs.exists(projectFilePath)) {
5556
let fileContent: any = null;
5657
try {
5758
fileContent = this.$fs.readJson(projectFilePath);
5859
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
5960
} catch (err) {
60-
this.$errors.failWithoutHelp(
61-
`The project file ${this.projectFilePath} is corrupted.` + EOL +
62-
"Consider restoring an earlier version from your source control or backup." + EOL +
61+
this.$errors.failWithoutHelp(`The project file ${this.projectFilePath} is corrupted. ${EOL}` +
62+
`Consider restoring an earlier version from your source control or backup.${EOL}` +
6363
`Additional technical info: ${err.toString()}`);
6464
}
6565

@@ -80,8 +80,11 @@ export class ProjectData implements IProjectData {
8080
}
8181
}
8282

83+
const currentDir = path.resolve(".");
84+
this.$logger.trace(`Unable to find project. projectDir: ${projectDir}, options.path: ${this.$options.path}, ${currentDir}`);
85+
8386
// This is the case when no project file found
84-
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", projectDir || this.$options.path || path.resolve("."));
87+
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", projectDir || this.$options.path || currentDir);
8588
}
8689

8790
private getProjectType(): string {

lib/providers/livesync-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export class LiveSyncProvider implements ILiveSyncProvider {
4545
await this.$platformService.buildPlatform(device.deviceInfo.platform, buildConfig, projectData);
4646
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
4747
if (device.isEmulator) {
48-
return this.$platformService.getLatestApplicationPackageForEmulator(platformData, { isReleaseBuild: buildConfig.release }).packageName;
48+
return this.$platformService.getLatestApplicationPackageForEmulator(platformData, buildConfig).packageName;
4949
}
5050

51-
return this.$platformService.getLatestApplicationPackageForDevice(platformData, { isReleaseBuild: buildConfig.release }).packageName;
51+
return this.$platformService.getLatestApplicationPackageForDevice(platformData, buildConfig).packageName;
5252
}
5353

5454
public async preparePlatformForSync(platform: string, provision: any, projectData: IProjectData): Promise<void> {

lib/services/android-debug-service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ class AndroidDebugService implements IDebugService {
2828
this._device = newDevice;
2929
}
3030

31-
public async debug(projectData: IProjectData): Promise<void> {
31+
public async debug(projectData: IProjectData, buildConfig: IBuildConfig): Promise<void> {
3232
return this.$options.emulator
33-
? this.debugOnEmulator(projectData)
34-
: this.debugOnDevice(projectData);
33+
? this.debugOnEmulator(projectData, buildConfig)
34+
: this.debugOnDevice(projectData, buildConfig);
3535
}
3636

37-
private async debugOnEmulator(projectData: IProjectData): Promise<void> {
37+
private async debugOnEmulator(projectData: IProjectData, buildConfig: IBuildConfig): Promise<void> {
3838
// Assure we've detected the emulator as device
3939
// For example in case deployOnEmulator had stated new emulator instance
4040
// we need some time to detect it. Let's force detection.
4141
await this.$androidDeviceDiscovery.startLookingForDevices();
42-
await this.debugOnDevice(projectData);
42+
await this.debugOnDevice(projectData, buildConfig);
4343
}
4444

4545
private isPortAvailable(candidatePort: number): Promise<boolean> {
@@ -108,7 +108,7 @@ class AndroidDebugService implements IDebugService {
108108
return this.device.adb.executeCommand(["forward", `tcp:${local}`, `localabstract:${remote}`]);
109109
}
110110

111-
private async debugOnDevice(projectData: IProjectData): Promise<void> {
111+
private async debugOnDevice(projectData: IProjectData, buildConfig: IBuildConfig): Promise<void> {
112112
let packageFile = "";
113113

114114
if (!this.$options.start && !this.$options.emulator) {
@@ -117,7 +117,7 @@ class AndroidDebugService implements IDebugService {
117117
this.$options.forDevice = !!cachedDeviceOption;
118118

119119
let platformData = this.$platformsData.getPlatformData(this.platform, projectData);
120-
packageFile = this.$platformService.getLatestApplicationPackageForDevice(platformData, { isReleaseBuild: this.$options.release }).packageName;
120+
packageFile = this.$platformService.getLatestApplicationPackageForDevice(platformData, buildConfig).packageName;
121121
this.$logger.out("Using ", packageFile);
122122
}
123123

@@ -170,7 +170,7 @@ class AndroidDebugService implements IDebugService {
170170
await this.debugStartCore(packageName);
171171
}
172172

173-
public async debugStart(projectData: IProjectData): Promise<void> {
173+
public async debugStart(projectData: IProjectData, buildConfig: IBuildConfig): Promise<void> {
174174
await this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device });
175175
let action = (device: Mobile.IAndroidDevice): Promise<void> => {
176176
this.device = device;

lib/services/android-project-service.ts

+10-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as semver from "semver";
55
import * as projectServiceBaseLib from "./platform-project-service-base";
66
import { DeviceAndroidDebugBridge } from "../common/mobile/android/device-android-debug-bridge";
77
import { EOL } from "os";
8+
import { Configurations } from "../common/constants";
89

910
export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
1011
private static VALUES_DIRNAME = "values";
@@ -58,16 +59,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
5859
projectRoot: projectRoot,
5960
deviceBuildOutputPath: path.join(projectRoot, "build", "outputs", "apk"),
6061
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
61-
if (buildOptions.isReleaseBuild) {
62-
return [
63-
`${packageName}-release.apk`,
64-
`${projectData.projectName}-release.apk`
65-
];
66-
}
62+
const buildMode = buildOptions.isReleaseBuild ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase();
6763

6864
return [
69-
`${packageName}-debug.apk`,
70-
`${projectData.projectName}-debug.apk`,
65+
`${packageName}-${buildMode}.apk`,
66+
`${projectData.projectName}-${buildMode}.apk`
7167
];
7268
},
7369
frameworkFilesExtensions: [".jar", ".dat", ".so"],
@@ -383,7 +379,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
383379
// check whether the dependency that's being removed has native code
384380
let pluginConfigDir = path.join(this.getPlatformData(projectData).projectRoot, "configurations", pluginData.name);
385381
if (this.$fs.exists(pluginConfigDir)) {
386-
await this.cleanProject(this.getPlatformData(projectData).projectRoot, [], projectData);
382+
await this.cleanProject(this.getPlatformData(projectData).projectRoot, projectData);
387383
}
388384
} catch (e) {
389385
if (e.code === "ENOENT") {
@@ -414,12 +410,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
414410
}
415411
}
416412

417-
// We don't need release options here
418-
let buildOptions = this.getBuildOptions({ release: false }, projectData);
419-
420413
let projectRoot = this.getPlatformData(projectData).projectRoot;
421414

422-
await this.cleanProject(projectRoot, buildOptions, projectData);
415+
await this.cleanProject(projectRoot, projectData);
423416
}
424417
}
425418

@@ -432,19 +425,16 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
432425
return this.$childProcess.spawnFromEvent(gradleBin, ["--stop", "--quiet"], "close", { stdio: "inherit", cwd: projectRoot });
433426
}
434427

435-
public async cleanProject(projectRoot: string, options: string[], projectData: IProjectData): Promise<void> {
436-
// In case options are not passed, we'll use the default ones for cleaning the project.
437-
// In case we do not do this, we'll required android-23 (default in build.gradle) for cleaning the project.
438-
options = options.length === 0 ? this.getBuildOptions({ release: false }, projectData) : options;
439-
440-
options.unshift("clean");
428+
public async cleanProject(projectRoot: string, projectData: IProjectData): Promise<void> {
429+
const buildOptions = this.getBuildOptions({ release: false }, projectData);
430+
buildOptions.unshift("clean");
441431

442432
let gradleBin = path.join(projectRoot, "gradlew");
443433
if (this.$hostInfo.isWindows) {
444434
gradleBin += ".bat";
445435
}
446436

447-
await this.spawn(gradleBin, options, { stdio: "inherit", cwd: this.getPlatformData(projectData).projectRoot });
437+
await this.spawn(gradleBin, buildOptions, { stdio: "inherit", cwd: this.getPlatformData(projectData).projectRoot });
448438
}
449439

450440
public async cleanDeviceTempFolder(deviceIdentifier: string, projectData: IProjectData): Promise<void> {

0 commit comments

Comments
 (0)