Skip to content

Commit 544c602

Browse files
joyeecheungaduh95
authored andcommitted
module: skip NODE_COMPILE_CACHE when policy is enabled
It might be worth designing a policy for the compilation cache. For now, just skip the cache when policy is enabled. PR-URL: #52577 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 4f713fb commit 544c602

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/env.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@ void Environment::InitializeCompileCache() {
10961096
dir_from_env.empty()) {
10971097
return;
10981098
}
1099+
if (!options()->experimental_policy.empty()) {
1100+
Debug(this,
1101+
DebugCategory::COMPILE_CACHE,
1102+
"[compile cache] skipping cache because policy is enabled");
1103+
return;
1104+
}
10991105
auto handler = std::make_unique<CompileCacheHandler>(this);
11001106
if (handler->InitializeDirectory(this, dir_from_env)) {
11011107
compile_cache_handler_ = std::move(handler);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
// This tests NODE_COMPILE_CACHE is disabled when policy is used.
4+
5+
const common = require('../common');
6+
if (!common.hasCrypto)
7+
common.skip('missing crypto');
8+
9+
const { spawnSyncAndAssert } = require('../common/child_process');
10+
const assert = require('assert');
11+
const fs = require('fs');
12+
const tmpdir = require('../common/tmpdir');
13+
const fixtures = require('../common/fixtures');
14+
15+
{
16+
tmpdir.refresh();
17+
const dir = tmpdir.resolve('.compile_cache_dir');
18+
const script = fixtures.path('policy', 'parent.js');
19+
const policy = fixtures.path(
20+
'policy',
21+
'dependencies',
22+
'dependencies-redirect-policy.json');
23+
spawnSyncAndAssert(
24+
process.execPath,
25+
['--experimental-policy', policy, script],
26+
{
27+
env: {
28+
...process.env,
29+
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
30+
NODE_COMPILE_CACHE: dir
31+
},
32+
cwd: tmpdir.path
33+
},
34+
{
35+
stderr: /skipping cache because policy is enabled/
36+
});
37+
assert(!fs.existsSync(dir));
38+
}

0 commit comments

Comments
 (0)