From 9bdf1e6ad019f84ba3a1ab4d4ff83ac15c6bcaa2 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 17 Aug 2017 13:46:55 +0300 Subject: [PATCH] Fix passing provision to `tns run ios` and passsing `--teamId` Passing `--provision` to `tns run ` is not respected. Fix this by including additional option in the deviceDescriptors. This allows us to pass different provisions for each device, however in CLI's commands we'll set one provision for all devices. Also fix passing `--teamId` option - during previous refactoring we've broken the code for it and it has not been respected. Remove the unused alias `teamIdentifier` and use `teamId` in all cases. --- lib/definitions/livesync.d.ts | 5 ++++ lib/definitions/platform.d.ts | 21 ++++++--------- lib/definitions/project.d.ts | 4 --- lib/services/ios-project-service.ts | 17 +++++++----- .../livesync/livesync-command-helper.ts | 2 ++ lib/services/livesync/livesync-service.ts | 11 +++++--- lib/services/platform-service.ts | 26 +++++++++---------- test/platform-service.ts | 2 +- 8 files changed, 47 insertions(+), 41 deletions(-) diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index 892b8d455a..ec89823dbe 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -94,6 +94,11 @@ interface ILiveSyncDeviceInfo { * Whether to skip preparing the native platform. */ skipNativePrepare?: boolean; + + /** + * Describes options specific for each platform, like provision for iOS, target sdk for Android, etc. + */ + platformSpecificOptions?: IPlatformOptions; } /** diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index fed7c2fd15..058f33fffa 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -1,7 +1,7 @@ interface IPlatformService extends NodeJS.EventEmitter { - cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, framework?: string): Promise; + cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, framework?: string): Promise; - addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, frameworkPath?: string): Promise; + addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, frameworkPath?: string): Promise; /** * Gets list of all installed platforms (the ones for which /platforms/ exists). @@ -32,7 +32,7 @@ interface IPlatformService extends NodeJS.EventEmitter { */ removePlatforms(platforms: string[], projectData: IProjectData): Promise; - updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise; + updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise; /** * Ensures that the specified platform and its dependencies are installed. @@ -47,7 +47,7 @@ interface IPlatformService extends NodeJS.EventEmitter { * @param {Array} filesToSync Files about to be synced to device. * @returns {boolean} true indicates that the platform was prepared. */ - preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, filesToSync?: Array, nativePrepare?: INativePrepare): Promise; + preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, filesToSync?: Array, nativePrepare?: INativePrepare): Promise; /** * Determines whether a build is necessary. A build is necessary when one of the following is true: @@ -113,7 +113,7 @@ interface IPlatformService extends NodeJS.EventEmitter { * @param {IAddPlatformCoreOptions} config Options required for project preparation/creation. * @returns {void} */ - deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise; + deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, config: IPlatformOptions): Promise; /** * Runs the application on specified platform. Assumes that the application is already build and installed. Fails if this is not true. @@ -124,7 +124,7 @@ interface IPlatformService extends NodeJS.EventEmitter { */ startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string): Promise; - cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise; + cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise; validatePlatformInstalled(platform: string, projectData: IProjectData): void; /** @@ -213,17 +213,12 @@ interface IPlatformService extends NodeJS.EventEmitter { saveBuildInfoFile(platform: string, projectDir: string, buildInfoFileDirname: string): void } -interface IAddPlatformCoreOptions extends IPlatformSpecificData, ICreateProjectOptions { } +interface IPlatformOptions extends IPlatformSpecificData, ICreateProjectOptions { } /** * Platform specific data required for project preparation. */ -interface IPlatformSpecificData { - /** - * UUID of the provisioning profile used in iOS project preparation. - */ - provision: any; - +interface IPlatformSpecificData extends IProvision { /** * Target SDK for Android. */ diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index b8a73670af..9a328d9255 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -155,10 +155,6 @@ interface IiOSBuildConfig extends IBuildForDevice, IDeviceIdentifier, IProvision * Code sign identity used for build. If not set iPhone Developer is used as a default when building for device. */ codeSignIdentity?: string; - /** - * Team identifier. - */ - teamIdentifier?: string; } interface IPlatformProjectService extends NodeJS.EventEmitter { diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 72a4379006..cd75de7dad 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -396,8 +396,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ args.push(`PROVISIONING_PROFILE=${buildConfig.mobileProvisionIdentifier}`); } - if (buildConfig && buildConfig.teamIdentifier) { - args.push(`DEVELOPMENT_TEAM=${buildConfig.teamIdentifier}`); + if (buildConfig && buildConfig.teamId) { + args.push(`DEVELOPMENT_TEAM=${buildConfig.teamId}`); } // this.$logger.out("xcodebuild..."); @@ -470,12 +470,14 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ xcode.setManualSigningStyle(projectData.projectName); xcode.save(); } else if (!buildConfig.provision && !(signing && signing.style === "Manual" && !buildConfig.teamId)) { - if (buildConfig) { - delete buildConfig.teamIdentifier; - } - const teamId = await this.getDevelopmentTeam(projectData, buildConfig.teamId); + // Remove teamId from build config as we'll set the signing in Xcode project directly. + // In case we do not remove it, we'll pass DEVELOPMENT_TEAM= to xcodebuild, which is unnecessary. + if (buildConfig.teamId) { + delete buildConfig.teamId; + } + xcode.setAutomaticSigningStyle(projectData.projectName, teamId); xcode.save(); this.$logger.trace("Set Automatic signing style and team."); @@ -1328,6 +1330,9 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f } } } + + this.$logger.trace(`Selected teamId is '${teamId}'.`); + return teamId; } diff --git a/lib/services/livesync/livesync-command-helper.ts b/lib/services/livesync/livesync-command-helper.ts index c6e0334898..869c148160 100644 --- a/lib/services/livesync/livesync-command-helper.ts +++ b/lib/services/livesync/livesync-command-helper.ts @@ -40,6 +40,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { .map(d => { const info: ILiveSyncDeviceInfo = { identifier: d.deviceInfo.identifier, + platformSpecificOptions: this.$options, + buildAction: async (): Promise => { const buildConfig: IBuildConfig = { buildForDevice: !d.isEmulator, diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 1cdb9d6a1d..69f112b8af 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -165,11 +165,12 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { const appInstalledOnDeviceResult: IAppInstalledOnDeviceResult = { appInstalled: false }; if (options.preparedPlatforms.indexOf(platform) === -1) { options.preparedPlatforms.push(platform); - // TODO: Pass provision and sdk as a fifth argument here + + const platformSpecificOptions = options.deviceBuildInfoDescriptor.platformSpecificOptions || {}; await this.$platformService.preparePlatform(platform, { bundle: false, release: false, - }, null, options.projectData, {}, options.modifiedFiles, nativePrepare); + }, null, options.projectData, platformSpecificOptions, options.modifiedFiles, nativePrepare); } const buildResult = await this.installedCachedAppPackage(platform, options); @@ -178,8 +179,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService { return appInstalledOnDeviceResult; } - // TODO: Pass provision and sdk as a fifth argument here - const shouldBuild = await this.$platformService.shouldBuild(platform, options.projectData, { buildForDevice: !options.device.isEmulator, clean: options.liveSyncData && options.liveSyncData.clean }, options.deviceBuildInfoDescriptor.outputPath); + const shouldBuild = await this.$platformService.shouldBuild(platform, + options.projectData, + { buildForDevice: !options.device.isEmulator, clean: options.liveSyncData && options.liveSyncData.clean }, + options.deviceBuildInfoDescriptor.outputPath); let pathToBuildItem = null; let action = LiveSyncTrackActionNames.LIVESYNC_OPERATION; if (shouldBuild) { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 1275f1e1db..1d072f6592 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -43,7 +43,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { super(); } - public async cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, framworkPath?: string): Promise { + public async cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, framworkPath?: string): Promise { for (let platform of platforms) { let version: string = this.getCurrentPlatformVersion(platform, projectData); @@ -57,7 +57,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } - public async addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, frameworkPath?: string): Promise { + public async addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, frameworkPath?: string): Promise { const platformsDir = projectData.platformsDir; this.$fs.ensureDirectoryExists(platformsDir); @@ -84,7 +84,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { return version; } - private async addPlatform(platformParam: string, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, frameworkPath?: string, nativePrepare?: INativePrepare): Promise { + private async addPlatform(platformParam: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, frameworkPath?: string, nativePrepare?: INativePrepare): Promise { let data = platformParam.split("@"), platform = data[0].toLowerCase(), version = data[1]; @@ -137,7 +137,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { this.$logger.out("Project successfully created."); } - private async addPlatformCore(platformData: IPlatformData, frameworkDir: string, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, nativePrepare?: INativePrepare): Promise { + private async addPlatformCore(platformData: IPlatformData, frameworkDir: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, nativePrepare?: INativePrepare): Promise { const coreModuleData = this.$fs.readJson(path.join(frameworkDir, "..", "package.json")); const installedVersion = coreModuleData.version; const customTemplateOptions = await this.getPathToPlatformTemplate(platformTemplate, platformData.frameworkPackageName, projectData.projectDir); @@ -159,7 +159,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } - private async addPlatformCoreNative(platformData: IPlatformData, frameworkDir: string, installedVersion: string, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise { + private async addPlatformCoreNative(platformData: IPlatformData, frameworkDir: string, installedVersion: string, projectData: IProjectData, config: IPlatformOptions): Promise { await platformData.platformProjectService.createProject(path.resolve(frameworkDir), installedVersion, projectData, config); platformData.platformProjectService.ensureConfigurationFileInAppResources(projectData); await platformData.platformProjectService.interpolateData(projectData, config); @@ -213,7 +213,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { public getPreparedPlatforms(projectData: IProjectData): string[] { return _.filter(this.$platformsData.platformsNames, p => { return this.isPlatformPrepared(p, projectData); }); } - public async preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, filesToSync?: Array, nativePrepare?: INativePrepare): Promise { + public async preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, filesToSync?: Array, nativePrepare?: INativePrepare): Promise { const platformData = this.$platformsData.getPlatformData(platform, projectData); const changesInfo = await this.initialPrepare(platform, platformData, appFilesUpdaterOptions, platformTemplate, projectData, config, nativePrepare); const requiresNativePrepare = (!nativePrepare || !nativePrepare.skipNativePrepare) && changesInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPrepare; @@ -265,7 +265,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } - private async initialPrepare(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, nativePrepare?: INativePrepare): Promise { + private async initialPrepare(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, nativePrepare?: INativePrepare): Promise { this.validatePlatform(platform, projectData); await this.trackProjectType(projectData); @@ -532,7 +532,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { this.$logger.out(`Successfully installed on device with identifier '${device.deviceInfo.identifier}'.`); } - public async deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise { + public async deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, config: IPlatformOptions): Promise { await this.preparePlatform(platform, appFilesUpdaterOptions, deployOptions.platformTemplate, projectData, config); let options: Mobile.IDevicesServicesInitializationOptions = { platform: platform, deviceId: deployOptions.device, emulator: deployOptions.emulator @@ -623,7 +623,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { return null; } - public async cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise { + public async cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise { await this.ensurePlatformInstalled(platform, platformTemplate, projectData, config); const appSourceDirectoryPath = path.join(projectData.projectDir, constants.APP_FOLDER_NAME); @@ -679,7 +679,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } - public async updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise { + public async updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise { for (let platformParam of platforms) { let data = platformParam.split("@"), platform = data[0], @@ -736,7 +736,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } - public async ensurePlatformInstalled(platform: string, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions, nativePrepare?: INativePrepare): Promise { + public async ensurePlatformInstalled(platform: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, nativePrepare?: INativePrepare): Promise { let requiresNativePlatformAdd = false; if (!this.isPlatformInstalled(platform, projectData)) { @@ -808,7 +808,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { return this.getLatestApplicationPackage(outputPath || platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath, platformData.getValidPackageNames({ isForDevice: false, isReleaseBuild: buildConfig.release })); } - private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise { + private async updatePlatform(platform: string, version: string, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions): Promise { let platformData = this.$platformsData.getPlatformData(platform, projectData); let data = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName); @@ -841,7 +841,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { } - private async updatePlatformCore(platformData: IPlatformData, updateOptions: IUpdatePlatformOptions, projectData: IProjectData, config: IAddPlatformCoreOptions): Promise { + private async updatePlatformCore(platformData: IPlatformData, updateOptions: IUpdatePlatformOptions, projectData: IProjectData, config: IPlatformOptions): Promise { let packageName = platformData.normalizedPlatformName.toLowerCase(); await this.removePlatforms([packageName], projectData); packageName = updateOptions.newVersion ? `${packageName}@${updateOptions.newVersion}` : packageName; diff --git a/test/platform-service.ts b/test/platform-service.ts index d017e07c76..22d5bf78d0 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -147,7 +147,7 @@ class DestinationFolderVerifier { describe('Platform Service Tests', () => { let platformService: IPlatformService, testInjector: IInjector; - const config: IAddPlatformCoreOptions = { + const config: IPlatformOptions = { ignoreScripts: false, provision: null, sdk: null,