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 issue #486. Distinguish xcodebuild build command and archive command. #487

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module.exports.run = function (buildOpts) {
// remove the build/device folder before building
shell.rm('-rf', buildOutputDir);

var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget, buildOpts.automaticProvisioning);
var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget, buildOpts.automaticProvisioning, buildOpts.buildAction);
return superspawn.spawn('xcodebuild', xcodebuildArgs, { cwd: projectPath, printCommand: true, stdio: 'inherit' });

}).then(function () {
Expand Down Expand Up @@ -269,7 +269,7 @@ module.exports.findXCodeProjectIn = findXCodeProjectIn;
* @param {Boolean} autoProvisioning Whether to allow Xcode to automatically update provisioning
* @return {Array} Array of arguments that could be passed directly to spawn method
*/
function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, buildFlags, emulatorTarget, autoProvisioning) {
function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, buildFlags, emulatorTarget, autoProvisioning, buildAction) {
var xcodebuildArgs;
var options;
var buildActions;
Expand All @@ -295,7 +295,7 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b
'-destination', customArgs.destination || 'generic/platform=iOS',
'-archivePath', customArgs.archivePath || projectName + '.xcarchive'
];
buildActions = [ 'archive' ];
buildActions = buildAction ? [ buildAction ] : [ 'archive' ];
settings = [
customArgs.configuration_build_dir || 'CONFIGURATION_BUILD_DIR=' + path.join(projectPath, 'build', 'device'),
customArgs.shared_precomps_dir || 'SHARED_PRECOMPS_DIR=' + path.join(projectPath, 'build', 'sharedpch')
Expand Down
43 changes: 12 additions & 31 deletions bin/templates/scripts/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var Q = require('q');
var path = require('path');
var cp = require('child_process');
var build = require('./build');
var shell = require('shelljs');
var superspawn = require('cordova-common').superspawn;
var check_reqs = require('./check_reqs');

Expand Down Expand Up @@ -59,6 +58,13 @@ module.exports.run = function (runOptions) {
return check_reqs.check_ios_deploy();
}
}).then(function () {
if (useDevice) { // for device
if (!runOptions['nobuild-device']) {
return build.run(Object.assign({}, runOptions, {buildFlag: 'CONFIGURATION_BUILD_DIR=' + path.join(projectPath, 'build', 'device-run'), buildAction: 'build'}));
} else {
return Q.resolve();
}
} // for emulator
if (!runOptions.nobuild) {
return build.run(runOptions);
} else {
Expand All @@ -68,36 +74,10 @@ module.exports.run = function (runOptions) {
return build.findXCodeProjectIn(projectPath);
}).then(function (projectName) {
var appPath = path.join(projectPath, 'build', 'emulator', projectName + '.app');
var buildOutputDir = path.join(projectPath, 'build', 'device');

// select command to run and arguments depending whether
// we're running on device/emulator
if (useDevice) {
return module.exports.checkDeviceConnected()
.then(function () {
// Unpack IPA
var ipafile = path.join(buildOutputDir, projectName + '.ipa');

// unpack the existing platform/ios/build/device/appname.ipa (zipfile), will create a Payload folder
return superspawn.spawn('unzip', [ '-o', '-qq', ipafile ], { cwd: buildOutputDir, printCommand: true, stdio: 'inherit' });
})
.then(function () {
// Uncompress IPA (zip file)
var appFileInflated = path.join(buildOutputDir, 'Payload', projectName + '.app');
var appFile = path.join(buildOutputDir, projectName + '.app');
var payloadFolder = path.join(buildOutputDir, 'Payload');

// delete the existing platform/ios/build/device/appname.app
shell.rm('-rf', 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
shell.rm('-rf', payloadFolder);

return null;
})
.then(function () {
appPath = path.join(projectPath, 'build', 'device', projectName + '.app');
appPath = path.join(projectPath, 'build', 'device-run', projectName + '.app');
var extraArgs = [];
if (runOptions.argv) {
// argv.slice(2) removes node and run.js, filterSupportedArgs removes the run.js args
Expand Down Expand Up @@ -129,7 +109,7 @@ module.exports.listEmulators = listEmulators;
*/
function filterSupportedArgs (args) {
var filtered = [];
var sargs = ['--device', '--emulator', '--nobuild', '--list', '--target', '--debug', '--release'];
var sargs = ['--device', '--emulator', '--nobuild', '--nobuild-device', '--list', '--target', '--debug', '--release'];
var re = new RegExp(sargs.join('|'));

args.forEach(function (element) {
Expand Down Expand Up @@ -228,15 +208,16 @@ function listEmulators () {
}

module.exports.help = function () {
console.log('\nUsage: run [ --device | [ --emulator [ --target=<id> ] ] ] [ --debug | --release | --nobuild ]');
console.log('\nUsage: run [ --device | [ --emulator [ --target=<id> ] ] ] [ --debug | --release | --nobuild | --nobuild-device ]');
// TODO: add support for building different archs
// console.log(" [ --archs=\"<list of target architectures>\" ] ");
console.log(' --device : Deploys and runs the project on the connected device.');
console.log(' --emulator : Deploys and runs the project on an emulator.');
console.log(' --target=<id> : Deploys and runs the project on the specified target.');
console.log(' --debug : Builds project in debug mode. (Passed down to build command, if necessary)');
console.log(' --release : Builds project in release mode. (Passed down to build command, if necessary)');
console.log(' --nobuild : Uses pre-built package, or errors if project is not built.');
console.log(' --nobuild : Uses pre-built package, or errors if project is not built for emulator.');
console.log(' --nobuild-device : Uses pre-built package, or errors if project is not built for device.');
// TODO: add support for building different archs
// console.log(" --archs : Specific chip architectures (`anycpu`, `arm`, `x86`, `x64`).");
console.log('');
Expand Down