diff options
Diffstat (limited to 'deps/npm/node_modules/node-gyp/lib/build.js')
-rw-r--r-- | deps/npm/node_modules/node-gyp/lib/build.js | 102 |
1 files changed, 67 insertions, 35 deletions
diff --git a/deps/npm/node_modules/node-gyp/lib/build.js b/deps/npm/node_modules/node-gyp/lib/build.js index 3ffc4c7919..92f21336cf 100644 --- a/deps/npm/node_modules/node-gyp/lib/build.js +++ b/deps/npm/node_modules/node-gyp/lib/build.js @@ -5,12 +5,11 @@ module.exports = exports = build * Module dependencies. */ -var fs = require('fs') +var fs = require('graceful-fs') , path = require('path') , glob = require('glob') , which = require('which') - , asyncEmit = require('./util/asyncEmit') - , createHook = require('./util/hook') + , mkdirp = require('./util/mkdirp') , win = process.platform == 'win32' exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the module' @@ -21,14 +20,12 @@ function build (gyp, argv, callback) { var command = win ? 'msbuild' : 'make' , buildDir = path.resolve('build') , configPath = path.resolve(buildDir, 'config.gypi') + , buildType , config - , emitter + , arch + , version - createHook('gyp-build.js', function (err, _e) { - if (err) return callback(err) - emitter = _e - loadConfigGypi() - }) + loadConfigGypi() /** * Load the "config.gypi" file that was generated during "configure". @@ -45,6 +42,23 @@ function build (gyp, argv, callback) { return } config = JSON.parse(data.replace(/\#.+\n/, '')) + + // get the 'arch', 'buildType', and 'version' vars from the config + buildType = config.target_defaults.default_configuration + arch = config.variables.target_arch + version = config.variables.target_version + + if ('debug' in gyp.opts) { + buildType = gyp.opts.debug ? 'Debug' : 'Release' + } + if (!buildType) { + buildType = 'Release' + } + + gyp.verbose('build type:', buildType) + gyp.verbose('architecture:', arch) + gyp.verbose('node version:', version) + if (win) { findSolutionFile() } else { @@ -54,7 +68,7 @@ function build (gyp, argv, callback) { } /** - * On Windows, find first build/*.sln file. + * On Windows, find the first build/*.sln file. */ function findSolutionFile () { @@ -69,6 +83,10 @@ function build (gyp, argv, callback) { }) } + /** + * Uses node-which to locate the msbuild / make executable. + */ + function doWhich () { // First make sure we have the build command in the PATH which(command, function (err, execPath) { @@ -83,7 +101,7 @@ function build (gyp, argv, callback) { return } gyp.verbose('`which` succeeded for `' + command + '`', execPath) - build() + copyNodeLib() }) } @@ -109,21 +127,40 @@ function build (gyp, argv, callback) { return } command = msbuild - build() + copyNodeLib() }) } /** - * Actually spawn the process and compile the module. + * Copies the node.lib file for the current target architecture into the + * current proper dev dir location. */ - function build () { - var buildType = config.target_defaults.default_configuration - , platform = config.variables.target_arch == 'x64' ? '64' : '32' + function copyNodeLib () { + if (!win) return doBuild() - if (gyp.opts.debug) { - buildType = 'Debug' - } + var devDir = path.resolve(gyp.devDir, version) + , buildDir = path.resolve(devDir, buildType) + , archNodeLibPath = path.resolve(devDir, arch, 'node.lib') + , buildNodeLibPath = path.resolve(buildDir, 'node.lib') + + mkdirp(buildDir, function (err, isNew) { + if (err) return callback(err) + gyp.verbose('"' + buildType + '" dir needed to be created?', isNew) + var rs = fs.createReadStream(archNodeLibPath) + , ws = fs.createWriteStream(buildNodeLibPath) + rs.pipe(ws) + rs.on('error', callback) + ws.on('error', callback) + rs.on('end', doBuild) + }) + } + + /** + * Actually spawn the process and compile the module. + */ + + function doBuild () { // Enable Verbose build if (!win && gyp.opts.verbose) { @@ -140,7 +177,8 @@ function build (gyp, argv, callback) { // Specify the build type, Release by default if (win) { - argv.push('/p:Configuration=' + buildType + ';Platform=Win' + platform) + var p = arch === 'x64' ? 'x64' : 'Win32' + argv.push('/p:Configuration=' + buildType + ';Platform=' + p) } else { argv.push('BUILDTYPE=' + buildType) // Invoke the Makefile in the 'build' dir. @@ -158,11 +196,8 @@ function build (gyp, argv, callback) { } } - asyncEmit(emitter, 'before', function (err) { - if (err) return callback(err) - var proc = gyp.spawn(command, argv) - proc.on('exit', onExit) - }) + var proc = gyp.spawn(command, argv) + proc.on('exit', onExit) } /** @@ -170,16 +205,13 @@ function build (gyp, argv, callback) { */ function onExit (code, signal) { - asyncEmit(emitter, 'after', function (err) { - if (err) return callback(err) - if (code !== 0) { - return callback(new Error('`' + command + '` failed with exit code: ' + code)) - } - if (signal) { - return callback(new Error('`' + command + '` got signal: ' + signal)) - } - callback() - }) + if (code !== 0) { + return callback(new Error('`' + command + '` failed with exit code: ' + code)) + } + if (signal) { + return callback(new Error('`' + command + '` got signal: ' + signal)) + } + callback() } } |