Commit 5521bb6b by Lachlan Donald Committed by Michael Mifsud

Add a platform variant for installing a musl binary (#1836)

Add a platform variant for installing a musl binary
parent 3c17b033
...@@ -23,6 +23,7 @@ function getHumanPlatform(platform) { ...@@ -23,6 +23,7 @@ function getHumanPlatform(platform) {
case 'darwin': return 'OS X'; case 'darwin': return 'OS X';
case 'freebsd': return 'FreeBSD'; case 'freebsd': return 'FreeBSD';
case 'linux': return 'Linux'; case 'linux': return 'Linux';
case 'linux_musl': return 'Linux/musl';
case 'win32': return 'Windows'; case 'win32': return 'Windows';
default: return false; default: return false;
} }
...@@ -171,7 +172,9 @@ function getArgument(name, args) { ...@@ -171,7 +172,9 @@ function getArgument(name, args) {
*/ */
function getBinaryName() { function getBinaryName() {
var binaryName; var binaryName,
variant,
platform = process.platform;
if (getArgument('--sass-binary-name')) { if (getArgument('--sass-binary-name')) {
binaryName = getArgument('--sass-binary-name'); binaryName = getArgument('--sass-binary-name');
...@@ -182,8 +185,13 @@ function getBinaryName() { ...@@ -182,8 +185,13 @@ function getBinaryName() {
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) { } else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) {
binaryName = pkg.nodeSassConfig.binaryName; binaryName = pkg.nodeSassConfig.binaryName;
} else { } else {
variant = getPlatformVariant();
if (variant) {
platform += '_' + variant;
}
binaryName = [ binaryName = [
process.platform, '-', platform, '-',
process.arch, '-', process.arch, '-',
process.versions.modules process.versions.modules
].join(''); ].join('');
...@@ -256,7 +264,7 @@ function getBinaryPath() { ...@@ -256,7 +264,7 @@ function getBinaryPath() {
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryPath) { } else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryPath) {
binaryPath = pkg.nodeSassConfig.binaryPath; binaryPath = pkg.nodeSassConfig.binaryPath;
} else { } else {
binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_/, '/')); binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_(?=binding\.node)/, '/'));
} }
return binaryPath; return binaryPath;
...@@ -359,6 +367,36 @@ function getVersionInfo(binding) { ...@@ -359,6 +367,36 @@ function getVersionInfo(binding) {
].join(eol); ].join(eol);
} }
/**
* Gets the platform variant, currently either an empty string or 'musl' for Linux/musl platforms.
*
* @api public
*/
function getPlatformVariant() {
var contents = '';
if (process.platform !== 'linux') {
return '';
}
try {
contents = fs.readFileSync(process.execPath);
// Buffer.indexOf was added in v1.5.0 so cast to string for old node
// Delay contents.toStrings because it's expensive
if (!contents.indexOf) {
contents = contents.toString();
}
if (contents.indexOf('libc.musl-x86_64.so.1') !== -1) {
return 'musl';
}
} catch (err) { } // eslint-disable-line no-empty
return '';
}
module.exports.hasBinary = hasBinary; module.exports.hasBinary = hasBinary;
module.exports.getBinaryUrl = getBinaryUrl; module.exports.getBinaryUrl = getBinaryUrl;
module.exports.getBinaryName = getBinaryName; module.exports.getBinaryName = getBinaryName;
......
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