Skip to content

Commit 0f51df3

Browse files
committed
Fix some issues about the provision switch
1 parent 1606b2a commit 0f51df3

11 files changed

+85
-25
lines changed

lib/declarations.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ interface IClean {
9898
}
9999

100100
interface IProvision {
101-
provision: any;
101+
provision: string;
102102
}
103103

104104
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/services/android-project-service.ts

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

438+
public checkForChanges(changesInfo: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void {
439+
// Nothing android specific to check yet.
440+
}
441+
438442
private _canUseGradle: boolean;
439443
private canUseGradle(projectData: IProjectData, frameworkVersion?: string): boolean {
440444
if (!this._canUseGradle) {

lib/services/ios-project-service.ts

+48-7
Original file line numberDiff line numberDiff line change
@@ -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 = Xcode.open(this.getPbxProjPath(projectData));
386385
const signing = xcode.getSigning(projectData.projectName);
387386

388387
let shouldUpdateXcode = false;
@@ -428,11 +427,16 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
428427
}
429428

430429
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);
430+
const xcode = Xcode.open(this.getPbxProjPath(projectData));
433431
const signing = xcode.getSigning(projectData.projectName);
434432

435-
if ((this.readXCConfigProvisioningProfile(projectData) || this.readXCConfigProvisioningProfileForIPhoneOs(projectData)) && (!signing || signing.style !== "Manual")) {
433+
const hasProvisioningProfileInXCConfig =
434+
this.readXCConfigProvisioningProfileSpecifierForIPhoneOs(projectData) ||
435+
this.readXCConfigProvisioningProfileSpecifier(projectData) ||
436+
this.readXCConfigProvisioningProfileForIPhoneOs(projectData) ||
437+
this.readXCConfigProvisioningProfile(projectData);
438+
439+
if (hasProvisioningProfileInXCConfig && (!signing || signing.style !== "Manual")) {
436440
xcode.setManualSigningStyle(projectData.projectName);
437441
xcode.save();
438442
} else if (!buildConfig.provision && !(signing && signing.style === "Manual" && !buildConfig.teamId)) {
@@ -623,7 +627,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
623627

624628
if (provision) {
625629
let projectRoot = path.join(projectData.platformsDir, "ios");
626-
await this.setupSigningFromProvision(projectRoot, provision);
630+
await this.setupSigningFromProvision(projectRoot, projectData, provision);
627631
}
628632

629633
let project = this.createPbxProj(projectData);
@@ -844,6 +848,35 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
844848
return Promise.resolve();
845849
}
846850

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

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

lib/services/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
293293
}
294294
}
295295

296-
if (!changesInfo || changesInfo.appResourcesChanged) {
296+
if (!changesInfo || changesInfo.changesRequirePrepare) {
297297
await this.copyAppFiles(platform, appFilesUpdaterOptions, projectData);
298298
this.copyAppResources(platform, projectData);
299299
await platformData.platformProjectService.prepareProject(projectData, platformSpecificData);

lib/services/project-changes-service.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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 ||
@@ -25,6 +26,11 @@ class ProjectChangesInfo implements IProjectChangesInfo {
2526
this.appResourcesChanged ||
2627
this.nativeChanged;
2728
}
29+
30+
public get changesRequirePrepare(): boolean {
31+
return this.appResourcesChanged ||
32+
this.signingChanged;
33+
}
2834
}
2935

3036
export class ProjectChangesService implements IProjectChangesService {
@@ -75,16 +81,10 @@ export class ProjectChangesService implements IProjectChangesService {
7581
]);
7682
}
7783
}
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-
}
84+
85+
let projectService = platformData.platformProjectService;
86+
projectService.checkForChanges(this._changesInfo, projectChangesOptions, projectData);
87+
8888
if (projectChangesOptions.bundle !== this._prepareInfo.bundle || projectChangesOptions.release !== this._prepareInfo.release) {
8989
this._changesInfo.appFilesChanged = true;
9090
this._changesInfo.appResourcesChanged = true;

package.json

+1-1
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",

test/npm-support.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ async function setupProject(dependencies?: any): Promise<any> {
159159
ensureConfigurationFileInAppResources: (): any => null,
160160
interpolateConfigurationFile: (): void => undefined,
161161
isPlatformPrepared: (projectRoot: string) => false,
162-
validatePlugins: (projectData: IProjectData) => Promise.resolve()
162+
validatePlugins: (projectData: IProjectData) => Promise.resolve(),
163+
checkForChanges: () => { /* */ }
163164
}
164165
};
165166
};

test/platform-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ describe('Platform Service Tests', () => {
359359
processConfigurationFilesFromAppResources: () => Promise.resolve(),
360360
ensureConfigurationFileInAppResources: (): any => null,
361361
interpolateConfigurationFile: (): void => undefined,
362-
isPlatformPrepared: (projectRoot: string) => false
362+
isPlatformPrepared: (projectRoot: string) => false,
363+
checkForChanges: () => { /* */ }
363364
}
364365
};
365366
};
@@ -432,7 +433,8 @@ describe('Platform Service Tests', () => {
432433
processConfigurationFilesFromAppResources: () => Promise.resolve(),
433434
ensureConfigurationFileInAppResources: (): any => null,
434435
interpolateConfigurationFile: (): void => undefined,
435-
isPlatformPrepared: (projectRoot: string) => false
436+
isPlatformPrepared: (projectRoot: string) => false,
437+
checkForChanges: () => { /* */ }
436438
}
437439
};
438440
};

test/stubs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
355355
async cleanProject(projectRoot: string, projectData: IProjectData): Promise<void> {
356356
return Promise.resolve();
357357
}
358+
checkForChanges(changesInfo: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void {
359+
// Nothing yet.
360+
}
358361
}
359362

360363
export class ProjectDataService implements IProjectDataService {

0 commit comments

Comments
 (0)