Skip to content

Commit

Permalink
use process.release, make aware of io.js & node v4 differences
Browse files Browse the repository at this point in the history
PR-URL: #711
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
rvagg committed Sep 7, 2015
1 parent 1ea7ed0 commit 9e9df66
Show file tree
Hide file tree
Showing 10 changed files with 565 additions and 120 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gyp/test
node_modules
3 changes: 2 additions & 1 deletion addon.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'product_prefix': '',

'include_dirs': [
'<(node_root_dir)/include/node',
'<(node_root_dir)/src',
'<(node_root_dir)/deps/uv/include',
'<(node_root_dir)/deps/v8/include'
Expand Down Expand Up @@ -78,7 +79,7 @@
'-luuid.lib',
'-lodbc32.lib',
'-lDelayImp.lib',
'-l"<(node_root_dir)/$(ConfigurationName)/node.lib"'
'-l"<(node_root_dir)/$(ConfigurationName)/<(node_lib_file)"'
],
'msvs_disabled_warnings': [
# warning C4251: 'node::ObjectWrap::handle_' : class 'v8::Persistent<T>'
Expand Down
11 changes: 6 additions & 5 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ var fs = require('graceful-fs')
, which = require('which')
, mkdirp = require('mkdirp')
, exec = require('child_process').exec
, processRelease = require('./process-release')
, win = process.platform == 'win32'

exports.usage = 'Invokes `' + (win ? 'msbuild' : 'make') + '` and builds the module'

function build (gyp, argv, callback) {

var makeCommand = gyp.opts.make || process.env.MAKE
var release = processRelease(argv, gyp, process.version, process.release)
, makeCommand = gyp.opts.make || process.env.MAKE
|| (process.platform.indexOf('bsd') != -1 && process.platform.indexOf('kfreebsd') == -1 ? 'gmake' : 'make')
, command = win ? 'msbuild' : makeCommand
, buildDir = path.resolve('build')
Expand Down Expand Up @@ -181,15 +182,15 @@ function build (gyp, argv, callback) {
if (!win || !copyDevLib) return doBuild()

var buildDir = path.resolve(nodeDir, buildType)
, archNodeLibPath = path.resolve(nodeDir, arch, 'node.lib')
, buildNodeLibPath = path.resolve(buildDir, 'node.lib')
, archNodeLibPath = path.resolve(nodeDir, arch, release.name + '.lib')
, buildNodeLibPath = path.resolve(buildDir, release.name + '.lib')

mkdirp(buildDir, function (err, isNew) {
if (err) return callback(err)
log.verbose('"' + buildType + '" dir needed to be created?', isNew)
var rs = fs.createReadStream(archNodeLibPath)
, ws = fs.createWriteStream(buildNodeLibPath)
log.verbose('copying "node.lib" for ' + arch, buildNodeLibPath)
log.verbose('copying "' + release.name + '.lib" for ' + arch, buildNodeLibPath)
rs.pipe(ws)
rs.on('error', callback)
ws.on('error', callback)
Expand Down
93 changes: 46 additions & 47 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var fs = require('graceful-fs')
, cp = require('child_process')
, PathArray = require('path-array')
, extend = require('util')._extend
, processRelease = require('./process-release')
, spawn = cp.spawn
, execFile = cp.execFile
, win = process.platform == 'win32'
Expand All @@ -28,6 +29,7 @@ function configure (gyp, argv, callback) {
, configNames = [ 'config.gypi', 'common.gypi' ]
, configs = []
, nodeDir
, release = processRelease(argv, gyp, process.version, process.release)

checkPython()

Expand Down Expand Up @@ -135,35 +137,25 @@ function configure (gyp, argv, callback) {

} else {
// if no --nodedir specified, ensure node dependencies are installed
var version
var versionStr

if (gyp.opts.target) {
if ('v' + release.version !== process.version) {
// if --target was given, then determine a target version to compile for
versionStr = gyp.opts.target
log.verbose('get node dir', 'compiling against --target node version: %s', versionStr)
log.verbose('get node dir', 'compiling against --target node version: %s', release.version)
} else {
// if no --target was specified then use the current host node version
versionStr = process.version
log.verbose('get node dir', 'no --target version specified, falling back to host node version: %s', versionStr)
log.verbose('get node dir', 'no --target version specified, falling back to host node version: %s', release.version)
}

// make sure we have a valid version
try {
version = semver.parse(versionStr)
} catch (e) {
return callback(e)
}
if (!version) {
return callback(new Error('Invalid version number: ' + versionStr))
if (!release.semver) {
return callback(new Error('Invalid version number: ' + release.version))
}

// ensure that the target node version's dev files are installed
gyp.opts.ensure = true
gyp.commands.install([ versionStr ], function (err, version) {
gyp.commands.install([ release.version ], function (err, version) {
if (err) return callback(err)
log.verbose('get node dir', 'target node version installed:', version)
nodeDir = path.resolve(gyp.devDir, version)
log.verbose('get node dir', 'target node version installed:', release.versionDir)
nodeDir = path.resolve(gyp.devDir, release.versionDir)
createBuildDir()
})
}
Expand Down Expand Up @@ -310,42 +302,49 @@ function configure (gyp, argv, callback) {
// this logic ported from the old `gyp_addon` python file
var gyp_script = path.resolve(__dirname, '..', 'gyp', 'gyp_main.py')
var addon_gypi = path.resolve(__dirname, '..', 'addon.gypi')
var common_gypi = path.resolve(nodeDir, 'common.gypi')
var output_dir = 'build'
if (win) {
// Windows expects an absolute path
output_dir = buildDir
}
var nodeGypDir = path.resolve(__dirname, '..')
var common_gypi = path.resolve(nodeDir, 'include/node/common.gypi')
fs.stat(common_gypi, function (err, stat) {
if (err || !stat.isFile()) {
common_gypi = path.resolve(nodeDir, 'common.gypi')
}

argv.push('-I', addon_gypi)
argv.push('-I', common_gypi)
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
argv.push('-Dnode_gyp_dir=' + nodeGypDir)
argv.push('-Dmodule_root_dir=' + process.cwd())
argv.push('--depth=.')
argv.push('--no-parallel')
var output_dir = 'build'
if (win) {
// Windows expects an absolute path
output_dir = buildDir
}
var nodeGypDir = path.resolve(__dirname, '..')

// tell gyp to write the Makefile/Solution files into output_dir
argv.push('--generator-output', output_dir)
argv.push('-I', addon_gypi)
argv.push('-I', common_gypi)
argv.push('-Dlibrary=shared_library')
argv.push('-Dvisibility=default')
argv.push('-Dnode_root_dir=' + nodeDir)
argv.push('-Dnode_gyp_dir=' + nodeGypDir)
argv.push('-Dnode_lib_file=' + release.name + '.lib')
argv.push('-Dmodule_root_dir=' + process.cwd())
argv.push('--depth=.')
argv.push('--no-parallel')

// tell make to write its output into the same dir
argv.push('-Goutput_dir=.')
// tell gyp to write the Makefile/Solution files into output_dir
argv.push('--generator-output', output_dir)

// enforce use of the "binding.gyp" file
argv.unshift('binding.gyp')
// tell make to write its output into the same dir
argv.push('-Goutput_dir=.')

// execute `gyp` from the current target nodedir
argv.unshift(gyp_script)
// enforce use of the "binding.gyp" file
argv.unshift('binding.gyp')

// make sure python uses files that came with this particular node package
var pypath = new PathArray(process.env, 'PYTHONPATH')
pypath.unshift(path.join(__dirname, '..', 'gyp', 'pylib'))
// execute `gyp` from the current target nodedir
argv.unshift(gyp_script)

var cp = gyp.spawn(python, argv)
cp.on('exit', onCpExit)
// make sure python uses files that came with this particular node package
var pypath = new PathArray(process.env, 'PYTHONPATH')
pypath.unshift(path.join(__dirname, '..', 'gyp', 'pylib'))

var cp = gyp.spawn(python, argv)
cp.on('exit', onCpExit)
})
}

/**
Expand Down
Loading

0 comments on commit 9e9df66

Please sign in to comment.