diff --git a/bin/node-gyp.js b/bin/node-gyp.js index f4d2f1e..589c857 100755 --- a/bin/node-gyp.js +++ b/bin/node-gyp.js @@ -10,10 +10,18 @@ process.title = 'node-gyp' * Module dependencies. */ -var gyp = require('../lib/node-gyp')() +var gyp = require('../lib/node-gyp') /** * Process and execute the selected command. */ -gyp.run(process.argv, function () {}) +var prog = gyp() +prog.run(process.argv, function (err) { + if (err) throw err +}) +prog.on('spawn', function (command, args, proc) { + //console.error('spawn', command, args) + proc.stdout.pipe(process.stdout, { end: false }) + proc.stderr.pipe(process.stderr, { end: false }) +}) diff --git a/lib/build.js b/lib/build.js index 32bfe74..e3fb9cf 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,6 +1,42 @@ module.exports = exports = build -function build (argv) { +/** + * Module dependencies. + */ +var which = require('which') + , win = process.platform == 'win32' + +function build (gyp, argv, callback) { + + console.error('build') + + var command + + if (win) { + // invoke "msbuild" + command = 'msbuild' + } else { + // invoke "make" + command = 'make' + } + + // First make sure we have the build command in the PATH + which(command, function (err, execPath) { + if (err) return callback(err) + //console.error(execPath) + + var args = [] + + // Enable Verbose build + if (gyp.opts.verbose) { + args.push('V=1') + } + + // Specify the build type, Release by default + args.push('BUILDTYPE=' + (gyp.opts.debug ? 'Debug' : 'Release')) + + var proc = gyp.spawn(command, args) + }) } diff --git a/lib/configure.js b/lib/configure.js index b18856c..99e981f 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -6,7 +6,6 @@ module.exports = exports = configure */ var path = require('path') - , spawn = require('child_process').spawn , win = process.platform == 'win32' exports.usage = 'Creates the project files to build the native addon.' @@ -17,24 +16,32 @@ function configure (gyp, argv, callback) { //console.error(argv) //console.error(gyp.argv) - // TODO: Detect and add support for a "current" dev version, - // so `target` would be implicit. - var target = String(gyp.opts.target) - , devDir = path.join(process.env.HOME, '.node-gyp', target) - , gyp_addon = path.join(devDir, 'tools', 'gyp_addon') + gyp.commands.install(['0.7'], go) + + function go () { + console.error('starting "configure"') + + // TODO: Detect and add support for a "current" dev version, + // so `target` would be implicit. + var target = String(gyp.opts.target) + , devDir = path.join(process.env.HOME, '.node-gyp', target) + , gyp_addon = path.join(devDir, 'tools', 'gyp_addon') + + // Force the 'make' target for non-Windows + if (!win) { + argv.unshift('make') + argv.unshift('-f') + } + + console.error(gyp_addon) + var cp = gyp.spawn(gyp_addon, argv) + + cp.on('exit', function (code, signal) { + if (code !== 0) { + callback(new Error('gyp_addon failed with exit code: ' + code)) + } + }) - // Force the 'make' target for non-Windows - if (!win) { - argv.unshift('make') - argv.unshift('-f') } - var cp = spawn(gyp_addon, argv, { - customFds: [ 0, 1, 2 ] - }) - - cp.on('end', function () { - console.error('end') - }) - } diff --git a/lib/install.js b/lib/install.js index 5c09940..916935a 100644 --- a/lib/install.js +++ b/lib/install.js @@ -32,11 +32,16 @@ function install (gyp, argv, callback) { // now download the node tarball // TODO: download the newest version instead of the .0 release var tarballUrl = distUrl + '/v' + version + '.0/node-v' + version + '.0.tar.gz' + , parser = tar.Parse() console.error('downloading:', tarballUrl) request(tarballUrl, downloadError) .pipe(zlib.createGunzip()) - .pipe(tar.Parse()) - .on('entry', onEntry) + .pipe(parser) + parser.on('entry', onEntry) + parser.on('end', function () { + // TODO: Ensure no multiple-callback + callback() + }) // something went wrong downloading the tarball? function downloadError (err, res) { diff --git a/lib/node-gyp.js b/lib/node-gyp.js index 7794dca..e2b4dc1 100644 --- a/lib/node-gyp.js +++ b/lib/node-gyp.js @@ -74,7 +74,7 @@ proto.parseArgv = function parseOpts (argv) { proto.spawn = function spawn () { var cp = child_process.spawn.apply(child_process, arguments) - this.emit('spawn', cp) + this.emit('spawn', arguments[0], arguments[1], cp) return cp }