diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-10-26 01:41:16 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-10-26 01:41:16 +0200 |
| commit | 8dae6a5044f9c1b7a8497cc1c96155fd262b40cf (patch) | |
| tree | 6f546503efcb198a193f919efafb83977abb9535 /StoneIsland/platforms/ios/cordova/lib/build.js | |
| parent | 531c60ee7ecbee516812d560b63a8317c3cf3590 (diff) | |
iphone x fixes
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/build.js')
| -rwxr-xr-x | StoneIsland/platforms/ios/cordova/lib/build.js | 315 |
1 files changed, 169 insertions, 146 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/build.js b/StoneIsland/platforms/ios/cordova/lib/build.js index 29d808ab..f51b084c 100755 --- a/StoneIsland/platforms/ios/cordova/lib/build.js +++ b/StoneIsland/platforms/ios/cordova/lib/build.js @@ -17,23 +17,16 @@ * under the License. */ -/*jshint node: true*/ +var Q = require('q'); +var path = require('path'); +var shell = require('shelljs'); +var spawn = require('./spawn'); +var fs = require('fs'); +var plist = require('plist'); +var util = require('util'); -var Q = require('q'), - path = require('path'), - shell = require('shelljs'), - spawn = require('./spawn'), - fs = require('fs'), - plist = require('plist'), - util = require('util'); - -var check_reqs; -try { - check_reqs = require('./check_reqs'); -} catch (err) { - // For unit tests, check_reqs.js is not a sibling to build.js - check_reqs = require('../../../../lib/check_reqs'); -} +var check_reqs = require('./check_reqs'); +var projectFile = require('./projectFile'); var events = require('cordova-common').events; @@ -41,41 +34,43 @@ 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 = { - 'xcconfig' : /^\-xcconfig\s*(.*)$/, - 'workspace' : /^\-workspace\s*(.*)/, - 'scheme' : /^\-scheme\s*(.*)/, - 'configuration' : /^\-configuration\s*(.*)/, - 'sdk' : /^\-sdk\s*(.*)/, - 'destination' : /^\-destination\s*(.*)/, - 'archivePath' : /^\-archivePath\s*(.*)/, - 'configuration_build_dir' : /^(CONFIGURATION_BUILD_DIR=.*)/, - 'shared_precomps_dir' : /^(SHARED_PRECOMPS_DIR=.*)/ + 'xcconfig': /^\-xcconfig\s*(.*)$/, + 'workspace': /^\-workspace\s*(.*)/, + 'scheme': /^\-scheme\s*(.*)/, + 'configuration': /^\-configuration\s*(.*)/, + 'sdk': /^\-sdk\s*(.*)/, + 'destination': /^\-destination\s*(.*)/, + 'archivePath': /^\-archivePath\s*(.*)/, + 'configuration_build_dir': /^(CONFIGURATION_BUILD_DIR=.*)/, + 'shared_precomps_dir': /^(SHARED_PRECOMPS_DIR=.*)/ }; +/* eslint-enable no-useless-escape */ /** * Returns a promise that resolves to the default simulator target; the logic here - * matches what `cordova emulate ios` does. - * + * 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() { +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; + .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; }); - return targetEmulator; - }); } module.exports.run = function (buildOpts) { @@ -91,126 +86,153 @@ module.exports.run = function (buildOpts) { return Q.reject('Cannot specify "device" and "emulator" options together.'); } - if(buildOpts.buildConfig) { - if(!fs.existsSync(buildOpts.buildConfig)) { + if (buildOpts.buildConfig) { + if (!fs.existsSync(buildOpts.buildConfig)) { return Q.reject('Build config file does not exist:' + buildOpts.buildConfig); } - events.emit('log','Reading build config file:', path.resolve(buildOpts.buildConfig)); + events.emit('log', 'Reading build config file:', path.resolve(buildOpts.buildConfig)); var contents = fs.readFileSync(buildOpts.buildConfig, 'utf-8'); var buildConfig = JSON.parse(contents.replace(/^\ufeff/, '')); // Remove BOM - if(buildConfig.ios) { + if (buildConfig.ios) { var buildType = buildOpts.release ? 'release' : 'debug'; var config = buildConfig.ios[buildType]; - if(config) { - ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag'].forEach( - function(key) { + if (config) { + ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment'].forEach( + function (key) { buildOpts[key] = buildOpts[key] || config[key]; }); } } } -return require('./list-devices').run() - .then(function (devices) { - if (devices.length > 0 && !(buildOpts.emulator)) { - // we also explicitly set device flag in options as we pass - // those parameters to other api (build as an example) - buildOpts.device = true; - 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) { + return require('./list-devices').run() + .then(function (devices) { + if (devices.length > 0 && !(buildOpts.emulator)) { + // we also explicitly set device flag in options as we pass + // those parameters to other api (build as an example) + buildOpts.device = true; + 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 newTarget = buildOpts.target || ''; + + if (newTarget) { + // only grab the device name, not the runtime specifier + newTarget = newTarget.split(',')[0]; + } // 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(); + var promise = require('./list-emulator-build-targets').targetForSimIdentifier(newTarget); + return promise.then(function (theTarget) { + if (!theTarget) { + return getDefaultSimulatorTarget().then(function (defaultTarget) { + emulatorTarget = defaultTarget.name; + events.emit('log', 'Building for ' + emulatorTarget + ' Simulator'); + return emulatorTarget; + }); + } else { + emulatorTarget = theTarget.name; + events.emit('log', 'Building for ' + emulatorTarget + ' Simulator'); + return emulatorTarget; + } + }); } - 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); - }).then(function (name) { - projectName = name; - var extraConfig = ''; - if (buildOpts.codeSignIdentity) { - extraConfig += 'CODE_SIGN_IDENTITY = ' + buildOpts.codeSignIdentity + '\n'; - extraConfig += 'CODE_SIGN_IDENTITY[sdk=iphoneos*] = ' + buildOpts.codeSignIdentity + '\n'; - } - if (buildOpts.codeSignResourceRules) { - extraConfig += 'CODE_SIGN_RESOURCE_RULES_PATH = ' + buildOpts.codeSignResourceRules + '\n'; - } - if (buildOpts.provisioningProfile) { - extraConfig += 'PROVISIONING_PROFILE = ' + buildOpts.provisioningProfile + '\n'; - } - if (buildOpts.developmentTeam) { - extraConfig += 'DEVELOPMENT_TEAM = ' + buildOpts.developmentTeam + '\n'; - } - return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8'); - }).then(function () { - var configuration = buildOpts.release ? 'Release' : 'Debug'; + }).then(function () { + return check_reqs.run(); + }).then(function () { + return findXCodeProjectIn(projectPath); + }).then(function (name) { + projectName = name; + var extraConfig = ''; + if (buildOpts.codeSignIdentity) { + extraConfig += 'CODE_SIGN_IDENTITY = ' + buildOpts.codeSignIdentity + '\n'; + extraConfig += 'CODE_SIGN_IDENTITY[sdk=iphoneos*] = ' + buildOpts.codeSignIdentity + '\n'; + } + if (buildOpts.codeSignResourceRules) { + extraConfig += 'CODE_SIGN_RESOURCE_RULES_PATH = ' + buildOpts.codeSignResourceRules + '\n'; + } + if (buildOpts.provisioningProfile) { + extraConfig += 'PROVISIONING_PROFILE = ' + buildOpts.provisioningProfile + '\n'; + } + if (buildOpts.developmentTeam) { + extraConfig += 'DEVELOPMENT_TEAM = ' + buildOpts.developmentTeam + '\n'; + } + return Q.nfcall(fs.writeFile, path.join(__dirname, '..', 'build-extras.xcconfig'), extraConfig, 'utf-8'); + }).then(function () { + var configuration = buildOpts.release ? 'Release' : 'Debug'; - events.emit('log','Building project: ' + path.join(projectPath, projectName + '.xcworkspace')); - events.emit('log','\tConfiguration: ' + configuration); - events.emit('log','\tPlatform: ' + (buildOpts.device ? 'device' : 'emulator')); + events.emit('log', 'Building project: ' + path.join(projectPath, projectName + '.xcworkspace')); + events.emit('log', '\tConfiguration: ' + configuration); + events.emit('log', '\tPlatform: ' + (buildOpts.device ? 'device' : 'emulator')); - var buildOutputDir = path.join(projectPath, 'build', (buildOpts.device ? 'device' : 'emulator')); + 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, emulatorTarget); - return spawn('xcodebuild', xcodebuildArgs, projectPath); - }); + // 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, emulatorTarget); + return spawn('xcodebuild', xcodebuildArgs, projectPath); + }); - }).then(function () { - if (!buildOpts.device || buildOpts.noSign) { - return; - } + }).then(function () { + if (!buildOpts.device || buildOpts.noSign) { + return; + } - var exportOptions = {'compileBitcode': false, 'method': 'development'}; + var locations = { + root: projectPath, + pbxproj: path.join(projectPath, projectName + '.xcodeproj', 'project.pbxproj') + }; - if (buildOpts.packageType) { - exportOptions.method = buildOpts.packageType; - } + var bundleIdentifier = projectFile.parse(locations).getPackageName(); + var exportOptions = {'compileBitcode': false, 'method': 'development'}; - if (buildOpts.developmentTeam) { - exportOptions.teamID = buildOpts.developmentTeam; - } + if (buildOpts.packageType) { + exportOptions.method = buildOpts.packageType; + } - var exportOptionsPlist = plist.build(exportOptions); - var exportOptionsPath = path.join(projectPath, 'exportOptions.plist'); + if (buildOpts.iCloudContainerEnvironment) { + exportOptions.iCloudContainerEnvironment = buildOpts.iCloudContainerEnvironment; + } - var buildOutputDir = path.join(projectPath, 'build', 'device'); + if (buildOpts.developmentTeam) { + exportOptions.teamID = buildOpts.developmentTeam; + } + if (buildOpts.provisioningProfile && bundleIdentifier) { + exportOptions.provisioningProfiles = { [ bundleIdentifier ]: String(buildOpts.provisioningProfile) }; + exportOptions.signingStyle = 'manual'; + } - function checkSystemRuby() { - var ruby_cmd = shell.which('ruby'); + if (buildOpts.codeSignIdentity) { + exportOptions.signingCertificate = buildOpts.codeSignIdentity; + } - if (ruby_cmd != '/usr/bin/ruby') { - events.emit('warn', 'Non-system Ruby in use. This may cause packaging to fail.\n' + - 'If you use RVM, please run `rvm use system`.\n' + - 'If you use chruby, please run `chruby system`.'); - } - } + var exportOptionsPlist = plist.build(exportOptions); + var exportOptionsPath = path.join(projectPath, 'exportOptions.plist'); - function packageArchive() { - var xcodearchiveArgs = getXcodeArchiveArgs(projectName, projectPath, buildOutputDir, exportOptionsPath); - return spawn('xcodebuild', xcodearchiveArgs, projectPath); - } + var buildOutputDir = path.join(projectPath, 'build', 'device'); + + function checkSystemRuby () { + var ruby_cmd = shell.which('ruby'); + + if (ruby_cmd !== '/usr/bin/ruby') { + events.emit('warn', 'Non-system Ruby in use. This may cause packaging to fail.\n' + + 'If you use RVM, please run `rvm use system`.\n' + + 'If you use chruby, please run `chruby system`.'); + } + } + + function packageArchive () { + var xcodearchiveArgs = getXcodeArchiveArgs(projectName, projectPath, buildOutputDir, exportOptionsPath); + return spawn('xcodebuild', xcodearchiveArgs, projectPath); + } - return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8') + return Q.nfcall(fs.writeFile, exportOptionsPath, exportOptionsPlist, 'utf-8') .then(checkSystemRuby) .then(packageArchive); - }); + }); }; /** @@ -218,7 +240,7 @@ return require('./list-devices').run() * @param {String} projectPath Path where to search project * @return {Promise} Promise either fulfilled with project name or rejected */ -function findXCodeProjectIn(projectPath) { +function findXCodeProjectIn (projectPath) { // 'Searching for Xcode project in ' + projectPath); var xcodeProjFiles = shell.ls(projectPath).filter(function (name) { return path.extname(name) === '.xcodeproj'; @@ -228,7 +250,7 @@ function findXCodeProjectIn(projectPath) { return Q.reject('No Xcode project found in ' + projectPath); } if (xcodeProjFiles.length > 1) { - events.emit('warn','Found multiple .xcodeproj directories in \n' + + events.emit('warn', 'Found multiple .xcodeproj directories in \n' + projectPath + '\nUsing first one'); } @@ -248,7 +270,7 @@ module.exports.findXCodeProjectIn = findXCodeProjectIn; * @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, emulatorTarget) { +function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, buildFlags, emulatorTarget) { var xcodebuildArgs; var options; var buildActions; @@ -260,16 +282,16 @@ function getXcodeBuildArgs(projectName, projectPath, configuration, isDevice, bu if (typeof buildFlags === 'string' || buildFlags instanceof String) { parseBuildFlag(buildFlags, customArgs); } else { // buildFlags is an Array of strings - buildFlags.forEach( function(flag) { + buildFlags.forEach(function (flag) { parseBuildFlag(flag, customArgs); }); } } - + if (isDevice) { options = [ '-xcconfig', customArgs.xcconfig || path.join(__dirname, '..', 'build-' + configuration.toLowerCase() + '.xcconfig'), - '-workspace', customArgs.workspace || projectName + '.xcworkspace', + '-workspace', customArgs.workspace || projectName + '.xcworkspace', '-scheme', customArgs.scheme || projectName, '-configuration', customArgs.configuration || configuration, '-destination', customArgs.destination || 'generic/platform=iOS', @@ -309,7 +331,6 @@ function getXcodeBuildArgs(projectName, projectPath, configuration, isDevice, bu return xcodebuildArgs; } - /** * Returns array of arguments for xcodebuild * @param {String} projectName Name of xcode project @@ -318,16 +339,16 @@ function getXcodeBuildArgs(projectName, projectPath, configuration, isDevice, bu * @param {String} exportOptionsPath Path to the exportOptions.plist file * @return {Array} Array of arguments that could be passed directly to spawn method */ -function getXcodeArchiveArgs(projectName, projectPath, outputPath, exportOptionsPath) { - return [ - '-exportArchive', - '-archivePath', projectName + '.xcarchive', - '-exportOptionsPlist', exportOptionsPath, - '-exportPath', outputPath - ]; +function getXcodeArchiveArgs (projectName, projectPath, outputPath, exportOptionsPath) { + return [ + '-exportArchive', + '-archivePath', projectName + '.xcarchive', + '-exportOptionsPlist', exportOptionsPath, + '-exportPath', outputPath + ]; } -function parseBuildFlag(buildFlag, args) { +function parseBuildFlag (buildFlag, args) { var matched; for (var key in buildFlagMatchers) { var found = buildFlag.match(buildFlagMatchers[key]); @@ -342,7 +363,8 @@ function parseBuildFlag(buildFlag, args) { if (!matched) { // If the flag starts with a '-' then it is an xcodebuild built-in option or a // user-defined setting. The regex makes sure that we don't split a user-defined - // setting that is wrapped in quotes. + // setting that is wrapped in quotes. + /* eslint-disable no-useless-escape */ if (buildFlag[0] === '-' && !buildFlag.match(/^.*=(\".*\")|(\'.*\')$/)) { args.otherFlags = args.otherFlags.concat(buildFlag.split(' ')); events.emit('warn', util.format('Adding xcodebuildArg: %s', buildFlag.split(' '))); @@ -354,7 +376,7 @@ function parseBuildFlag(buildFlag, args) { } // help/usage function -module.exports.help = function help() { +module.exports.help = function help () { console.log(''); console.log('Usage: build [--debug | --release] [--archs=\"<list of architectures...>\"]'); console.log(' [--device | --simulator] [--codeSignIdentity=\"<identity>\"]'); @@ -365,6 +387,7 @@ module.exports.help = function help() { console.log(' --debug : Builds project in debug mode. (Default)'); console.log(' --release : Builds project in release mode.'); console.log(' -r : Shortcut :: builds project in release mode.'); + /* eslint-enable no-useless-escape */ // TODO: add support for building different archs // console.log(" --archs : Builds project binaries for specific chip architectures (`anycpu`, `arm`, `x86`, `x64`)."); console.log(' --device, --simulator'); |
