Commit d4ffe84a by Nick Schonning

Build: Add v8 specific platform builds

Idea courtesy of node-fibers.
When installing, check to see if there is a compatible binary version
for the current version of v8. v8 3.6 = Node 0.6, 3.11 = Node 0.8, 3.14
= Node 0.10. The test suite is run as well, so that any underlying
libsass breaks will be rebuilt.

Closes gh-146
parent 586d3342
......@@ -19,3 +19,5 @@ vagrant
.lock-wscript
.DS_Store
.sass-cache
bin/*-v8-*
\ No newline at end of file
#!/usr/bin/env node
var cp = require('child_process'),
fs = require('fs'),
path = require('path'),
Mocha = require('mocha');
// Parse args
var force = false, debug = false;
var arch = process.arch,
platform = process.platform,
v8 = /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
var args = process.argv.slice(2).filter(function(arg) {
if (arg === '-f') {
force = true;
return false;
} else if (arg.substring(0, 13) === '--target_arch') {
arch = arg.substring(14);
} else if (arg === '--debug') {
debug = true;
}
return true;
});
if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {
console.error('Unsupported (?) architecture: `'+ arch+ '`');
process.exit(1);
}
// Test for pre-built library
var modPath = platform + '-' + arch + '-v8-' + v8;
if (!force) {
try {
fs.statSync(path.join(__dirname, 'bin', modPath, 'binding.node'));
console.log('`'+ modPath+ '` exists; testing');
var mocha = new Mocha({
reporter: 'min',
ui: 'bdd',
timeout: 999999
});
mocha.addFile(path.resolve(__dirname, "test", "test.js"));
var runner = mocha.run(function (done) {
if (done !== 0) {
console.log('Problem with the binary; manual build incoming');
console.log('Please consider contributing the release binary to https://github.com/andrew/node-sass-binaries for npm distribution.');
build();
} else {
console.log('Binary is fine; exiting');
}
});
} catch (ex) {
// Stat failed
build();
}
} else {
build();
}
// Build it
function build() {
cp.spawn(
process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp',
['rebuild'].concat(args),
{customFds: [0, 1, 2]})
.on('exit', function(err) {
if (err) {
if (err === 127) {
console.error(
'node-gyp not found! Please upgrade your install of npm! You need at least 1.1.5 (I think) '+
'and preferably 1.1.30.'
);
} else {
console.error('Build failed');
}
return process.exit(err);
}
afterBuild();
});
}
// Move it to expected location
function afterBuild() {
var targetPath = path.join(__dirname, 'build', debug ? 'Debug' : 'Release', 'binding.node');
var installPath = path.join(__dirname, 'bin', modPath, 'binding.node');
try {
fs.mkdirSync(path.join(__dirname, 'bin', modPath));
} catch (ex) {}
try {
fs.statSync(targetPath);
} catch (ex) {
console.error('Build succeeded but target not found');
process.exit(1);
}
fs.renameSync(targetPath, installPath);
console.log('Installed in `'+ installPath+ '`');
}
......@@ -24,8 +24,9 @@
"url": "git://github.com/andrew/node-sass.git"
},
"scripts": {
"install": "node rebuild.js",
"test": "mocha test"
"install": "node build.js",
"test": "mocha test",
"prepublish": "bash scripts/prepublish.sh"
},
"bin": {
"node-sass": "bin/node-sass"
......@@ -38,9 +39,7 @@
"mkdirp": "0.3.x",
"colors": "0.6.0-1",
"optimist": "0.6.x",
"node-watch": "0.3.x"
},
"devDependencies": {
"mocha": "1.7.x"
"node-watch": "0.3.x",
"mocha": "1.13.x"
}
}
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
var spawn = require('child_process').spawn;
// Only rebuild the binaries if on Mac OS or Linux, as we're assuming that
// the toolchain exists. This is here to not rebuild on windows, as that
// had issues as of https://github.com/andrew/node-sass/issues/123
if (process.platform === 'darwin' || process.platform === 'linux') {
spawn('node-gyp', ['rebuild'], {stdio: 'inherit'});
}
var binding;
var fs = require('fs');
var path = require('path');
var v8 = 'v8-' + /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
var modPath = path.join(__dirname, 'bin', process.platform + '-' + process.arch + '-' + v8, 'binding');
try {
if (fs.realpathSync(__dirname + '/build')) {
// use the build version if it exists
binding = require(__dirname + '/build/Release/binding');
}
} catch (e) {
// default to a precompiled binary if no build exists
var platform_full = process.platform+'-'+process.arch;
binding = require(__dirname + '/precompiled/'+platform_full+'/binding');
}
if (binding === null) {
throw new Error('Cannot find appropriate binary library for node-sass');
try {
fs.realpathSync(modPath + '.node');
binding = require(modPath);
} catch (ex) {
// No binary!
throw new Error('`'+ modPath + '.node` is missing. Try reinstalling `node-sass`?');
}
}
var SASS_OUTPUT_STYLE = {
......
#!/bin/bash
DIRECTORY="../node-sass-binaries"
if [ "$CI" == "true" ]; then
echo "Skipping prepublish on CI builds";
elif [ -d "$DIRECTORY" ]; then
echo "Copying binaries to bin"
cp $DIRECTORY/*-v8-* bin/ -R
else
echo "Skipping bin copy. Please clone https://github.com/andrew/node-sass-binaries for prebuilt binaries";
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment