Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for official libc formatting #22

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/detect-libc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const GLIBC = 'glibc';
* A Regexp constant to get the GLIBC Version.
* @type {string}
*/
const RE_GLIBC_VERSION = /GLIBC\s(\d+\.\d+)/;
const RE_GLIBC_VERSION = /LIBC[a-z0-9 \-).]*?(\d+\.\d+)/i;

/**
* A String constant containing the value `musl`.
Expand Down Expand Up @@ -86,7 +86,7 @@ const getFamilyFromLddContent = (content) => {
if (content.includes('musl')) {
return MUSL;
}
if (content.includes('GLIBC')) {
if (content.includes('GNU C Library')) {
return GLIBC;
}
return null;
Expand Down
78 changes: 76 additions & 2 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('linux - glibc family detected via ldd', async (t) => {
isLinux: () => true
},
'./filesystem': {
readFile: () => Promise.resolve('bunch-of-text GLIBC')
readFile: () => Promise.resolve('# This file is part of the GNU C Library.')
}
});

Expand All @@ -74,7 +74,7 @@ test('linux - glibc familySync detected via ldd', async (t) => {
isLinux: () => true
},
'./filesystem': {
readFileSync: () => 'bunch-of-text GLIBC'
readFileSync: () => '# The GNU C Library is free software; you can redistribute it and/or'
}
});

Expand Down Expand Up @@ -488,6 +488,43 @@ test('linux - glibc version detected via filesystem', async (t) => {
t.is(await libc.version(), '1.23');
});

test('linux - glibc version detected via filesystem (libc)', async (t) => {
t.plan(1);

const out = '--vers | --versi | --versio | --version)\necho \'ldd (GNU libc) 2.39\'';
const libc = proxyquire('../', {
'./process': {
isLinux: () => true
},
'./filesystem': {
readFile: () => Promise.resolve(out)
}
});

t.is(await libc.version(), '2.39');
});

test('linux - libc version not detected via filesystem (void linux musl)', async (t) => {
t.plan(1);

const out = 'startlibc_startGNU AS 2.35.1';
const libc = proxyquire('../', {
'./process': {
isLinux: () => true,
getReport: () => ({})
},
'./filesystem': {
readFile: () => Promise.resolve(out)
},
child_process: {
exec: (_c, cb) => cb(null, out),
execSync: () => out
}
});

t.is(await libc.version(), null);
});

test('linux - glibc version detected via filesystemSync', async (t) => {
t.plan(1);

Expand All @@ -504,6 +541,43 @@ test('linux - glibc version detected via filesystemSync', async (t) => {
t.is(libc.versionSync(), '1.23');
});

test('linux - glibc version detected via filesystemSync (libc)', async (t) => {
t.plan(1);

const out = '--vers | --versi | --versio | --version)\necho \'ldd (GNU libc) 2.39\'';
const libc = proxyquire('../', {
'./process': {
isLinux: () => true
},
'./filesystem': {
readFileSync: () => out
}
});

t.is(libc.versionSync(), '2.39');
});

test('linux - libc version not detected via filesystemSync (void linux musl)', (t) => {
t.plan(1);

const out = 'startlibc_startGNU AS 2.35.1';
const libc = proxyquire('../', {
'./process': {
isLinux: () => true,
getReport: () => ({})
},
'./filesystem': {
readFile: () => Promise.resolve(out)
},
child_process: {
exec: (_c, cb) => cb(null, out),
execSync: () => out
}
});

t.is(libc.versionSync(), null);
});

test('linux - glibc version detected via child process', async (t) => {
t.plan(1);

Expand Down