Skip to content

Commit 4aafecc

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
Fix multiple rebuilds for the same platform
1 parent b3b7df8 commit 4aafecc

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

lib/definitions/platform.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ interface IPlatformService extends NodeJS.EventEmitter {
137137
* Returns information about the latest built application for device in the current project.
138138
* @param {IPlatformData} platformData Data describing the current platform.
139139
* @param {IBuildConfig} buildConfig Defines if the build is for release configuration.
140+
* @param {string} @optional outputPath Directory that should contain the build artifact.
140141
* @returns {IApplicationPackage} Information about latest built application.
141142
*/
142-
getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig): IApplicationPackage;
143+
getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage;
143144

144145
/**
145146
* Returns information about the latest built application for simulator in the current project.
146147
* @param {IPlatformData} platformData Data describing the current platform.
147148
* @param {IBuildConfig} buildConfig Defines if the build is for release configuration.
149+
* @param {string} @optional outputPath Directory that should contain the build artifact.
148150
* @returns {IApplicationPackage} Information about latest built application.
149151
*/
150-
getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig): IApplicationPackage;
152+
getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage;
151153

152154
/**
153155
* Copies latest build output to a specified location.
@@ -164,9 +166,10 @@ interface IPlatformService extends NodeJS.EventEmitter {
164166
* @param {string} platform Mobile platform - Android, iOS.
165167
* @param {IBuildConfig} buildConfig Defines if the searched artifact should be for simulator and is it built for release.
166168
* @param {IProjectData} projectData DTO with information about the project.
169+
* @param {string} @optional outputPath Directory that should contain the build artifact.
167170
* @returns {string} The path to latest built artifact.
168171
*/
169-
lastOutputPath(platform: string, buildConfig: IBuildConfig, projectData: IProjectData): string;
172+
lastOutputPath(platform: string, buildConfig: IBuildConfig, projectData: IProjectData, outputPath?: string): string;
170173

171174
/**
172175
* Reads contents of a file on device.

lib/services/ios-project-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
7373
emulatorBuildOutputPath: path.join(projectRoot, "build", "emulator"),
7474
getValidPackageNames: (buildOptions: { isReleaseBuild?: boolean, isForDevice?: boolean }): string[] => {
7575
if (buildOptions.isForDevice) {
76-
return [projectData.projectName + ".ipa"];
76+
return [`${projectData.projectName}.ipa`];
7777
}
7878

79-
return [projectData.projectName + ".app"];
79+
return [`${projectData.projectName}.app`, `${projectData.projectName}.zip`];
8080
},
8181
frameworkFilesExtensions: [".a", ".framework", ".bin"],
8282
frameworkDirectoriesExtensions: [".framework"],

lib/services/livesync/livesync-service.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,29 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
143143
await this.$platformService.preparePlatform(platform, <any>{}, null, projectData, <any>{}, modifiedFiles);
144144
}
145145

146+
const rebuildInfo = _.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === platform);
147+
148+
if (rebuildInfo) {
149+
// Case where we have three devices attached, a change that requires build is found,
150+
// we'll rebuild the app only for the first device, but we should install new package on all three devices.
151+
await this.$platformService.installApplication(device, { release: false }, projectData, rebuildInfo.pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
152+
return;
153+
}
154+
146155
// TODO: fix args cast to any
147156
const shouldBuild = await this.$platformService.shouldBuild(platform, projectData, <any>{ buildForDevice: !device.isEmulator }, deviceBuildInfoDescriptor.outputPath);
148157
if (shouldBuild) {
149158
const pathToBuildItem = await deviceBuildInfoDescriptor.buildAction();
150159
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
151160
rebuiltInformation.push({ isEmulator: device.isEmulator, platform, pathToBuildItem });
152-
}
153-
154-
const rebuildInfo = _.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === platform);
161+
await this.$platformService.installApplication(device, { release: false }, projectData, pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
155162

156-
if (rebuildInfo) {
157-
// Case where we have three devices attached, a change that requires build is found,
158-
// we'll rebuild the app only for the first device, but we should install new package on all three devices.
159-
await this.$platformService.installApplication(device, { release: false }, projectData, rebuildInfo.pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
160163
}
161164

162165
const shouldInstall = await this.$platformService.shouldInstall(device, projectData, deviceBuildInfoDescriptor.outputPath);
163166
if (shouldInstall) {
164-
// device.applicationManager.installApplication()
165-
console.log("TODO!!!!!!");
166-
// call platformService.installApplication here as well.
167+
168+
await this.$platformService.installApplication(device, { release: false }, projectData, null, deviceBuildInfoDescriptor.outputPath);
167169
}
168170
}
169171

lib/services/platform-service.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
370370
}
371371

372372
public async shouldBuild(platform: string, projectData: IProjectData, buildConfig: IBuildConfig, outputPath?: string): Promise<boolean> {
373-
//TODO: shouldBuild - issue with outputPath - we do not have always the built dir locally
374373
if (this.$projectChangesService.currentChanges.changesRequireBuild) {
375374
return true;
376375
}
@@ -587,13 +586,13 @@ export class PlatformService extends EventEmitter implements IPlatformService {
587586
appUpdater.cleanDestinationApp();
588587
}
589588

590-
public lastOutputPath(platform: string, buildConfig: IBuildConfig, projectData: IProjectData): string {
589+
public lastOutputPath(platform: string, buildConfig: IBuildConfig, projectData: IProjectData, outputPath?: string): string {
591590
let packageFile: string;
592591
let platformData = this.$platformsData.getPlatformData(platform, projectData);
593592
if (buildConfig.buildForDevice) {
594-
packageFile = this.getLatestApplicationPackageForDevice(platformData, buildConfig).packageName;
593+
packageFile = this.getLatestApplicationPackageForDevice(platformData, buildConfig, outputPath).packageName;
595594
} else {
596-
packageFile = this.getLatestApplicationPackageForEmulator(platformData, buildConfig).packageName;
595+
packageFile = this.getLatestApplicationPackageForEmulator(platformData, buildConfig, outputPath).packageName;
597596
}
598597
if (!packageFile || !this.$fs.exists(packageFile)) {
599598
this.$errors.failWithoutHelp("Unable to find built application. Try 'tns build %s'.", platform);
@@ -744,12 +743,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
744743
return packages[0];
745744
}
746745

747-
public getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig): IApplicationPackage {
748-
return this.getLatestApplicationPackage(platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release }));
746+
public getLatestApplicationPackageForDevice(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
747+
return this.getLatestApplicationPackage(outputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: true, isReleaseBuild: buildConfig.release }));
749748
}
750749

751-
public getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig): IApplicationPackage {
752-
return this.getLatestApplicationPackage(platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release }));
750+
public getLatestApplicationPackageForEmulator(platformData: IPlatformData, buildConfig: IBuildConfig, outputPath?: string): IApplicationPackage {
751+
return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release }));
753752
}
754753

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

0 commit comments

Comments
 (0)