Skip to content

Commit ffc9f8a

Browse files
authored
Improves the check for the libc presence (#5971)
**What's the problem this PR addresses?** The libc detection can currently be really slow on Linux systems due to deficiencies in the Node.js `getReport` implementation. **How did you fix it?** As a workaround, we now first check the `ldd` content. **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent de2e5aa commit ffc9f8a

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

.yarn/versions/d6853e56.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-nm"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/extensions"
32+
- "@yarnpkg/nm"
33+
- "@yarnpkg/pnpify"
34+
- "@yarnpkg/sdks"

packages/yarnpkg-core/sources/nodeUtils.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {ppath} from '@yarnpkg/fslib';
2-
import os from 'os';
1+
import {PortablePath, ppath, xfs} from '@yarnpkg/fslib';
2+
import os from 'os';
33

4-
import * as execUtils from './execUtils';
5-
import * as miscUtils from './miscUtils';
4+
import * as execUtils from './execUtils';
5+
import * as miscUtils from './miscUtils';
66

77
export const major = Number(process.versions.node.split(`.`)[0]);
88

@@ -23,12 +23,29 @@ export const openUrl = typeof openUrlBinary !== `undefined`
2323
}
2424
: undefined;
2525

26+
const LDD_PATH = `/usr/bin/ldd` as PortablePath;
27+
2628
function getLibc() {
2729
// Darwin and Windows have their own standard libraries, and the getReport() call is costly.
2830
// It also seems that Node randomly crashes with no output under some circumstances when running a getReport() on Windows.
2931
if (process.platform === `darwin` || process.platform === `win32`)
3032
return null;
3133

34+
let header: Buffer | undefined;
35+
try {
36+
header = xfs.readFileSync(LDD_PATH);
37+
} catch {}
38+
39+
// Since the getReport can be prohibitely expensive (it also queries DNS which, if misconfigured, can take a long time to timeout),
40+
// we first check if the ldd binary is glibc or musl, and only then run the getReport() if we can't determine the libc variant.
41+
if (typeof header !== `undefined`) {
42+
if (header && header.includes(`GLIBC`))
43+
return `glibc`;
44+
if (header && header.includes(`musl`)) {
45+
return `musl`;
46+
}
47+
}
48+
3249
const report: any = process.report?.getReport() ?? {};
3350
const sharedObjects: Array<string> = report.sharedObjects ?? [];
3451

0 commit comments

Comments
 (0)