-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add a platform variant for installing a musl binary #1836
Changes from 12 commits
fd0238a
85193ea
5773e8d
a3e3e6d
3cf4232
83e3095
78f4601
b0a63a0
7e32a94
4647e02
df1803d
5892a85
73199fa
209b1a6
d38985a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ function getHumanPlatform(platform) { | |
case 'darwin': return 'OS X'; | ||
case 'freebsd': return 'FreeBSD'; | ||
case 'linux': return 'Linux'; | ||
case 'linux_musl': return 'Linux/musl'; | ||
case 'win32': return 'Windows'; | ||
default: return false; | ||
} | ||
|
@@ -182,8 +183,14 @@ function getBinaryName() { | |
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) { | ||
binaryName = pkg.nodeSassConfig.binaryName; | ||
} else { | ||
var platform = process.platform; | ||
var variant = getPlatformVariant(); | ||
if (variant !== '') { | ||
platform += '_' + variant; | ||
} | ||
|
||
binaryName = [ | ||
process.platform, '-', | ||
platform, '-', | ||
process.arch, '-', | ||
process.versions.modules | ||
].join(''); | ||
|
@@ -256,7 +263,7 @@ function getBinaryPath() { | |
} else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryPath) { | ||
binaryPath = pkg.nodeSassConfig.binaryPath; | ||
} else { | ||
binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_/, '/')); | ||
binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_(?=binding\.node)/, '/')); | ||
} | ||
|
||
return binaryPath; | ||
|
@@ -359,6 +366,29 @@ function getVersionInfo(binding) { | |
].join(eol); | ||
} | ||
|
||
/** | ||
* Gets the platform variant, currently either an empty string or 'musl' for Linux/musl platforms. | ||
* | ||
* @api public | ||
*/ | ||
|
||
function getPlatformVariant() { | ||
if (process.platform !== 'linux') { | ||
return ''; | ||
} | ||
var contents = ''; | ||
try { | ||
contents = fs.readFileSync(process.execPath); | ||
if (!contents.indexOf) { | ||
contents = contents.toString(); | ||
} | ||
if (contents.indexOf('libc.musl-x86_64.so.1') !== -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry I sent comment while you are updating this.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starts to get a bit micro-optimization-y for my tastes, but sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @ncopa can you confirm it's ok to cover all Alpine releases or should we look for a wider pattern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you asking whether this test will work for all Alpine releases? If so, yes. |
||
return 'musl'; | ||
} | ||
} catch (err) { } // eslint-disable-line no-empty | ||
return ''; | ||
} | ||
|
||
module.exports.hasBinary = hasBinary; | ||
module.exports.getBinaryUrl = getBinaryUrl; | ||
module.exports.getBinaryName = getBinaryName; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to figure out how contents wasn't a string or buffer? This intent of line isn't clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just tried on 0.10. 0.12 and 7, they all return Buffer, indexOf is not available in 0.10 and 0.12
Docs says, buf.indexOf is added in v1.5.0
https://nodejs.org/api/buffer.html#buffer_buf_indexof_value_byteoffset_encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and performance difference with/without .toString() on node 7.0
Also I think toString will use additional memory like 20M binary x UTF16 = 40M, If I am not wrong.
Of course there will be better performance by reading file by chunks, stop when found, but that's too much code to add, in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification @S-YOU. I've gone back to lazily tostring'ing.