Skip to content

Commit

Permalink
Merge pull request #8622 from cb1kenobi/timob-24142_6_0_X
Browse files Browse the repository at this point in the history
[TIMOB-24142] (6_0_X) Added hook around writing the entitlements file.
  • Loading branch information
hansemannn committed Nov 18, 2016
2 parents ffabf7a + c38ab7e commit d2eca7b
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3512,7 +3512,7 @@ iOSBuilder.prototype.createXcodeProject = function createXcodeProject(next) {
hook(xcodeProject, next);
};

iOSBuilder.prototype._embedCapabilitiesAndWriteEntitlementsPlist = function _embedCapabilitiesAndWriteEntitlementsPlist(plist, dest) {
iOSBuilder.prototype._embedCapabilitiesAndWriteEntitlementsPlist = function _embedCapabilitiesAndWriteEntitlementsPlist(plist, dest, isExtension, next) {
var caps = this.tiapp.ios.capabilities,
parent = path.dirname(dest);

Expand All @@ -3530,22 +3530,30 @@ iOSBuilder.prototype._embedCapabilitiesAndWriteEntitlementsPlist = function _emb

this.unmarkBuildDirFile(dest);

// write the entitlements.plist
var contents = plist.toString('xml');
if (!fs.existsSync(dest) || contents !== fs.readFileSync(dest).toString()) {
if (!this.forceRebuild) {
this.logger.info(__('Forcing rebuild: %s has changed since last build', dest.replace(this.projectDir + '/', '')));
this.forceRebuild = true;
var name = 'build.ios.write' + (isExtension ? 'Extension' : '') + 'Entitlements';
var hook = this.cli.createHook(name, this, function (plist, dest, done) {
// write the entitlements.plist
var contents = plist.toString('xml');

if (!fs.existsSync(dest) || contents !== fs.readFileSync(dest).toString()) {
if (!this.forceRebuild) {
this.logger.info(__('Forcing rebuild: %s has changed since last build', dest.replace(this.projectDir + '/', '')));
this.forceRebuild = true;
}
this.logger.debug(__('Writing %s', dest.cyan));
fs.existsSync(parent) || wrench.mkdirSyncRecursive(parent);
fs.writeFileSync(dest, contents);
} else {
this.logger.trace(__('No change, skipping %s', dest.cyan));
}
this.logger.debug(__('Writing %s', dest.cyan));
fs.existsSync(parent) || wrench.mkdirSyncRecursive(parent);
fs.writeFileSync(dest, contents);
} else {
this.logger.trace(__('No change, skipping %s', dest.cyan));
}

done();
});

hook(plist, dest, next);
};

iOSBuilder.prototype.writeEntitlementsPlist = function writeEntitlementsPlist() {
iOSBuilder.prototype.writeEntitlementsPlist = function writeEntitlementsPlist(next) {
this.logger.info(__('Creating Entitlements.plist'));

// allow the project to have its own custom entitlements
Expand Down Expand Up @@ -3595,7 +3603,7 @@ iOSBuilder.prototype.writeEntitlementsPlist = function writeEntitlementsPlist()
}
}

this._embedCapabilitiesAndWriteEntitlementsPlist(plist, path.join(this.buildDir, this.tiapp.name + '.entitlements'));
this._embedCapabilitiesAndWriteEntitlementsPlist(plist, path.join(this.buildDir, this.tiapp.name + '.entitlements'), false, next);
};

iOSBuilder.prototype.writeInfoPlist = function writeInfoPlist() {
Expand Down Expand Up @@ -4299,12 +4307,12 @@ iOSBuilder.prototype.copyTitaniumiOSFiles = function copyTitaniumiOSFiles() {
}
};

iOSBuilder.prototype.copyExtensionFiles = function copyExtensionFiles() {
if (!this.extensions.length) return;
iOSBuilder.prototype.copyExtensionFiles = function copyExtensionFiles(next) {
if (!this.extensions.length) return next();

this.logger.info(__('Copying iOS extensions'));

this.extensions.forEach(function (extension) {
async.eachSeries(this.extensions, function (extension, next) {
var extName = path.basename(extension.projectPath).replace(/\.xcodeproj$/, ''),
src = path.dirname(extension.projectPath),
dest = path.join(this.buildDir, 'extensions', path.basename(src));
Expand Down Expand Up @@ -4389,15 +4397,15 @@ iOSBuilder.prototype.copyExtensionFiles = function copyExtensionFiles() {
extension.projectPath = path.join(dest, path.basename(extension.projectPath));

// check if we need to write an entitlements file
Object.keys(extension.targetInfo).forEach(function (target) {
async.eachSeries(Object.keys(extension.targetInfo), function (target, next) {
if (!extension.targetInfo[target].entitlementsFile) {
return;
return next();
}

var plist = new appc.plist(fs.existsSync(extension.targetInfo[target].entitlementsFile) ? extension.targetInfo[target].entitlementsFile : null);
this._embedCapabilitiesAndWriteEntitlementsPlist(plist, extension.targetInfo[target].entitlementsFile);
}, this);
}, this);
this._embedCapabilitiesAndWriteEntitlementsPlist(plist, extension.targetInfo[target].entitlementsFile, true, next);
}.bind(this), next);
}.bind(this), next);
};

iOSBuilder.prototype.cleanXcodeDerivedData = function cleanXcodeDerivedData(next) {
Expand Down

0 comments on commit d2eca7b

Please sign in to comment.