Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): fix extension app group and entitlements support #10813

Merged
merged 5 commits into from
Apr 15, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 47 additions & 21 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3356,7 +3356,7 @@ iOSBuilder.prototype.createXcodeProject = function createXcodeProject(next) {
ta.SystemCapabilities || (ta.SystemCapabilities = {});
if (cap === 'app-groups') {
ta.SystemCapabilities['com.apple.ApplicationGroups.iOS'] || (ta.SystemCapabilities['com.apple.ApplicationGroups.iOS'] = {});
ta.SystemCapabilities['com.apple.ApplicationGroups.iOS'].enabled = true;
ta.SystemCapabilities['com.apple.ApplicationGroups.iOS'].enabled = 1;
}
});
}
Expand Down Expand Up @@ -3562,32 +3562,58 @@ iOSBuilder.prototype.createXcodeProject = function createXcodeProject(next) {
extBuildSettings.CODE_SIGN_IDENTITY = buildSettings.CODE_SIGN_IDENTITY;
}

const setEntitlementsFile = (entFile, warn) => {
let src = path.join(ext.basePath, entFile);
if (fs.existsSync(src)) {
extBuildSettings.CODE_SIGN_ENTITLEMENTS = '"' + path.join(ext.relPath, entFile) + '"';
targetInfo.entitlementsFile = path.join(this.buildDir, ext.relPath, entFile);
} else {
src = path.join(ext.basePath, targetName, entFile);
if (fs.existsSync(src)) {
extBuildSettings.CODE_SIGN_ENTITLEMENTS = '"' + path.join(ext.relPath, targetName, entFile) + '"';
targetInfo.entitlementsFile = path.join(this.buildDir, ext.relPath, targetName, entFile);
} else {
delete extBuildSettings.CODE_SIGN_ENTITLEMENTS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should spit out a warning here that we couldn't resolve the configured entitlements file instead of just silently deleting the CODE_SIGN_ENTITLEMENTS setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I originally thought too, but I realized that not every extension target has entitlements. For example, File Provider UI targets do not have entitlements. So, having a warning leads to false positives and that would be confusing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but wouldn't CODE_SIGN_ENTITLEMENTS then be empty anyway and we could check for that? Like an extra parameter if we should print a warning or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so in that specific case it should be fine to print a warning, shouldn't it? If CODE_SIGN_ENTITLEMENTS is explicitly set, warn if we can't properly resolve it. If it's not set, e.g. for the File Provider UI extension, that code path is ignored anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a warning. Should be good to go now.

targetInfo.entitlementsFile = null;
if (warn) {
this.logger.warn(`Unable to find extension target "${targetName}" CODE_SIGN_ENTITLEMENTS file: ${entFile}`);
}
}
}
};

if (extBuildSettings.CODE_SIGN_ENTITLEMENTS) {
const entFile = extBuildSettings.CODE_SIGN_ENTITLEMENTS.replace(/^"/, '').replace(/"$/, '');
extBuildSettings.CODE_SIGN_ENTITLEMENTS = '"' + path.join(ext.relPath, targetName, entFile) + '"';
targetInfo.entitlementsFile = path.join(this.buildDir, ext.relPath, targetName, entFile);
setEntitlementsFile(extBuildSettings.CODE_SIGN_ENTITLEMENTS.replace(/^"/, '').replace(/"$/, ''), true);

} else if (haveEntitlements) {
haveEntitlements = false;

const entFile = targetName + '.entitlements';
extBuildSettings.CODE_SIGN_ENTITLEMENTS = '"' + path.join(ext.relPath, targetName, entFile) + '"';
targetInfo.entitlementsFile = path.join(this.buildDir, ext.relPath, targetName, entFile);

// create the file reference
const entFileRefUuid = this.generateXcodeUuid(xcodeProject);
xobjs.PBXFileReference[entFileRefUuid] = {
isa: 'PBXFileReference',
lastKnownFileType: 'text.xml',
path: '"' + entFile + '"',
sourceTree: '"<group>"'
};
xobjs.PBXFileReference[entFileRefUuid + '_comment'] = entFile;
setEntitlementsFile(entFile);

// add the file to the target's pbx group
targetGroup && targetGroup.children.push({
value: entFileRefUuid,
comment: entFile
});
if (targetInfo.entitlementsFile) {
const exists = Object.keys(xobjs.PBXFileReference).some(function (uuid) {
return xobjs.PBXFileReference[uuid + '_comment'] === entFile;
});

if (!exists) {
// create the file reference
const entFileRefUuid = this.generateXcodeUuid(xcodeProject);
xobjs.PBXFileReference[entFileRefUuid] = {
isa: 'PBXFileReference',
lastKnownFileType: 'text.xml',
path: '"' + entFile + '"',
sourceTree: '"<group>"'
};
xobjs.PBXFileReference[entFileRefUuid + '_comment'] = entFile;

// add the file to the target's pbx group
targetGroup && targetGroup.children.push({
value: entFileRefUuid,
comment: entFile
});
}
}
}

if (hasSwiftFiles) {
Expand Down