Skip to content

fix: find correct apk name when --release passed #3419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
* @param {string} @optional outputPath Directory containing build information and artifacts.
* @returns {Promise<boolean>} true indicates that the application should be installed.
*/
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean>;
shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IRelease, outputPath?: string): Promise<boolean>;

/**
* Determines whether the project should undergo the prepare process.
Expand Down Expand Up @@ -260,7 +260,7 @@ interface IPlatformData {
projectRoot: string;
normalizedPlatformName: string;
appDestinationDirectoryPath: string;
deviceBuildOutputPath: string;
getDeviceBuildOutputPath(options: IRelease): string;
emulatorBuildOutputPath?: string;
getValidPackageNames(buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[];
frameworkFilesExtensions: string[];
Expand Down
4 changes: 4 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ interface IBuildForDevice {
buildForDevice: boolean;
}

interface IShouldInstall extends IBuildForDevice, IRelease {

}

interface INativePrepare {
skipNativePrepare: boolean;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
platformProjectService: this,
emulatorServices: this.$androidEmulatorServices,
projectRoot: projectRoot,
deviceBuildOutputPath: this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData),
getDeviceBuildOutputPath: (options: IRelease): string => {
return this.getDeviceBuildOutputPath(path.join(...deviceBuildOutputArr), projectData, options);
},
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
const buildMode = buildOptions.isReleaseBuild ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase();

Expand All @@ -106,10 +108,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
return this._platformData;
}

private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData): string {
private getDeviceBuildOutputPath(currentPath: string, projectData: IProjectData, options: IRelease): string {
const currentPlatformData: IDictionary<any> = this.$projectDataService.getNSValue(projectData.projectDir, constants.TNS_ANDROID_RUNTIME_NAME);
const platformVersion = currentPlatformData && currentPlatformData[constants.VERSION_STRING];
const normalizedPath = path.join(currentPath, "debug");
const buildType = options.release === true ? "release" : "debug";
const normalizedPath = path.join(currentPath, buildType);

if (semver.valid(platformVersion)) {
const gradleAndroidPluginVersion3xx = "4.0.0";
Expand Down
4 changes: 3 additions & 1 deletion lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
platformProjectService: this,
emulatorServices: this.$iOSEmulatorServices,
projectRoot: projectRoot,
deviceBuildOutputPath: path.join(projectRoot, "build", "device"),
getDeviceBuildOutputPath: (options: IRelease): string => {
return path.join(projectRoot, "build", "device");
},
emulatorBuildOutputPath: path.join(projectRoot, "build", "emulator"),
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
if (buildOptions.isForDevice) {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi

await this.trackAction(action, platform, options);

const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options.deviceBuildInfoDescriptor.outputPath);
const shouldInstall = await this.$platformService.shouldInstall(options.device, options.projectData, options, options.deviceBuildInfoDescriptor.outputPath);
if (shouldInstall) {
await this.$platformService.installApplication(options.device, { release: false }, options.projectData, pathToBuildItem, options.deviceBuildInfoDescriptor.outputPath);
appInstalledOnDeviceResult.appInstalled = true;
Expand Down
26 changes: 14 additions & 12 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {

const platformData = this.$platformsData.getPlatformData(platform, projectData);
const forDevice = !buildConfig || buildConfig.buildForDevice;
outputPath = outputPath || (forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath);
outputPath = outputPath || (forDevice ? platformData.getDeviceBuildOutputPath(buildConfig) : platformData.emulatorBuildOutputPath || platformData.getDeviceBuildOutputPath(buildConfig));
if (!this.$fs.exists(outputPath)) {
return true;
}
Expand Down Expand Up @@ -433,15 +433,15 @@ export class PlatformService extends EventEmitter implements IPlatformService {
this.$fs.writeJson(buildInfoFile, buildInfo);
}

public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean> {
public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, release: IBuildConfig, outputPath?: string): Promise<boolean> {
const platform = device.deviceInfo.platform;
if (!(await device.applicationManager.isApplicationInstalled(projectData.projectId))) {
return true;
}

const platformData = this.$platformsData.getPlatformData(platform, projectData);
const deviceBuildInfo: IBuildInfo = await this.getDeviceBuildInfo(device, projectData);
const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator }, outputPath);
const localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator, release: release.release }, outputPath);
return !localBuildInfo || !deviceBuildInfo || deviceBuildInfo.buildTime !== localBuildInfo.buildTime;
}

Expand Down Expand Up @@ -469,7 +469,9 @@ export class PlatformService extends EventEmitter implements IPlatformService {

if (!buildConfig.release) {
const deviceFilePath = await this.getDeviceBuildInfoFilePath(device, projectData);
const buildInfoFilePath = outputFilePath || this.getBuildOutputPath(device.deviceInfo.platform, platformData, { buildForDevice: !device.isEmulator });
const options = buildConfig;
options.buildForDevice = !device.isEmulator;
const buildInfoFilePath = outputFilePath || this.getBuildOutputPath(device.deviceInfo.platform, platformData, options);
const appIdentifier = projectData.projectId;

await device.fileSystem.putFile(path.join(buildInfoFilePath, buildInfoFileName), deviceFilePath, appIdentifier);
Expand Down Expand Up @@ -515,8 +517,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
this.$logger.out("Skipping package build. No changes detected on the native side. This will be fast!");
}

if (deployInfo.deployOptions.forceInstall || shouldBuild || (await this.shouldInstall(device, deployInfo.projectData))) {
await this.installApplication(device, buildConfig, deployInfo.projectData, installPackageFile, deployInfo.outputPath);
if (deployInfo.deployOptions.forceInstall || shouldBuild || (await this.shouldInstall(device, deployInfo.projectData, buildConfig))) {
await this.installApplication(device, buildConfig, deployInfo.projectData);
} else {
this.$logger.out("Skipping install.");
}
Expand Down Expand Up @@ -550,12 +552,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
await this.$devicesService.execute(action, this.getCanExecuteAction(platform, runOptions));
}

private getBuildOutputPath(platform: string, platformData: IPlatformData, options: IBuildForDevice): string {
private getBuildOutputPath(platform: string, platformData: IPlatformData, options: IShouldInstall): string {
if (platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
return options.buildForDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath;
return options.buildForDevice ? platformData.getDeviceBuildOutputPath(options) : platformData.emulatorBuildOutputPath;
}

return platformData.deviceBuildOutputPath;
return platformData.getDeviceBuildOutputPath(options);
}

private async getDeviceBuildInfoFilePath(device: Mobile.IDevice, projectData: IProjectData): Promise<string> {
Expand All @@ -575,7 +577,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}
}

private getBuildInfo(platform: string, platformData: IPlatformData, options: IBuildForDevice, buildOutputPath?: string): IBuildInfo {
private getBuildInfo(platform: string, platformData: IPlatformData, options: IShouldInstall, buildOutputPath?: string): IBuildInfo {
buildOutputPath = buildOutputPath || this.getBuildOutputPath(platform, platformData, options);
const buildInfoFile = path.join(buildOutputPath, buildInfoFileName);
if (this.$fs.exists(buildInfoFile)) {
Expand Down Expand Up @@ -765,11 +767,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}

public getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
return this.getLatestApplicationPackage(outputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release }));
return this.getLatestApplicationPackage(outputPath || platformData.getDeviceBuildOutputPath(buildConfig), platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release }));
}

public getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release }));
return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.getDeviceBuildOutputPath(buildConfig), platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release }));
}

private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class PlatformData implements IPlatformData {
};
emulatorServices: Mobile.IEmulatorPlatformServices = null;
projectRoot = "";
deviceBuildOutputPath = "";
getDeviceBuildOutputPath = (buildTypeOption: IRelease) => {
return "";
}
getValidPackageNames = (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [""];
validPackageNamesForDevice: string[] = [];
frameworkFilesExtensions = [".jar", ".dat"];
Expand Down
8 changes: 6 additions & 2 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
platformProjectService: this,
emulatorServices: undefined,
projectRoot: "",
deviceBuildOutputPath: "",
getDeviceBuildOutputPath: (buildTypeOption: IRelease) => {
return "";
},
getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [],
frameworkFilesExtensions: [],
appDestinationDirectoryPath: "",
Expand Down Expand Up @@ -415,7 +417,9 @@ export class PlatformsDataStub extends EventEmitter implements IPlatformsData {
projectRoot: "",
normalizedPlatformName: "",
appDestinationDirectoryPath: "",
deviceBuildOutputPath: "",
getDeviceBuildOutputPath: (buildTypeOption: IRelease) => {
return "";
},
getValidPackageNames: (buildOptions: { isForDevice?: boolean, isReleaseBuild?: boolean }) => [],
frameworkFilesExtensions: [],
relativeToFrameworkConfigurationFilePath: "",
Expand Down