Skip to content

Commit c7815b5

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

8 files changed

+78
-21
lines changed

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

+54-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,41 @@ 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 nextCommandProvisionUUID = options.provision;
853+
854+
if (typeof nextCommandProvisionUUID === "string") {
855+
const pbxprojPath = this.getPbxProjPath(projectData);
856+
857+
// Check if the native project's signing is set to the provided provision...
858+
let signingChanged = false;
859+
if (this.$fs.exists(pbxprojPath)) {
860+
const xcode = Xcode.open(pbxprojPath);
861+
const signing = xcode.getSigning(projectData.projectName);
862+
if (signing && signing.style === "Manual") {
863+
for (let name in signing.configurations) {
864+
let config = signing.configurations[name];
865+
if (config.uuid !== nextCommandProvisionUUID && config.name !== nextCommandProvisionUUID) {
866+
signingChanged = true;
867+
break;
868+
}
869+
}
870+
} else {
871+
signingChanged = true;
872+
}
873+
} else {
874+
signingChanged = true;
875+
}
876+
877+
if (signingChanged) {
878+
changesInfo.nativeChanged = true;
879+
changesInfo.configChanged = true;
880+
// TRICKY: The native project is prepared only if appResourcesChanged.
881+
changesInfo.appResourcesChanged = true;
882+
}
883+
}
884+
}
885+
847886
private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string): string[] {
848887
let filterCallback = (fileName: string, pluginPlatformsFolderPath: string) => path.extname(fileName) === fileExtension;
849888
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);
@@ -1186,6 +1225,14 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
11861225
return this.readXCConfig("PROVISIONING_PROFILE[sdk=iphoneos*]", projectData);
11871226
}
11881227

1228+
private readXCConfigProvisioningProfileSpecifier(projectData: IProjectData): string {
1229+
return this.readXCConfig("PROVISIONING_PROFILE_SPECIFIER", projectData);
1230+
}
1231+
1232+
private readXCConfigProvisioningProfileSpecifierForIPhoneOs(projectData: IProjectData): string {
1233+
return this.readXCConfig("PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]", projectData);
1234+
}
1235+
11891236
private async getDevelopmentTeam(projectData: IProjectData, teamId?: string): Promise<string> {
11901237
teamId = teamId || this.readTeamId(projectData);
11911238

lib/services/project-changes-service.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,10 @@ export class ProjectChangesService implements IProjectChangesService {
7575
]);
7676
}
7777
}
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-
}
78+
79+
let projectService = platformData.platformProjectService;
80+
projectService.checkForChanges(this._changesInfo, projectChangesOptions, projectData);
81+
8882
if (projectChangesOptions.bundle !== this._prepareInfo.bundle || projectChangesOptions.release !== this._prepareInfo.release) {
8983
this._changesInfo.appFilesChanged = true;
9084
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)