Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add io.js support #564

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test: build-buffertools build-leveldown

build-buffertools:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and build-leveldown should probably depend on an npm install task if you want these tests to be self-contained for CI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

howso? that's why they are in devDependencies, doesn't that suffice?

cd node_modules/buffertools/ && \
../../bin/node-gyp.js rebuild

build-leveldown:
cd node_modules/leveldown/ && \
../../bin/node-gyp.js rebuild

test-docker-node:
docker run \
--rm=true -i -v `pwd`:/opt/node-gyp/ \
nodesource/node:wheezy \
bash -c 'rm -rf /root/.node-gyp/ && cd /opt/node-gyp && make test'

test-docker-iojs:
docker run \
--rm=true -i -v `pwd`:/opt/node-gyp/ \
iojs/iojs:1.0 \
bash -c 'rm -rf /root/.node-gyp/ && cd /opt/node-gyp && make test'

test-docker: test-docker-node test-docker-iojs
8 changes: 5 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var fs = require('graceful-fs')
, mkdirp = require('mkdirp')
, exec = require('child_process').exec
, win = process.platform == 'win32'
, semver = require('semver')
, runtime = semver.parse(process.version).major < 1 ? 'node' : 'iojs'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be a problem when node v1 is released?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can there be an override for this as an env variable? e.g. tcr/pangyp@b9209b8

If I want to enable gyp configure --target=1.3.0 and gyp configure --target=0.12.0, I'd rather not have to install both iojs and node, just to alter the meaning of process.version.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in iojs you can check for process.release.name.
in nodejs process.release doesn't even exist, yet.

To set as a target I would recommend to use same notation as nvm: gyp configure --target=iojs-v3.0.0


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

Expand Down Expand Up @@ -181,15 +183,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, runtime + '.lib')
, buildNodeLibPath = path.resolve(buildDir, runtime + '.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 "' + runtime + '.lib" for ' + arch, buildNodeLibPath)
rs.pipe(ws)
rs.on('error', callback)
ws.on('error', callback)
Expand Down
44 changes: 24 additions & 20 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var fs = require('graceful-fs')
, minimatch = require('minimatch')
, mkdir = require('mkdirp')
, win = process.platform == 'win32'
, runtime = semver.parse(process.version).major < 1 ? 'node' : 'iojs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longer-term, I'd really like to see iojs add an "iojs" property to process.versions so this test, which feels like a flaky heuristic that somebody, somewhere is going to forget about at some point, with unpredictable, but probably dire, consequences, can go away.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This is pretty lame.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion here nodejs/node#491

, defaultDisturl = runtime == 'node' ? 'http://nodejs.org/dist' : 'https://iojs.org/dist'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea to support nvm custom dist url env by default? https://github.com/creationix/nvm/blob/master/nvm.sh#L73

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fengmk2 would this be to support mirrors, like in China? I'm tinkering around in there currently and it wouldn't be hard to bring in custom URLs from where my local version is at.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only for mirrors, but also can be used in private NPM services. @rvagg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvagg yes, it will be very helpful for us.

function install (gyp, argv, callback) {

Expand All @@ -39,7 +41,7 @@ function install (gyp, argv, callback) {
}
}

var distUrl = gyp.opts['dist-url'] || gyp.opts.disturl || 'http://nodejs.org/dist'
var distUrl = gyp.opts['dist-url'] || gyp.opts.disturl || defaultDisturl


