Skip to content

Commit 3f8f321

Browse files
committed
Add CCache to ENV
1 parent 54477be commit 3f8f321

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os from "node:os";
22
import syncFs from "node:fs";
33
import fs from "node:fs/promises";
4-
import { spawn, spawnSync } from "node:child_process";
4+
import { spawn } from "node:child_process";
55

66
const coreCount = os.cpus().length;
77
const threadCount = coreCount * 2;
8+
const ccacheEnv = { CC: "ccache gcc", CXX: "ccache g++" };
89

910
const nodejsGithubRepo = "https://github.com/nodejs/node";
1011
const removeTheVCharacter = (str) => str.replace("v", "");
@@ -35,11 +36,15 @@ const isANewerVersion = (oldVer, newVer) => {
3536
return false;
3637
};
3738

38-
const spawnAsync = (program, args, cwd) =>
39+
const spawnAsync = (program, args, cwd, env) =>
3940
new Promise((resolve, reject) => {
4041
console.log([program, ...args].join(" "));
4142

42-
const child = spawn(program, args, cwd ? { cwd } : {});
43+
const child = spawn(
44+
program,
45+
args,
46+
cwd ? { cwd, env: { ...process.env, ...env } } : {}
47+
);
4348

4449
child.stdout.on("data", (chunk) => console.log(chunk.toString()));
4550
child.stderr.on("data", (chunk) => console.warn(chunk.toString()));
@@ -62,14 +67,16 @@ if (!syncFs.existsSync("node")) {
6267
`v${latestNodeVersion}`,
6368
"--depth=1",
6469
],
65-
undefined
70+
undefined,
71+
{}
6672
);
6773
}
6874

6975
await spawnAsync(
7076
"./configure",
71-
["--ninja", "--shared", "--debug", "CC='ccache gcc'", "CXX='ccache g++'"],
72-
"node"
77+
["--ninja", "--shared", "--debug"],
78+
"node",
79+
ccacheEnv
7380
);
7481

75-
await spawnAsync("make", [`-j${threadCount}`], "node");
82+
await spawnAsync("make", [`-j${threadCount}`], "node", ccacheEnv);

0 commit comments

Comments
 (0)