From a919a7aec26f396b9a92d1913cc1acc1fb3a04f2 Mon Sep 17 00:00:00 2001 From: Adeel Date: Tue, 10 Feb 2015 09:46:15 +0200 Subject: [PATCH] Build: Produces identifiable binary name. The new format is: {platform}-{arch}-{runtime}-{major.minor} where major and minor version belong to the runtime. Related Issue: #655. PR URL: sass/node-sass#657. --- lib/index.js | 7 +++++-- lib/utils.js | 28 ++++++++++++++++++++++++++++ package.json | 1 + scripts/build.js | 5 +++-- scripts/install.js | 5 +++-- 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 lib/utils.js diff --git a/lib/index.js b/lib/index.js index cf421e4c2..3146d2072 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,6 @@ var fs = require('fs'), - path = require('path'); + path = require('path'), + utils = require('./utils'); /** * Get binding @@ -8,7 +9,8 @@ var fs = require('fs'), */ function getBinding() { - var name = process.platform + '-' + process.arch; + var name = utils.getBinaryIdentifiableName(); + var candidates = [ path.join(__dirname, '..', 'build', 'Release', 'binding.node'), path.join(__dirname, '..', 'build', 'Debug', 'binding.node'), @@ -255,6 +257,7 @@ module.exports.renderSync = function(options) { /** * API Info * + * @api public */ module.exports.info = function() { diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 000000000..ecc8ae967 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,28 @@ +var semver = require('semver'), + runtimeVersion = semver.parse(process.version); + +/** + * Get Runtime Name + * + * @api private + */ + +function getRuntimeName() { + return process.execPath + .split(/[\\/]+/).pop() + .split('.')[0]; +} + +/** + * Get unique name of binary for current platform + * + * @api public + */ + +module.exports.getBinaryIdentifiableName = function() { + return process.platform + '-' + + process.arch + '-' + + runtime + '-' + + runtimeVersion.major + '.' + + runtimeVersion.minor; +} diff --git a/package.json b/package.json index 13460f91b..074942cd5 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "replace-ext": "0.0.1", "request": "^2.53.0", "sass-graph": "^1.0.3", + "semver": "^4.2.2", "shelljs": "^0.3.0" }, "devDependencies": { diff --git a/scripts/build.js b/scripts/build.js index 09a54a135..48ab094ef 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -2,7 +2,8 @@ var fs = require('fs'), path = require('path'), spawn = require('child_process').spawn, mkdir = require('mkdirp'), - Mocha = require('mocha'); + Mocha = require('mocha'), + utils = require('../lib/utils'); /** * After build @@ -109,7 +110,7 @@ function parseArgs(args) { */ function testBinary(options) { - options.bin = options.platform + '-' + options.arch; + options.bin = utils.getBinaryIdentifiableName(); if (options.force || process.env.SASS_FORCE_BUILD) { return build(options); diff --git a/scripts/install.js b/scripts/install.js index 296345b62..addd50079 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -2,7 +2,8 @@ var fs = require('fs'), path = require('path'), request = require('request'), mkdirp = require('mkdirp'), - exec = require('shelljs').exec; + exec = require('shelljs').exec, + utils = require('../lib/utils'); /** * Download file, if succeeds save, if not delete @@ -76,7 +77,7 @@ function applyProxy(options, cb) { */ function exists() { - var name = process.platform + '-' + process.arch; + var name = utils.getBinaryIdentifiableName(); fs.exists(path.join(__dirname, '..', 'vendor', name), function (exists) { if (exists) {