// Determine which node dev files version we are installing
Expand Down Expand Up @@ -185,7 +187,7 @@ function install (gyp, argv, callback) {

// now download the node tarball
var tarPath = gyp.opts['tarball']
var tarballUrl = tarPath ? tarPath : distUrl + '/v' + version + '/node-v' + version + '.tar.gz'
var tarballUrl = tarPath ? tarPath : distUrl + '/v' + version + '/' + runtime + '-v' + version + '.tar.gz'
, badDownload = false
, extractCount = 0
, gunzip = zlib.createGunzip()
Expand Down Expand Up @@ -343,36 +345,38 @@ function install (gyp, argv, callback) {
}

function downloadNodeLib (done) {
log.verbose('on Windows; need to download `node.lib`...')
log.verbose('on Windows; need to download `' + runtime + '.lib`...')
var dir32 = path.resolve(devDir, 'ia32')
, dir64 = path.resolve(devDir, 'x64')
, nodeLibPath32 = path.resolve(dir32, 'node.lib')
, nodeLibPath64 = path.resolve(dir64, 'node.lib')
, nodeLibUrl32 = distUrl + '/v' + version + '/node.lib'
, nodeLibUrl64 = distUrl + '/v' + version + '/x64/node.lib'

log.verbose('32-bit node.lib dir', dir32)
log.verbose('64-bit node.lib dir', dir64)
log.verbose('`node.lib` 32-bit url', nodeLibUrl32)
log.verbose('`node.lib` 64-bit url', nodeLibUrl64)
, nodeLibPath32 = path.resolve(dir32, runtime + '.lib')
, nodeLibPath64 = path.resolve(dir64, runtime + '.lib')
, nodeLibUrlFile32 = (runtime == 'node' ? 'node.lib' : 'win-x86/iojs.lib')
, nodeLibUrlFile64 = (runtime == 'node' ? 'x64/node.lib' : 'win-x64/iojs.lib')
, nodeLibUrl32 = distUrl + '/v' + version + '/' + nodeLibUrlFile32
, nodeLibUrl64 = distUrl + '/v' + version + '/' + nodeLibUrlFile64

log.verbose('32-bit ' + runtime + '.lib dir', dir32)
log.verbose('64-bit ' + runtime + '.lib dir', dir64)
log.verbose('`' + runtime + '.lib` 32-bit url', nodeLibUrl32)
log.verbose('`' + runtime + '.lib` 64-bit url', nodeLibUrl64)

var async = 2
mkdir(dir32, function (err) {
if (err) return done(err)
log.verbose('streaming 32-bit node.lib to:', nodeLibPath32)
log.verbose('streaming 32-bit ' + runtime + '.lib to:', nodeLibPath32)

var req = download(nodeLibUrl32)
if (!req) return
req.on('error', done)
req.on('response', function (res) {
if (res.statusCode !== 200) {
done(new Error(res.statusCode + ' status code downloading 32-bit node.lib'))
done(new Error(res.statusCode + ' status code downloading 32-bit ' + runtime + '.lib'))
return
}

getContentSha(res, function (_, checksum) {
contentShasums['node.lib'] = checksum
log.verbose('content checksum', 'node.lib', checksum)
contentShasums[nodeLibUrlFile32] = checksum
log.verbose('content checksum', nodeLibUrlFile32, checksum)
})

var ws = fs.createWriteStream(nodeLibPath32)
Expand All @@ -385,20 +389,20 @@ function install (gyp, argv, callback) {
})
mkdir(dir64, function (err) {
if (err) return done(err)
log.verbose('streaming 64-bit node.lib to:', nodeLibPath64)
log.verbose('streaming 64-bit ' + runtime + '.lib to:', nodeLibPath64)

var req = download(nodeLibUrl64)
if (!req) return
req.on('error', done)
req.on('response', function (res) {
if (res.statusCode !== 200) {
done(new Error(res.statusCode + ' status code downloading 64-bit node.lib'))
done(new Error(res.statusCode + ' status code downloading 64-bit ' + runtime + '.lib'))
return
}

getContentSha(res, function (_, checksum) {
contentShasums['x64/node.lib'] = checksum
log.verbose('content checksum', 'x64/node.lib', checksum)
contentShasums[nodeLibUrlFile64] = checksum
log.verbose('content checksum', nodeLibUrlFile64, checksum)
})

var ws = fs.createWriteStream(nodeLibPath64)
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@
},
"engines": {
"node": ">= 0.8.0"
},
"devDependencies": {
"buffertools": "~2.1.2",
"leveldown": "~1.0.1"
}
}