Skip to content

Commit 5a46932

Browse files
committed
Fix some issues about the provision switch
1 parent 8b730f3 commit 5a46932

20 files changed

+405
-45
lines changed

lib/bootstrap.ts

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ $injector.require("projectChangesService", "./services/project-changes-service")
124124

125125
$injector.require("emulatorPlatformService", "./services/emulator-platform-service");
126126

127+
$injector.require("pbxprojDomXcode", "./node/pbxproj-dom-xcode");
128+
$injector.require("xcode", "./node/xcode");
129+
127130
$injector.require("staticConfig", "./config");
128131

129132
$injector.require("requireService", "./services/require-service");

lib/commands/emulate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class EmulateCommandBase {
2727
keyStorePassword: this.$options.keyStorePassword,
2828
keyStorePath: this.$options.keyStorePath
2929
};
30-
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, this.$options.provision);
30+
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, { frameworkPath: this.$options.frameworkPath, sdk: this.$options.sdk, provision: this.$options.provision, ignoreScripts: this.$options.ignoreScripts });
3131
}
3232
}
3333

lib/declarations.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ interface IClean {
281281
}
282282

283283
interface IProvision {
284-
provision: any;
284+
provision: string;
285285
}
286286

287287
interface ITeamIdentifier {

lib/definitions/project-changes.d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ interface IProjectChangesInfo {
1515
configChanged: boolean;
1616
packageChanged: boolean;
1717
nativeChanged: boolean;
18-
hasChanges: boolean;
19-
changesRequireBuild: boolean;
18+
signingChanged: boolean;
19+
20+
readonly hasChanges: boolean;
21+
readonly changesRequireBuild: boolean;
22+
readonly changesRequirePrepare: boolean;
2023
}
2124

2225
interface IProjectChangesOptions extends IAppFilesUpdaterOptions, IProvision {}

lib/definitions/project.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
258258
* @returns {void}
259259
*/
260260
cleanProject(projectRoot: string, projectData: IProjectData): Promise<void>
261+
262+
/**
263+
* Check the current state of the project, and validate against the options.
264+
* If there are parts in the project that are inconsistent with the desired options, marks them in the changeset flags.
265+
*/
266+
checkForChanges(changeset: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void;
261267
}
262268

263269
interface IAndroidProjectPropertiesManager {

lib/node/pbxproj-dom-xcode.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as pbxprojDomXcodeModule from "pbxproj-dom/xcode";
2+
3+
declare global {
4+
type IPbxprojDomXcode = typeof pbxprojDomXcodeModule;
5+
}
6+
7+
$injector.register("pbxprojDomXcode", pbxprojDomXcodeModule);

lib/node/xcode.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as xcode from "xcode";
2+
3+
declare global {
4+
type IXcode = typeof xcode;
5+
export namespace IXcode {
6+
export type project = typeof xcode.project;
7+
export interface Options extends xcode.Options {}
8+
}
9+
}
10+
11+
$injector.register("xcode", xcode);

lib/services/android-project-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
438438
await adb.executeShellCommand(["rm", "-rf", deviceRootPath]);
439439
}
440440

441+
public checkForChanges(changesInfo: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void {
442+
// Nothing android specific to check yet.
443+
}
444+
441445
private _canUseGradle: boolean;
442446
private canUseGradle(projectData: IProjectData, frameworkVersion?: string): boolean {
443447
if (!this._canUseGradle) {

lib/services/ios-project-service.ts

+53-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as path from "path";
22
import * as shell from "shelljs";
33
import * as os from "os";
44
import * as semver from "semver";
5-
import * as xcode from "xcode";
65
import * as constants from "../constants";
76
import * as helpers from "../common/helpers";
87
import { attachAwaitDetach } from "../common/helpers";
@@ -11,7 +10,6 @@ import { PlistSession } from "plist-merge-patch";
1110
import { EOL } from "os";
1211
import * as temp from "temp";
1312
import * as plist from "plist";
14-
import { Xcode } from "pbxproj-dom/xcode";
1513
import { IOSProvisionService } from "./ios-provision-service";
1614

1715
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
@@ -42,7 +40,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
4240
private $pluginVariablesService: IPluginVariablesService,
4341
private $xcprojService: IXcprojService,
4442
private $iOSProvisionService: IOSProvisionService,
45-
private $sysInfo: ISysInfo) {
43+
private $sysInfo: ISysInfo,
44+
private $pbxprojDomXcode: IPbxprojDomXcode,
45+
private $xcode: IXcode) {
4646
super($fs, $projectDataService);
4747
}
4848

@@ -379,10 +379,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
379379
await this.createIpa(projectRoot, projectData, buildConfig);
380380
}
381381

382-
private async setupSigningFromProvision(projectRoot: string, projectData: IProjectData, provision?: any): Promise<void> {
382+
private async setupSigningFromProvision(projectRoot: string, projectData: IProjectData, provision?: string): Promise<void> {
383383
if (provision) {
384-
const pbxprojPath = path.join(projectRoot, projectData.projectName + ".xcodeproj", "project.pbxproj");
385-
const xcode = Xcode.open(pbxprojPath);
384+
const xcode = this.$pbxprojDomXcode.Xcode.open(this.getPbxProjPath(projectData));
386385
const signing = xcode.getSigning(projectData.projectName);
387386

388387
let shouldUpdateXcode = false;
@@ -399,8 +398,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
399398
}
400399

401400
if (shouldUpdateXcode) {
402-
// This is slow, it read through 260 mobileprovision files on my machine and does quite some checking whether provisioning profiles and devices will match.
403-
// That's why we try to avoid id by checking in the Xcode first.
404401
const pickStart = Date.now();
405402
const mobileprovision = await this.$iOSProvisionService.pick(provision, projectData.projectId);
406403
const pickEnd = Date.now();
@@ -428,11 +425,16 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
428425
}
429426

430427
private async setupSigningForDevice(projectRoot: string, buildConfig: IiOSBuildConfig, projectData: IProjectData): Promise<void> {
431-
const pbxprojPath = path.join(projectRoot, projectData.projectName + ".xcodeproj", "project.pbxproj");
432-
const xcode = Xcode.open(pbxprojPath);
428+
const xcode = this.$pbxprojDomXcode.Xcode.open(this.getPbxProjPath(projectData));
433429
const signing = xcode.getSigning(projectData.projectName);
434430

435-
if ((this.readXCConfigProvisioningProfile(projectData) || this.readXCConfigProvisioningProfileForIPhoneOs(projectData)) && (!signing || signing.style !== "Manual")) {
431+
const hasProvisioningProfileInXCConfig =
432+
this.readXCConfigProvisioningProfileSpecifierForIPhoneOs(projectData) ||
433+
this.readXCConfigProvisioningProfileSpecifier(projectData) ||
434+
this.readXCConfigProvisioningProfileForIPhoneOs(projectData) ||
435+
this.readXCConfigProvisioningProfile(projectData);
436+
437+
if (hasProvisioningProfileInXCConfig && (!signing || signing.style !== "Manual")) {
436438
xcode.setManualSigningStyle(projectData.projectName);
437439
xcode.save();
438440
} else if (!buildConfig.provision && !(signing && signing.style === "Manual" && !buildConfig.teamId)) {
@@ -490,7 +492,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
490492
let frameworkBinaryPath = path.join(frameworkPath, frameworkName);
491493
let isDynamic = _.includes((await this.$childProcess.spawnFromEvent("otool", ["-Vh", frameworkBinaryPath], "close")).stdout, " DYLIB ");
492494

493-
let frameworkAddOptions: xcode.Options = { customFramework: true };
495+
let frameworkAddOptions: IXcode.Options = { customFramework: true };
494496

495497
if (isDynamic) {
496498
frameworkAddOptions["embed"] = true;
@@ -623,7 +625,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
623625

624626
if (provision) {
625627
let projectRoot = path.join(projectData.platformsDir, "ios");
626-
await this.setupSigningFromProvision(projectRoot, provision);
628+
await this.setupSigningFromProvision(projectRoot, projectData, provision);
627629
}
628630

629631
let project = this.createPbxProj(projectData);
@@ -787,7 +789,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
787789
}
788790

789791
private createPbxProj(projectData: IProjectData): any {
790-
let project = new xcode.project(this.getPbxProjPath(projectData));
792+
let project = new this.$xcode.project(this.getPbxProjPath(projectData));
791793
project.parseSync();
792794

793795
return project;
@@ -844,6 +846,35 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
844846
return Promise.resolve();
845847
}
846848

849+
public checkForChanges(changesInfo: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void {
850+
const provision = options.provision;
851+
if (provision !== undefined) {
852+
// Check if the native project's signing is set to the provided provision...
853+
const pbxprojPath = this.getPbxProjPath(projectData);
854+
855+
if (this.$fs.exists(pbxprojPath)) {
856+
const xcode = this.$pbxprojDomXcode.Xcode.open(pbxprojPath);
857+
const signing = xcode.getSigning(projectData.projectName);
858+
if (signing && signing.style === "Manual") {
859+
for (let name in signing.configurations) {
860+
let config = signing.configurations[name];
861+
if (config.uuid !== provision && config.name !== provision) {
862+
changesInfo.signingChanged = true;
863+
break;
864+
}
865+
}
866+
} else {
867+
// Specifying provisioning profile requires "Manual" signing style.
868+
// If the current signing style was not "Manual" it was probably "Automatic" or,
869+
// it was not uniform for the debug and release build configurations.
870+
changesInfo.signingChanged = true;
871+
}
872+
} else {
873+
changesInfo.signingChanged = true;
874+
}
875+
}
876+
}
877+
847878
private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string): string[] {
848879
let filterCallback = (fileName: string, pluginPlatformsFolderPath: string) => path.extname(fileName) === fileExtension;
849880
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);
@@ -1186,6 +1217,14 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11861217
return this.readXCConfig("PROVISIONING_PROFILE[sdk=iphoneos*]", projectData);
11871218
}
11881219

1220+
private readXCConfigProvisioningProfileSpecifier(projectData: IProjectData): string {
1221+
return this.readXCConfig("PROVISIONING_PROFILE_SPECIFIER", projectData);
1222+
}
1223+
1224+
private readXCConfigProvisioningProfileSpecifierForIPhoneOs(projectData: IProjectData): string {
1225+
return this.readXCConfig("PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]", projectData);
1226+
}
1227+
11891228
private async getDevelopmentTeam(projectData: IProjectData, teamId?: string): Promise<string> {
11901229
teamId = teamId || this.readTeamId(projectData);
11911230

lib/services/ios-provision-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class IOSProvisionService {
2929

3030
function formatSupportedDeviceCount(prov: mobileprovision.provision.MobileProvision) {
3131
if (devices.length > 0 && prov.Type === "Development") {
32-
return prov.ProvisionedDevices.reduce((count, device) => count + (devices.indexOf(device) >= 0 ? 1 : 0), 0) + "/" + devices.length + " targets";
32+
return prov.ProvisionedDevices.filter(device => devices.indexOf(device) >= 0).length + "/" + devices.length + " targets";
3333
} else {
3434
return "";
3535
}

lib/services/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
290290
}
291291
}
292292

293-
if (!changesInfo || changesInfo.appResourcesChanged) {
293+
if (!changesInfo || changesInfo.changesRequirePrepare) {
294294
await this.copyAppFiles(platform, appFilesUpdaterOptions, projectData);
295295
this.copyAppResources(platform, projectData);
296296
await platformData.platformProjectService.prepareProject(projectData, platformSpecificData);

lib/services/project-changes-service.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@ class ProjectChangesInfo implements IProjectChangesInfo {
1111
public configChanged: boolean;
1212
public packageChanged: boolean;
1313
public nativeChanged: boolean;
14+
public signingChanged: boolean;
1415

1516
public get hasChanges(): boolean {
1617
return this.packageChanged ||
1718
this.appFilesChanged ||
1819
this.appResourcesChanged ||
1920
this.modulesChanged ||
20-
this.configChanged;
21+
this.configChanged ||
22+
this.signingChanged;
2123
}
2224

2325
public get changesRequireBuild(): boolean {
2426
return this.packageChanged ||
2527
this.appResourcesChanged ||
2628
this.nativeChanged;
2729
}
30+
31+
public get changesRequirePrepare(): boolean {
32+
return this.appResourcesChanged ||
33+
this.signingChanged;
34+
}
2835
}
2936

3037
export class ProjectChangesService implements IProjectChangesService {
@@ -75,16 +82,10 @@ export class ProjectChangesService implements IProjectChangesService {
7582
]);
7683
}
7784
}
78-
if (platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
79-
const nextCommandProvisionUUID = projectChangesOptions.provision;
80-
// We should consider reading here the provisioning profile UUID from the xcodeproj and xcconfig.
81-
const prevProvisionUUID = this._prepareInfo.iOSProvisioningProfileUUID;
82-
if (nextCommandProvisionUUID !== prevProvisionUUID) {
83-
this._changesInfo.nativeChanged = true;
84-
this._changesInfo.configChanged = true;
85-
this._prepareInfo.iOSProvisioningProfileUUID = nextCommandProvisionUUID;
86-
}
87-
}
85+
86+
let projectService = platformData.platformProjectService;
87+
projectService.checkForChanges(this._changesInfo, projectChangesOptions, projectData);
88+
8889
if (projectChangesOptions.bundle !== this._prepareInfo.bundle || projectChangesOptions.release !== this._prepareInfo.release) {
8990
this._changesInfo.appFilesChanged = true;
9091
this._changesInfo.appResourcesChanged = true;

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"mute-stream": "0.0.5",
5757
"open": "0.0.5",
5858
"osenv": "0.1.3",
59-
"pbxproj-dom": "1.0.9",
59+
"pbxproj-dom": "1.0.11",
6060
"plist": "1.1.0",
6161
"plist-merge-patch": "0.0.9",
6262
"plistlib": "0.2.1",
@@ -98,8 +98,8 @@
9898
"grunt-tslint": "4.0.0",
9999
"istanbul": "0.4.5",
100100
"mocha": "3.1.2",
101-
"mocha-typescript": "^1.0.4",
102101
"should": "7.0.2",
102+
"source-map-support": "^0.4.14",
103103
"tslint": "4.3.1",
104104
"typescript": "2.1.4"
105105
},

0 commit comments

Comments
 (0)