From 9e9df66a06e80fe8274d72a7b917002dcc592992 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 4 Sep 2015 23:15:06 +1000 Subject: [PATCH] use process.release, make aware of io.js & node v4 differences PR-URL: https://github.com/nodejs/node-gyp/pull/711 Reviewed-By: Ben Noordhuis --- .gitignore | 1 + addon.gypi | 3 +- lib/build.js | 11 +- lib/configure.js | 93 ++++++------- lib/install.js | 101 ++++++-------- lib/process-release.js | 103 ++++++++++++++ lib/remove.js | 18 +-- package.json | 6 + test/docker.sh | 86 ++++++++++++ test/test-process-release.js | 263 +++++++++++++++++++++++++++++++++++ 10 files changed, 565 insertions(+), 120 deletions(-) create mode 100644 lib/process-release.js create mode 100755 test/docker.sh create mode 100644 test/test-process-release.js diff --git a/.gitignore b/.gitignore index b0b49bd62b..a9b16c38b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ gyp/test +node_modules diff --git a/addon.gypi b/addon.gypi index 4ed0a4a149..510b00c713 100644 --- a/addon.gypi +++ b/addon.gypi @@ -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' @@ -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' diff --git a/lib/build.js b/lib/build.js index eeeb60266e..198017b262 100644 --- a/lib/build.js +++ b/lib/build.js @@ -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') @@ -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) diff --git a/lib/configure.js b/lib/configure.js index e8c2029b59..ce534fe573 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -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' @@ -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() @@ -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() }) } @@ -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) + }) } /** diff --git a/lib/install.js b/lib/install.js index fafa857fbb..64df9c02e8 100644 --- a/lib/install.js +++ b/lib/install.js @@ -20,10 +20,13 @@ var fs = require('graceful-fs') , request = require('request') , minimatch = require('minimatch') , mkdir = require('mkdirp') + , processRelease = require('./process-release') , win = process.platform == 'win32' function install (gyp, argv, callback) { + var release = processRelease(argv, gyp, process.version, process.release) + // ensure no double-callbacks happen function cb (err) { if (cb.done) return @@ -31,34 +34,29 @@ function install (gyp, argv, callback) { if (err) { log.warn('install', 'got an error, rolling back install') // roll-back the install if anything went wrong - gyp.commands.remove([ version ], function (err2) { + gyp.commands.remove([ release.versionDir ], function (err2) { callback(err) }) } else { - callback(null, version) + callback(null, release.version) } } - var distUrl = gyp.opts['dist-url'] || gyp.opts.disturl || 'https://nodejs.org/dist' - - // Determine which node dev files version we are installing - var versionStr = argv[0] || gyp.opts.target || process.version - log.verbose('install', 'input version string %j', versionStr) + log.verbose('install', 'input version string %j', release.version) // parse the version to normalize and ensure it's valid - var version = semver.parse(versionStr) - if (!version) { - return callback(new Error('Invalid version number: ' + versionStr)) + if (!release.semver) { + return callback(new Error('Invalid version number: ' + release.version)) } - if (semver.lt(versionStr, '0.8.0')) { - return callback(new Error('Minimum target version is `0.8.0` or greater. Got: ' + versionStr)) + if (semver.lt(release.version, '0.8.0')) { + return callback(new Error('Minimum target version is `0.8.0` or greater. Got: ' + release.version)) } // 0.x.y-pre versions are not published yet and cannot be installed. Bail. - if (version.prerelease[0] === 'pre') { - log.verbose('detected "pre" node version', versionStr) + if (release.semver.prerelease[0] === 'pre') { + log.verbose('detected "pre" node version', release.version) if (gyp.opts.nodedir) { log.verbose('--nodedir flag was passed; skipping install', gyp.opts.nodedir) callback() @@ -69,14 +67,10 @@ function install (gyp, argv, callback) { } // flatten version into String - version = version.version - log.verbose('install', 'installing version: %s', version) - - // distributions starting with 0.10.0 contain sha256 checksums - var checksumAlgo = semver.gte(version, '0.10.0') ? 'sha256' : 'sha1' + log.verbose('install', 'installing version: %s', release.versionDir) // the directory where the dev files will be installed - var devDir = path.resolve(gyp.devDir, version) + var devDir = path.resolve(gyp.devDir, release.versionDir) // If '--ensure' was passed, then don't *always* install the version; // check if it is already installed, and only install when needed @@ -85,7 +79,7 @@ function install (gyp, argv, callback) { fs.stat(devDir, function (err, stat) { if (err) { if (err.code == 'ENOENT') { - log.verbose('install', 'version not already installed, continuing with install', version) + log.verbose('install', 'version not already installed, continuing with install', release.version) go() } else if (err.code == 'EACCES') { eaccesFallback() @@ -156,7 +150,7 @@ function install (gyp, argv, callback) { } function getContentSha(res, callback) { - var shasum = crypto.createHash(checksumAlgo) + var shasum = crypto.createHash(release.checksumAlgo) res.on('data', function (chunk) { shasum.update(chunk) }).on('end', function () { @@ -184,9 +178,8 @@ 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' - , badDownload = false + var tarPath = gyp.opts.tarball + var badDownload = false , extractCount = 0 , gunzip = zlib.createGunzip() , extracter = tar.Extract({ path: devDir, strip: 1, filter: isValid }) @@ -220,12 +213,12 @@ function install (gyp, argv, callback) { // download the tarball, gunzip and extract! if (tarPath) { - var input = fs.createReadStream(tarballUrl) + var input = fs.createReadStream(tarPath) input.pipe(gunzip).pipe(extracter) return } - var req = download(tarballUrl) + var req = download(release.tarballUrl) if (!req) return // something went wrong downloading the tarball? @@ -248,12 +241,12 @@ function install (gyp, argv, callback) { req.on('response', function (res) { if (res.statusCode !== 200) { badDownload = true - cb(new Error(res.statusCode + ' response downloading ' + tarballUrl)) + cb(new Error(res.statusCode + ' response downloading ' + release.tarballUrl)) return } // content checksum getContentSha(res, function (_, checksum) { - var filename = path.basename(tarballUrl).trim() + var filename = path.basename(release.tarballUrl).trim() contentShasums[filename] = checksum log.verbose('content checksum', filename, checksum) }) @@ -314,13 +307,11 @@ function install (gyp, argv, callback) { } function downloadShasums(done) { - var shasumsFile = (checksumAlgo === 'sha256') ? 'SHASUMS256.txt' : 'SHASUMS.txt' - log.verbose('check download content checksum, need to download `' + shasumsFile + '`...') - var shasumsPath = path.resolve(devDir, shasumsFile) - , shasumsUrl = distUrl + '/v' + version + '/' + shasumsFile + log.verbose('check download content checksum, need to download `' + release.shasumsFile + '`...') + var shasumsPath = path.resolve(devDir, release.shasumsFile) - log.verbose('checksum url', shasumsUrl) - var req = download(shasumsUrl) + log.verbose('checksum url', release.shasumsUrl) + var req = download(release.shasumsUrl) if (!req) return req.on('error', done) req.on('response', function (res) { @@ -351,39 +342,37 @@ function install (gyp, argv, callback) { } function downloadNodeLib (done) { - log.verbose('on Windows; need to download `node.lib`...') + log.verbose('on Windows; need to download `' + release.name + '.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' + , libPath32 = path.resolve(dir32, release.name + '.lib') + , libPath64 = path.resolve(dir64, release.name + '.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) + log.verbose('32-bit ' + release.name + '.lib dir', dir32) + log.verbose('64-bit ' + release.name + '.lib dir', dir64) + log.verbose('`' + release.name + '.lib` 32-bit url', release.libUrl32) + log.verbose('`' + release.name + '.lib` 64-bit url', release.libUrl64) 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 ' + release.name + '.lib to:', libPath32) - var req = download(nodeLibUrl32) + var req = download(release.libUrl32) 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 ' + release.name + '.lib')) return } getContentSha(res, function (_, checksum) { - contentShasums['node.lib'] = checksum - log.verbose('content checksum', 'node.lib', checksum) + contentShasums[release.libPath32] = checksum + log.verbose('content checksum', release.libPath32, checksum) }) - var ws = fs.createWriteStream(nodeLibPath32) + var ws = fs.createWriteStream(libPath32) ws.on('error', cb) req.pipe(ws) }) @@ -393,23 +382,23 @@ 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 ' + release.name + '.lib to:', libPath64) - var req = download(nodeLibUrl64) + var req = download(release.libUrl64) 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 ' + release.name + '.lib')) return } getContentSha(res, function (_, checksum) { - contentShasums['x64/node.lib'] = checksum - log.verbose('content checksum', 'x64/node.lib', checksum) + contentShasums[release.libPath64] = checksum + log.verbose('content checksum', release.libPath64, checksum) }) - var ws = fs.createWriteStream(nodeLibPath64) + var ws = fs.createWriteStream(libPath64) ws.on('error', cb) req.pipe(ws) }) diff --git a/lib/process-release.js b/lib/process-release.js new file mode 100644 index 0000000000..70e90abab4 --- /dev/null +++ b/lib/process-release.js @@ -0,0 +1,103 @@ +var semver = require('semver') +var url = require('url') +var path = require('path') + +var bitsre = /(x86|x64)/ +var bitsreV3 = /(x86|ia32|x64)/ // io.js v3.x.x shipped with "ia32" but should + // have been "x86" + +// Captures all the logic required to determine download URLs, local directory and +// file names and whether we need to use SHA-1 or 2. Inputs come from command-line +// switches (--target), `process.version` and `process.release` where it exists. +function processRelease (argv, gyp, defaultVersion, defaultRelease) { + var version = argv[0] || gyp.opts.target || defaultVersion + + // parse the version to normalize and ensure it's valid + var versionSemver = semver.parse(version) + if (!versionSemver) { + return { version: version } + } + // flatten version into String + version = versionSemver.version + + var overrideDistUrl = gyp.opts['dist-url'] || gyp.opts.disturl + var iojs = !overrideDistUrl && !defaultRelease && semver.satisfies(version, '>=1.0.0 <4.0.0') + var name = (defaultRelease && defaultRelease.name.replace(/\./g, '')) || (iojs ? 'iojs' : 'node') // io.js -> iojs + var defaultDirUrl = (overrideDistUrl || iojs ? 'https://iojs.org/download/release' : 'https://nodejs.org/dist') + '/v' + version + '/' + var baseUrl + var libUrl32 + var libUrl64 + + // new style, based on process.release so we have a lot of the data we need + if (defaultRelease && defaultRelease.headersUrl && !overrideDistUrl) { + baseUrl = url.resolve(defaultRelease.headersUrl, './') + libUrl32 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || defaultDirUrl, 'x86', version) + libUrl64 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || defaultDirUrl, 'x64', version) + + return { + version: version, + semver: versionSemver, + name: name, + baseUrl: baseUrl, + tarballUrl: defaultRelease.headersUrl, + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: url.resolve(baseUrl, 'SHASUMS256.txt'), + checksumAlgo: 'sha256', + versionDir: (name !== 'node' ? name + '-' : '') + version, + libUrl32: libUrl32, + libUrl64: libUrl64, + libPath32: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl32).path)), + libPath64: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl64).path)) + } + } + + // older versions without process.release are captured here and we have to make + // a lot of assumptions + + // distributions starting with 0.10.0 contain sha256 checksums + var checksumAlgo = semver.gte(version, '0.10.0') ? 'sha256' : 'sha1' + var shasumsFile = (checksumAlgo === 'sha256') ? 'SHASUMS256.txt' : 'SHASUMS.txt' + + baseUrl = defaultDirUrl + libUrl32 = resolveLibUrl(name, baseUrl, 'x86', version) + libUrl64 = resolveLibUrl(name, baseUrl, 'x64', version) + + return { + version: version, + semver: versionSemver, + name: name, + baseUrl: baseUrl, + tarballUrl: baseUrl + name + '-v' + version + '.tar.gz', + shasumsFile: shasumsFile, + shasumsUrl: baseUrl + shasumsFile, + checksumAlgo: checksumAlgo, + versionDir: (name !== 'node' ? name + '-' : '') + version, + libUrl32: libUrl32, + libUrl64: libUrl64, + libPath32: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl32).path)), + libPath64: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl64).path)) + } +} + +function normalizePath (p) { + return path.normalize(p).replace(/\\/g, '/') +} + +function resolveLibUrl (name, defaultUrl, arch, version) { + var base = url.resolve(defaultUrl, './') + var isV3 = semver.satisfies(version, '^3') + var hasLibUrl = bitsre.test(defaultUrl) || (isV3 && bitsreV3.test(defaultUrl)) + + if (!hasLibUrl) { + // let's assume it's a baseUrl then + if (semver.gte(version, '1.0.0')) + return url.resolve(base, 'win-' + arch +'/' + name + '.lib') + // prior to io.js@1.0.0 32-bit node.lib lives in /, 64-bit lives in /x64/ + return url.resolve(base, (arch == 'x64' ? 'x64/' : '') + name + '.lib') + } + + // else we have a proper url to a .lib, just make sure it's the right arch + return defaultUrl.replace(isV3 ? bitsreV3 : bitsre, arch) +} + +module.exports = processRelease diff --git a/lib/remove.js b/lib/remove.js index 068d1e3892..eb80981b88 100644 --- a/lib/remove.js +++ b/lib/remove.js @@ -19,23 +19,19 @@ function remove (gyp, argv, callback) { log.verbose('remove', 'using node-gyp dir:', devDir) // get the user-specified version to remove - var v = argv[0] || gyp.opts.target - log.verbose('remove', 'removing target version:', v) + var version = argv[0] || gyp.opts.target + log.verbose('remove', 'removing target version:', version) - if (!v) { + if (!version) { return callback(new Error('You must specify a version number to remove. Ex: "' + process.version + '"')) } - // parse the version to normalize and make sure it's valid - var version = semver.parse(v) - - if (!version) { - return callback(new Error('Invalid version number: ' + v)) + var versionSemver = semver.parse(version) + if (versionSemver) { + // flatten the version Array into a String + version = versionSemver.version } - // flatten the version Array into a String - version = version.version - var versionPath = path.resolve(gyp.devDir, version) log.verbose('remove', 'removing development files for version:', version) diff --git a/package.json b/package.json index dce9c28bef..e37e693898 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,11 @@ }, "engines": { "node": ">= 0.8.0" + }, + "devDependencies": { + "tape": "~4.2.0" + }, + "scripts": { + "test": "tape test/test-*" } } diff --git a/test/docker.sh b/test/docker.sh new file mode 100755 index 0000000000..2aaa53bd0c --- /dev/null +++ b/test/docker.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +#set -e + +test_node_versions="0.8.28 0.10.40 0.12.7" +test_iojs_versions="1.8.4 2.4.0 3.3.0" + +# borrows from https://github.com/rvagg/dnt/ + +# Simple setup function for a container: +# setup_container(image id, base image, commands to run to set up) +setup_container() { + local ID=$1 + local BASE=$2 + local RUN=$3 + + # Does this image exist? If yes, ignore + docker inspect "$ID" &> /dev/null + if [[ $? -eq 0 ]]; then + echo "Found existing container [$ID]" + else + # No such image, so make it + echo "Did not find container [$ID], creating..." + docker run -i $BASE /bin/bash -c "$RUN" + sleep 2 + docker commit $(docker ps -l -q) $ID + fi +} + +# Run tests inside each of the versioned containers, copy cwd into npm's copy of node-gyp +# so it'll be invoked by npm when a compile is needed +# run_tests(version, test-commands) +run_tests() { + local VERSION=$1 + local RUN=$2 + + RUN="rsync -aAXx --delete --exclude .git --exclude build /node-gyp-src/ /usr/lib/node_modules/npm/node_modules/node-gyp/; + /bin/su -s /bin/bash node-gyp -c 'cd && ${RUN}'" + + docker run --rm -v ~/.npm/:/dnt/.npm/ -v $(pwd):/node-gyp-src/:ro -i node-gyp-test/${VERSION} /bin/bash -c "$RUN" +} + + +# A base image with build tools and a user account +setup_container "node-gyp-test/base" "ubuntu:14.04" " + apt-get update && + apt-get install -y build-essential python git rsync curl && + adduser --gecos node-gyp --home /node-gyp/ --disabled-login node-gyp && + echo "node-gyp:node-gyp" | chpasswd +" + +# An image on top of the base containing clones of repos we want to use for testing +setup_container "node-gyp-test/clones" "node-gyp-test/base" " + cd /node-gyp/ && git clone https://github.com/justmoon/node-bignum.git && + cd /node-gyp/ && git clone https://github.com/bnoordhuis/node-buffertools.git && + chown -R node-gyp.node-gyp /node-gyp/ +" + +# An image for each of the node versions we want to test with that version installed and the latest npm +for v in $test_node_versions; do + setup_container "node-gyp-test/${v}" "node-gyp-test/clones" " + curl -sL https://nodejs.org/dist/v${v}/node-v${v}-linux-x64.tar.gz | tar -zxv --strip-components=1 -C /usr/ && + npm install npm@latest -g && + node -v && npm -v + " +done + +# An image for each of the io.js versions we want to test with that version installed and the latest npm +for v in $test_iojs_versions; do + setup_container "node-gyp-test/${v}" "node-gyp-test/clones" " + curl -sL https://iojs.org/dist/v${v}/iojs-v${v}-linux-x64.tar.gz | tar -zxv --strip-components=1 -C /usr/ && + npm install npm@latest -g && + node -v && npm -v + " +done + + +# Run the tests for all of the test images we've created, +# we should see node-gyp doing its download, configure and run thing +# _NOTE: bignum doesn't compile on 0.8 currently so it'll fail for that version only_ +for v in $test_node_versions $test_iojs_versions; do + run_tests $v " + cd node-buffertools && npm install --loglevel=info && npm test && cd && + cd node-bignum && npm install --loglevel=info && npm test + " +done \ No newline at end of file diff --git a/test/test-process-release.js b/test/test-process-release.js new file mode 100644 index 0000000000..9ec585e04b --- /dev/null +++ b/test/test-process-release.js @@ -0,0 +1,263 @@ +var test = require('tape') +var processRelease = require('../lib/process-release') + +test('test process release - process.version = 0.8.20', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v0.8.20', null) + + t.equal(release.semver.version, '0.8.20') + delete release.semver + + t.deepEqual(release, { + version: '0.8.20', + name: 'node', + baseUrl: 'https://nodejs.org/dist/v0.8.20/', + tarballUrl: 'https://nodejs.org/dist/v0.8.20/node-v0.8.20.tar.gz', + shasumsFile: 'SHASUMS.txt', + shasumsUrl: 'https://nodejs.org/dist/v0.8.20/SHASUMS.txt', + checksumAlgo: 'sha1', + versionDir: '0.8.20', + libUrl32: 'https://nodejs.org/dist/v0.8.20/node.lib', + libUrl64: 'https://nodejs.org/dist/v0.8.20/x64/node.lib', + libPath32: 'node.lib', + libPath64: 'x64/node.lib' + }) +}) + +test('test process release - process.version = 0.10.21', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v0.10.21', null) + + t.equal(release.semver.version, '0.10.21') + delete release.semver + + t.deepEqual(release, { + version: '0.10.21', + name: 'node', + baseUrl: 'https://nodejs.org/dist/v0.10.21/', + tarballUrl: 'https://nodejs.org/dist/v0.10.21/node-v0.10.21.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://nodejs.org/dist/v0.10.21/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: '0.10.21', + libUrl32: 'https://nodejs.org/dist/v0.10.21/node.lib', + libUrl64: 'https://nodejs.org/dist/v0.10.21/x64/node.lib', + libPath32: 'node.lib', + libPath64: 'x64/node.lib' + }) +}) + +test('test process release - process.version = 0.12.22', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v0.12.22', null) + + t.equal(release.semver.version, '0.12.22') + delete release.semver + + t.deepEqual(release, { + version: '0.12.22', + name: 'node', + baseUrl: 'https://nodejs.org/dist/v0.12.22/', + tarballUrl: 'https://nodejs.org/dist/v0.12.22/node-v0.12.22.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://nodejs.org/dist/v0.12.22/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: '0.12.22', + libUrl32: 'https://nodejs.org/dist/v0.12.22/node.lib', + libUrl64: 'https://nodejs.org/dist/v0.12.22/x64/node.lib', + libPath32: 'node.lib', + libPath64: 'x64/node.lib' + }) +}) + +test('test process release - process.release ~ node@4.1.23', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v4.1.23', { + name: 'node', + headersUrl: 'https://nodejs.org/dist/v4.1.23/node-v4.1.23-headers.tar.gz' + }) + + t.equal(release.semver.version, '4.1.23') + delete release.semver + + t.deepEqual(release, { + version: '4.1.23', + name: 'node', + baseUrl: 'https://nodejs.org/dist/v4.1.23/', + tarballUrl: 'https://nodejs.org/dist/v4.1.23/node-v4.1.23-headers.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://nodejs.org/dist/v4.1.23/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: '4.1.23', + libUrl32: 'https://nodejs.org/dist/v4.1.23/win-x86/node.lib', + libUrl64: 'https://nodejs.org/dist/v4.1.23/win-x64/node.lib', + libPath32: 'win-x86/node.lib', + libPath64: 'win-x64/node.lib' + }) +}) + +test('test process release - process.release ~ node@4.1.23 / corp build', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v4.1.23', { + name: 'node', + headersUrl: 'https://some.custom.location/node-v4.1.23-headers.tar.gz' + }) + + t.equal(release.semver.version, '4.1.23') + delete release.semver + + t.deepEqual(release, { + version: '4.1.23', + name: 'node', + baseUrl: 'https://some.custom.location/', + tarballUrl: 'https://some.custom.location/node-v4.1.23-headers.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://some.custom.location/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: '4.1.23', + libUrl32: 'https://some.custom.location/win-x86/node.lib', + libUrl64: 'https://some.custom.location/win-x64/node.lib', + libPath32: 'win-x86/node.lib', + libPath64: 'win-x64/node.lib' + }) +}) + +test('test process release - process.version = 1.8.4', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v1.8.4', null) + + t.equal(release.semver.version, '1.8.4') + delete release.semver + + t.deepEqual(release, { + version: '1.8.4', + name: 'iojs', + baseUrl: 'https://iojs.org/download/release/v1.8.4/', + tarballUrl: 'https://iojs.org/download/release/v1.8.4/iojs-v1.8.4.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://iojs.org/download/release/v1.8.4/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: 'iojs-1.8.4', + libUrl32: 'https://iojs.org/download/release/v1.8.4/win-x86/iojs.lib', + libUrl64: 'https://iojs.org/download/release/v1.8.4/win-x64/iojs.lib', + libPath32: 'win-x86/iojs.lib', + libPath64: 'win-x64/iojs.lib' + }) +}) + +test('test process release - process.release ~ iojs@3.2.24', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v3.2.24', { + name: 'io.js', + headersUrl: 'https://iojs.org/download/release/v3.2.24/iojs-v3.2.24-headers.tar.gz' + }) + + t.equal(release.semver.version, '3.2.24') + delete release.semver + + t.deepEqual(release, { + version: '3.2.24', + name: 'iojs', + baseUrl: 'https://iojs.org/download/release/v3.2.24/', + tarballUrl: 'https://iojs.org/download/release/v3.2.24/iojs-v3.2.24-headers.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://iojs.org/download/release/v3.2.24/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: 'iojs-3.2.24', + libUrl32: 'https://iojs.org/download/release/v3.2.24/win-x86/iojs.lib', + libUrl64: 'https://iojs.org/download/release/v3.2.24/win-x64/iojs.lib', + libPath32: 'win-x86/iojs.lib', + libPath64: 'win-x64/iojs.lib' + }) +}) + +test('test process release - process.release ~ iojs@3.2.11 +libUrl32', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v3.2.11', { + name: 'io.js', + headersUrl: 'https://iojs.org/download/release/v3.2.11/iojs-v3.2.11-headers.tar.gz', + libUrl: 'https://iojs.org/download/release/v3.2.11/libdir-x86/iojs.lib' // custom + }) + + t.equal(release.semver.version, '3.2.11') + delete release.semver + + t.deepEqual(release, { + version: '3.2.11', + name: 'iojs', + baseUrl: 'https://iojs.org/download/release/v3.2.11/', + tarballUrl: 'https://iojs.org/download/release/v3.2.11/iojs-v3.2.11-headers.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://iojs.org/download/release/v3.2.11/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: 'iojs-3.2.11', + libUrl32: 'https://iojs.org/download/release/v3.2.11/libdir-x86/iojs.lib', + libUrl64: 'https://iojs.org/download/release/v3.2.11/libdir-x64/iojs.lib', + libPath32: 'libdir-x86/iojs.lib', + libPath64: 'libdir-x64/iojs.lib' + }) +}) + +test('test process release - process.release ~ iojs@3.2.101 +libUrl64', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v3.2.101', { + name: 'io.js', + headersUrl: 'https://iojs.org/download/release/v3.2.101/iojs-v3.2.101-headers.tar.gz', + libUrl: 'https://iojs.org/download/release/v3.2.101/libdir-x64/iojs.lib' // custom + }) + + t.equal(release.semver.version, '3.2.101') + delete release.semver + + t.deepEqual(release, { + version: '3.2.101', + name: 'iojs', + baseUrl: 'https://iojs.org/download/release/v3.2.101/', + tarballUrl: 'https://iojs.org/download/release/v3.2.101/iojs-v3.2.101-headers.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://iojs.org/download/release/v3.2.101/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: 'iojs-3.2.101', + libUrl32: 'https://iojs.org/download/release/v3.2.101/libdir-x86/iojs.lib', + libUrl64: 'https://iojs.org/download/release/v3.2.101/libdir-x64/iojs.lib', + libPath32: 'libdir-x86/iojs.lib', + libPath64: 'libdir-x64/iojs.lib' + }) +}) + +test('test process release - process.release ~ iojs@3.3.0 - borked libdir', function (t) { + t.plan(2) + + var release = processRelease([], { opts: {} }, 'v3.2.101', { + name: 'io.js', + headersUrl: 'https://iojs.org/download/release/v3.2.101/iojs-v3.2.101-headers.tar.gz', + libUrl: 'https://iojs.org/download/release/v3.2.101/win-ia32/iojs.lib' // custom + }) + + t.equal(release.semver.version, '3.2.101') + delete release.semver + + t.deepEqual(release, { + version: '3.2.101', + name: 'iojs', + baseUrl: 'https://iojs.org/download/release/v3.2.101/', + tarballUrl: 'https://iojs.org/download/release/v3.2.101/iojs-v3.2.101-headers.tar.gz', + shasumsFile: 'SHASUMS256.txt', + shasumsUrl: 'https://iojs.org/download/release/v3.2.101/SHASUMS256.txt', + checksumAlgo: 'sha256', + versionDir: 'iojs-3.2.101', + libUrl32: 'https://iojs.org/download/release/v3.2.101/win-x86/iojs.lib', + libUrl64: 'https://iojs.org/download/release/v3.2.101/win-x64/iojs.lib', + libPath32: 'win-x86/iojs.lib', + libPath64: 'win-x64/iojs.lib' + }) +})