Skip to content

Commit

Permalink
Fixes $(PRODUCT_BUNDLE_IDENTIFIER) not being resolved for a product a…
Browse files Browse the repository at this point in the history
…rchive (#494)

* Fix shelljs error in not removing symlinks during run command
* Changed build settings in Xcode project for a manual build
- If a provisioning profile is set, set CODE_SIGN_STYLE build setting to 'Manual'
- If a provisioning profile is set, set ProvisioningStyle target attribute to 'Manual'
- if provisioning profile is NOT set AND 'automaticProvisioning' build option is set to TRUE, reverse the manual settings from above to 'Automatic'
  • Loading branch information
shazron authored Jan 14, 2019
1 parent 8e718c0 commit c2cab27
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
67 changes: 58 additions & 9 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ var projectFile = require('./projectFile');

var events = require('cordova-common').events;

var projectPath = path.join(__dirname, '..', '..');
var projectName = null;

// These are regular expressions to detect if the user is changing any of the built-in xcodebuildArgs
/* eslint-disable no-useless-escape */
var buildFlagMatchers = {
Expand All @@ -47,6 +44,40 @@ var buildFlagMatchers = {
};
/* eslint-enable no-useless-escape */

/**
* Creates a project object (see projectFile.js/parseProjectFile) from
* a project path and name
*
* @param {*} projectPath
* @param {*} projectName
*/
function createProjectObject (projectPath, projectName) {
var locations = {
root: projectPath,
pbxproj: path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj')
};

return projectFile.parse(locations);
}

/**
* Gets the resolved bundle identifier from a project.
* Resolves the variable set in INFO.plist, if any (simple case)
*
* @param {*} projectObject
*/
function getBundleIdentifier (projectObject) {
var packageName = projectObject.getPackageName();
var bundleIdentifier = packageName;

var variables = packageName.match(/\$\((\w+)\)/); // match $(VARIABLE), if any
if (variables && variables.length >= 2) {
bundleIdentifier = projectObject.xcode.getBuildProperty(variables[1]);
}

return bundleIdentifier;
}

/**
* Returns a promise that resolves to the default simulator target; the logic here
* matches what `cordova emulate ios` does.
Expand Down Expand Up @@ -74,6 +105,8 @@ function getDefaultSimulatorTarget () {

module.exports.run = function (buildOpts) {
var emulatorTarget = '';
var projectPath = path.join(__dirname, '..', '..');
var projectName = '';

buildOpts = buildOpts || {};

Expand Down Expand Up @@ -157,6 +190,26 @@ module.exports.run = function (buildOpts) {
if (buildOpts.developmentTeam) {
extraConfig += 'DEVELOPMENT_TEAM = ' + buildOpts.developmentTeam + '\n';
}

function writeCodeSignStyle (value) {
var project = createProjectObject(projectPath, projectName);

events.emit('verbose', `Set CODE_SIGN_STYLE Build Property to ${value}.`);
project.xcode.updateBuildProperty('CODE_SIGN_STYLE', value);
events.emit('verbose', `Set ProvisioningStyle Target Attribute to ${value}.`);
project.xcode.addTargetAttribute('ProvisioningStyle', value);

project.write();
}

if (buildOpts.provisioningProfile) {
events.emit('verbose', 'ProvisioningProfile build option set, changing project settings to Manual.');
writeCodeSignStyle('Manual');
} else if (buildOpts.automaticProvisioning) {
events.emit('verbose', 'ProvisioningProfile build option NOT set, changing project settings to Automatic.');
writeCodeSignStyle('Automatic');
}

return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8');
}).then(function () {
var configuration = buildOpts.release ? 'Release' : 'Debug';
Expand All @@ -178,12 +231,8 @@ module.exports.run = function (buildOpts) {
return;
}

var locations = {
root: projectPath,
pbxproj: path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj')
};

var bundleIdentifier = projectFile.parse(locations).getPackageName();
var project = createProjectObject(projectPath, projectName);
var bundleIdentifier = getBundleIdentifier(project);
var exportOptions = {'compileBitcode': false, 'method': 'development'};

if (buildOpts.packageType) {
Expand Down
3 changes: 2 additions & 1 deletion bin/templates/scripts/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var build = require('./build');
var shell = require('shelljs');
var superspawn = require('cordova-common').superspawn;
var check_reqs = require('./check_reqs');
var fs = require('fs-extra');

var events = require('cordova-common').events;

Expand Down Expand Up @@ -88,7 +89,7 @@ module.exports.run = function (runOptions) {
var payloadFolder = path.join(buildOutputDir, 'Payload');

// delete the existing platform/ios/build/device/appname.app
shell.rm('-rf', appFile);
fs.removeSync(appFile);
// move the platform/ios/build/device/Payload/appname.app to parent
shell.mv('-f', appFileInflated, buildOutputDir);
// delete the platform/ios/build/device/Payload folder
Expand Down

0 comments on commit c2cab27

Please sign in to comment.