diff options
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/build.js')
| -rwxr-xr-x | StoneIsland/platforms/ios/cordova/lib/build.js | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/build.js b/StoneIsland/platforms/ios/cordova/lib/build.js index c40bfe8b..29d808ab 100755 --- a/StoneIsland/platforms/ios/cordova/lib/build.js +++ b/StoneIsland/platforms/ios/cordova/lib/build.js @@ -53,7 +53,33 @@ var buildFlagMatchers = { 'shared_precomps_dir' : /^(SHARED_PRECOMPS_DIR=.*)/ }; +/** + * Returns a promise that resolves to the default simulator target; the logic here + * matches what `cordova emulate ios` does. + * + * The return object has two properties: `name` (the Xcode destination name), + * `identifier` (the simctl identifier), and `simIdentifier` (essentially the cordova emulate target) + * + * @return {Promise} + */ +function getDefaultSimulatorTarget() { + return require('./list-emulator-build-targets').run() + .then(function (emulators) { + var targetEmulator; + if (emulators.length > 0) { + targetEmulator = emulators[0]; + } + emulators.forEach(function (emulator) { + if (emulator.name.indexOf('iPhone') === 0) { + targetEmulator = emulator; + } + }); + return targetEmulator; + }); +} + module.exports.run = function (buildOpts) { + var emulatorTarget = ''; buildOpts = buildOpts || {}; @@ -93,6 +119,22 @@ return require('./list-devices').run() return check_reqs.check_ios_deploy(); } }).then(function () { + // CB-12287: Determine the device we should target when building for a simulator + if (!buildOpts.device) { + var promise; + if (buildOpts.target) { + // a target was given to us, find the matching Xcode destination name + promise = require('./list-emulator-build-targets').targetForSimIdentifier(buildOpts.target); + } else { + // no target provided, pick a default one (matching our emulator logic) + promise = getDefaultSimulatorTarget(); + } + return promise.then(function(theTarget) { + emulatorTarget = theTarget.name; + events.emit('log', 'Building for ' + emulatorTarget + ' Simulator'); + }); + } + }).then(function () { return check_reqs.run(); }).then(function () { return findXCodeProjectIn(projectPath); @@ -120,12 +162,12 @@ return require('./list-devices').run() events.emit('log','\tConfiguration: ' + configuration); events.emit('log','\tPlatform: ' + (buildOpts.device ? 'device' : 'emulator')); - var buildOutputDir = path.join(projectPath, 'build', 'device'); + var buildOutputDir = path.join(projectPath, 'build', (buildOpts.device ? 'device' : 'emulator')); // remove the build/device folder before building return spawn('rm', [ '-rf', buildOutputDir ], projectPath) .then(function() { - var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag); + var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget); return spawn('xcodebuild', xcodebuildArgs, projectPath); }); @@ -165,35 +207,9 @@ return require('./list-devices').run() return spawn('xcodebuild', xcodearchiveArgs, projectPath); } - function unpackIPA() { - var ipafile = path.join(buildOutputDir, projectName + '.ipa'); - - // unpack the existing platform/ios/build/device/appname.ipa (zipfile), will create a Payload folder - return spawn('unzip', [ '-o', '-qq', ipafile ], buildOutputDir); - } - - function moveApp() { - 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 - return spawn('rm', [ '-rf', appFile ], buildOutputDir) - .then(function() { - // move the platform/ios/build/device/Payload/appname.app to parent - return spawn('mv', [ '-f', appFileInflated, buildOutputDir ], buildOutputDir); - }) - .then(function() { - // delete the platform/ios/build/device/Payload folder - return spawn('rm', [ '-rf', payloadFolder ], buildOutputDir); - }); - } - return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8') .then(checkSystemRuby) - .then(packageArchive) - .then(unpackIPA) - .then(moveApp); + .then(packageArchive); }); }; @@ -224,13 +240,15 @@ module.exports.findXCodeProjectIn = findXCodeProjectIn; /** * Returns array of arguments for xcodebuild - * @param {String} projectName Name of xcode project - * @param {String} projectPath Path to project file. Will be used to set CWD for xcodebuild - * @param {String} configuration Configuration name: debug|release - * @param {Boolean} isDevice Flag that specify target for package (device/emulator) - * @return {Array} Array of arguments that could be passed directly to spawn method + * @param {String} projectName Name of xcode project + * @param {String} projectPath Path to project file. Will be used to set CWD for xcodebuild + * @param {String} configuration Configuration name: debug|release + * @param {Boolean} isDevice Flag that specify target for package (device/emulator) + * @param {Array} buildFlags + * @param {String} emulatorTarget Target for emulator (rather than default) + * @return {Array} Array of arguments that could be passed directly to spawn method */ -function getXcodeBuildArgs(projectName, projectPath, configuration, isDevice, buildFlags) { +function getXcodeBuildArgs(projectName, projectPath, configuration, isDevice, buildFlags, emulatorTarget) { var xcodebuildArgs; var options; var buildActions; @@ -274,7 +292,7 @@ function getXcodeBuildArgs(projectName, projectPath, configuration, isDevice, bu '-scheme', customArgs.scheme || projectName, '-configuration', customArgs.configuration || configuration, '-sdk', customArgs.sdk || 'iphonesimulator', - '-destination', customArgs.destination || 'platform=iOS Simulator,name=iPhone 5s' + '-destination', customArgs.destination || 'platform=iOS Simulator,name=' + emulatorTarget ]; buildActions = [ 'build' ]; settings = [ @@ -341,6 +359,7 @@ module.exports.help = function help() { console.log('Usage: build [--debug | --release] [--archs=\"<list of architectures...>\"]'); console.log(' [--device | --simulator] [--codeSignIdentity=\"<identity>\"]'); console.log(' [--codeSignResourceRules=\"<resourcerules path>\"]'); + console.log(' [--developmentTeam=\"<Team ID>\"]'); console.log(' [--provisioningProfile=\"<provisioning profile>\"]'); console.log(' --help : Displays this dialog.'); console.log(' --debug : Builds project in debug mode. (Default)'); @@ -352,6 +371,8 @@ module.exports.help = function help() { console.log(' : Specifies, what type of project to build'); console.log(' --codeSignIdentity : Type of signing identity used for code signing.'); console.log(' --codeSignResourceRules : Path to ResourceRules.plist.'); + console.log(' --developmentTeam : New for Xcode 8. The development team (Team ID)'); + console.log(' to use for code signing.'); console.log(' --provisioningProfile : UUID of the profile.'); console.log(' --device --noSign : Builds project without application signing.'); console.log(''); |
