Skip to content

Commit d84108e

Browse files
author
Tsvetan Raikov
committed
Fixed: TNS run command broken with using --watch
1 parent 85d7c78 commit d84108e

14 files changed

+130
-199
lines changed

bin/nativescript.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
require("../lib/nativescript-cli.js");

lib/commands/appstore-upload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class PublishIOS implements ICommand {
6565
};
6666
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
6767
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
68-
this.$platformService.prepareAndBuild(platform, iOSBuildConfig, true).wait();
68+
this.$platformService.buildPlatform(platform, iOSBuildConfig, true).wait();
6969
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice });
7070
} else {
7171
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.");

lib/commands/build.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ export class BuildCommandBase {
22
constructor(protected $options: IOptions,
33
private $platformService: IPlatformService) { }
44

5-
executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
5+
executeCore(args: string[]): IFuture<void> {
66
return (() => {
77
let platform = args[0].toLowerCase();
8-
this.$platformService.preparePlatform(platform, true).wait();
9-
this.$platformService.buildPlatform(platform, buildConfig).wait();
8+
this.$platformService.buildPlatform(platform, null, true).wait();
109
if(this.$options.copyTo) {
1110
this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice}).wait();
1211
}

lib/commands/deploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class DeployOnDeviceCommand implements ICommand {
66
private $mobileHelper: Mobile.IMobileHelper) { }
77

88
execute(args: string[]): IFuture<void> {
9-
return this.$platformService.deployOnDevice(args[0]);
9+
return this.$platformService.deployPlatform(args[0]);
1010
}
1111

1212
public canExecute(args: string[]): IFuture<boolean> {

lib/commands/emulate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export class EmulateCommandBase {
22
constructor(private $platformService: IPlatformService) { }
33

44
executeCore(args: string[]): IFuture<void> {
5-
return this.$platformService.deployOnEmulator(args[0]);
5+
return this.$platformService.emulatePlatform(args[0]);
66
}
77
}
88

lib/commands/run.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ export class RunCommandBase {
33
private $usbLiveSyncService: ILiveSyncService,
44
protected $options: IOptions) { }
55

6-
public executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
6+
public executeCore(args: string[]): IFuture<void> {
77
if (this.$options.watch) {
8+
this.$platformService.deployPlatform(args[0]).wait();
89
return this.$usbLiveSyncService.liveSync(args[0]);
910
} else {
10-
return this.$platformService.runPlatform(args[0], buildConfig);
11+
return this.$platformService.runPlatform(args[0]);
1112
}
1213
}
1314
}

lib/definitions/platform.d.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ interface IPlatformService {
55
getPreparedPlatforms(): IFuture<string[]>;
66
removePlatforms(platforms: string[]): IFuture<void>;
77
updatePlatforms(platforms: string[]): IFuture<void>;
8-
runPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
98
preparePlatform(platform: string, force?: boolean, skipModulesAndResources?: boolean): IFuture<boolean>;
9+
buildPlatform(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture<void>;
10+
deployPlatform(platform: string): IFuture<void>;
11+
runPlatform(platform: string): IFuture<void>;
12+
emulatePlatform(platform: string): IFuture<void>;
1013
cleanDestinationApp(platform: string): IFuture<void>;
11-
buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
12-
buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
13-
installOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
14-
deployOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
15-
startOnDevice(platform: string): IFuture<void>;
16-
deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
1714
validatePlatformInstalled(platform: string): void;
1815
validatePlatform(platform: string): void;
1916

@@ -22,8 +19,6 @@ interface IPlatformService {
2219
copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): IFuture<void>;
2320
lastOutputPath(platform: string, settings: { isForDevice: boolean }): string;
2421
ensurePlatformInstalled(platform: string): IFuture<void>;
25-
26-
prepareAndBuild(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture<void>;
2722
}
2823

2924
interface IPlatformData {

lib/definitions/project.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ interface IPlatformProjectService {
6868
interpolateConfigurationFile(configurationFilePath?: string): IFuture<void>;
6969
afterCreateProject(projectRoot: string): IFuture<void>;
7070
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
71-
buildForDeploy(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
7271
prepareProject(): IFuture<void>;
7372
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
7473
isPlatformPrepared(projectRoot: string): IFuture<boolean>;

lib/providers/livesync-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class LiveSyncProvider implements ILiveSyncProvider {
5757

5858
public buildForDevice(device: Mobile.IDevice): IFuture<string> {
5959
return (() => {
60-
this.$platformService.buildForDeploy(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
60+
this.$platformService.buildPlatform(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
6161
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform);
6262
if (device.isEmulator) {
6363
return this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait().packageName;

lib/services/android-debug-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AndroidDebugService implements IDebugService {
4242

4343
private debugOnEmulator(): IFuture<void> {
4444
return (() => {
45-
this.$platformService.deployOnEmulator(this.platform).wait();
45+
this.$platformService.deployPlatform(this.platform).wait();
4646
// Assure we've detected the emulator as device
4747
// For example in case deployOnEmulator had stated new emulator instance
4848
// we need some time to detect it. Let's force detection.
@@ -111,7 +111,7 @@ class AndroidDebugService implements IDebugService {
111111
let cachedDeviceOption = this.$options.forDevice;
112112
this.$options.forDevice = true;
113113
if (this.$options.rebuild) {
114-
this.$platformService.prepareAndBuild(this.platform).wait();
114+
this.$platformService.buildPlatform(this.platform).wait();
115115
}
116116
this.$options.forDevice = !!cachedDeviceOption;
117117

lib/services/android-project-service.ts

-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
291291
return buildOptions;
292292
}
293293

294-
public buildForDeploy(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
295-
return this.buildProject(projectRoot, buildConfig);
296-
}
297-
298294
public isPlatformPrepared(projectRoot: string): IFuture<boolean> {
299295
return this.$fs.exists(path.join(this.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
300296
}

lib/services/ios-debug-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class IOSDebugService implements IDebugService {
106106
return (() => {
107107
let platformData = this.$platformsData.getPlatformData(this.platform);
108108
if (this.$options.rebuild) {
109-
this.$platformService.prepareAndBuild(this.platform).wait();
109+
this.$platformService.buildPlatform(this.platform).wait();
110110
}
111111
let emulatorPackage = this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait();
112112

@@ -159,9 +159,9 @@ class IOSDebugService implements IDebugService {
159159
// we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification
160160
let action: IFuture<void>;
161161
if (this.$config.debugLivesync) {
162-
action = this.$platformService.startOnDevice(this.platform);
162+
action = this.$platformService.runPlatform(this.platform);
163163
} else {
164-
action = this.$platformService.deployOnDevice(this.platform);
164+
action = this.$platformService.deployPlatform(this.platform);
165165
}
166166
this.debugBrkCore(device, shouldBreak).wait();
167167
action.wait();

lib/services/ios-project-service.ts

+71-60
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
244244
"build",
245245
'SHARED_PRECOMPS_DIR=' + path.join(projectRoot, 'build', 'sharedpch')
246246
];
247-
248247
basicArgs = basicArgs.concat(this.xcbuildProjectArgs(projectRoot));
249248

250249
// Starting from tns-ios 1.4 the xcconfig file is referenced in the project template
@@ -253,37 +252,58 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
253252
basicArgs.push("-xcconfig", path.join(projectRoot, this.$projectData.projectName, "build.xcconfig"));
254253
}
255254

256-
let args: string[] = [];
257255
let buildForDevice = this.$options.forDevice || (buildConfig && buildConfig.buildForDevice);
258256
if (buildForDevice) {
259-
let defaultArchitectures = [
260-
'ARCHS=armv7 arm64',
261-
'VALID_ARCHS=armv7 arm64'
262-
];
263-
264-
args = basicArgs.concat([
265-
"-sdk", "iphoneos",
266-
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device")
267-
]);
257+
this.buildForDevice(projectRoot, basicArgs, buildConfig).wait();
258+
} else {
259+
this.buildForSimulator(projectRoot, basicArgs, buildConfig).wait();
260+
}
261+
}).future<void>()();
262+
}
268263

269-
args = args.concat((buildConfig && buildConfig.architectures) || defaultArchitectures);
264+
private buildForDevice(projectRoot: string, args: string[], buildConfig?: IiOSBuildConfig): IFuture<void> {
265+
return (() => {
266+
let defaultArchitectures = [
267+
'ARCHS=armv7 arm64',
268+
'VALID_ARCHS=armv7 arm64'
269+
];
270270

271-
let xcodeBuildVersion = this.getXcodeVersion();
272-
if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) {
273-
let teamId = this.getDevelopmentTeam();
274-
if (teamId) {
275-
args = args.concat("DEVELOPMENT_TEAM=" + teamId);
271+
// build only for device specific architecture
272+
if (!this.$options.release && !(buildConfig && buildConfig.architectures)) {
273+
this.$devicesService.initialize({ platform: this.$devicePlatformsConstants.iOS.toLowerCase(), deviceId: this.$options.device }).wait();
274+
let instances = this.$devicesService.getDeviceInstances();
275+
let devicesArchitectures = _(instances)
276+
.filter(d => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform) && d.deviceInfo.activeArchitecture)
277+
.map(d => d.deviceInfo.activeArchitecture)
278+
.uniq()
279+
.value();
280+
if (devicesArchitectures.length > 0) {
281+
let architectures = [
282+
`ARCHS=${devicesArchitectures.join(" ")}`,
283+
`VALID_ARCHS=${devicesArchitectures.join(" ")}`
284+
];
285+
if (devicesArchitectures.length > 1) {
286+
architectures.push('ONLY_ACTIVE_ARCH=NO');
287+
}
288+
if (!buildConfig) {
289+
buildConfig = {};
276290
}
291+
buildConfig.architectures = architectures;
292+
}
293+
}
294+
args = args.concat((buildConfig && buildConfig.architectures) || defaultArchitectures);
295+
296+
args = args.concat([
297+
"-sdk", "iphoneos",
298+
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device")
299+
]);
300+
301+
let xcodeBuildVersion = this.getXcodeVersion();
302+
if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) {
303+
let teamId = this.getDevelopmentTeam();
304+
if (teamId) {
305+
args = args.concat("DEVELOPMENT_TEAM=" + teamId);
277306
}
278-
} else {
279-
args = basicArgs.concat([
280-
"-sdk", "iphonesimulator",
281-
"ARCHS=i386 x86_64",
282-
"VALID_ARCHS=i386 x86_64",
283-
"ONLY_ACTIVE_ARCH=NO",
284-
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"),
285-
"CODE_SIGN_IDENTITY="
286-
]);
287307
}
288308

289309
if (buildConfig && buildConfig.codeSignIdentity) {
@@ -295,47 +315,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
295315
}
296316

297317
this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
318+
this.createIpa(projectRoot).wait();
298319

299-
if (buildForDevice) {
300-
let buildOutputPath = path.join(projectRoot, "build", "device");
301-
302-
// Produce ipa file
303-
let xcrunArgs = [
304-
"-sdk", "iphoneos",
305-
"PackageApplication",
306-
"-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"),
307-
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
308-
];
309-
310-
this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
311-
}
312320
}).future<void>()();
313321
}
314322

315-
public buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
316-
if (this.$options.release) {
317-
return this.buildProject(this.platformData.projectRoot, buildConfig);
318-
}
319-
320-
let devicesArchitectures = _(this.$devicesService.getDeviceInstances())
321-
.filter(d => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform))
322-
.map(d => d.deviceInfo.activeArchitecture)
323-
.uniq()
324-
.value();
325-
326-
let architectures = [
327-
`ARCHS=${devicesArchitectures.join(" ")}`,
328-
`VALID_ARCHS=${devicesArchitectures.join(" ")}`
329-
];
323+
private buildForSimulator(projectRoot: string, args: string[], buildConfig?: IiOSBuildConfig): IFuture<void> {
324+
return (() => {
325+
args = args.concat([
326+
"-sdk", "iphonesimulator",
327+
"ARCHS=i386 x86_64",
328+
"VALID_ARCHS=i386 x86_64",
329+
"ONLY_ACTIVE_ARCH=NO",
330+
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"),
331+
"CODE_SIGN_IDENTITY="
332+
]);
330333

331-
if (devicesArchitectures.length > 1) {
332-
architectures.push('ONLY_ACTIVE_ARCH=NO');
333-
}
334+
this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
334335

335-
buildConfig = buildConfig || {};
336-
buildConfig.architectures = architectures;
336+
}).future<void>()();
337+
}
337338

338-
return this.buildProject(this.platformData.projectRoot, buildConfig);
339+
private createIpa(projectRoot: string): IFuture<void> {
340+
return (() => {
341+
let buildOutputPath = path.join(projectRoot, "build", "device");
342+
let xcrunArgs = [
343+
"-sdk", "iphoneos",
344+
"PackageApplication",
345+
"-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"),
346+
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
347+
];
348+
this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
349+
}).future<void>()();
339350
}
340351

341352
public isPlatformPrepared(projectRoot: string): IFuture<boolean> {

0 commit comments

Comments
 (0)