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

Fixes $(PRODUCT_BUNDLE_IDENTIFIER) not being resolved for a product archive #494

Merged
merged 5 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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