From 0d435bc64a984e9a1bb4640f20012662ea061b62 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 18 Apr 2024 14:31:09 +0200 Subject: [PATCH 1/3] 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. --- src/env.cc | 6 ++++ test/parallel/test-compile-cache-policy.js | 36 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/parallel/test-compile-cache-policy.js diff --git a/src/env.cc b/src/env.cc index b8574fcfb775b8..642a7d4a9d2559 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1096,6 +1096,12 @@ void Environment::InitializeCompileCache() { dir_from_env.empty()) { return; } + if (!options()->experimental_policy.empty()) { + Debug(this, + DebugCategory::COMPILE_CACHE, + "[compile cache] skipping cache because policy is enabled"); + return; + } auto handler = std::make_unique(this); if (handler->InitializeDirectory(this, dir_from_env)) { compile_cache_handler_ = std::move(handler); diff --git a/test/parallel/test-compile-cache-policy.js b/test/parallel/test-compile-cache-policy.js new file mode 100644 index 00000000000000..4b05be3439f7d4 --- /dev/null +++ b/test/parallel/test-compile-cache-policy.js @@ -0,0 +1,36 @@ +'use strict'; + +// This tests NODE_COMPILE_CACHE is disabled when policy is used. + +require('../common'); +const { spawnSyncAndAssert } = require('../common/child_process'); +const assert = require('assert'); +const fs = require('fs'); +const tmpdir = require('../common/tmpdir'); +const fixtures = require('../common/fixtures'); + +{ + tmpdir.refresh(); + const dir = tmpdir.resolve('.compile_cache_dir'); + const script = fixtures.path('policy', 'parent.js'); + const policy = fixtures.path( + 'policy', + 'dependencies', + 'dependencies-redirect-policy.json'); + spawnSyncAndAssert( + process.execPath, + ['--experimental-policy', policy, script], + { + env: { + ...process.env, + NODE_DEBUG_NATIVE: 'COMPILE_CACHE', + NODE_COMPILE_CACHE: dir + }, + cwd: tmpdir.path + }, + { + stderr: /skipping cache because policy is enabled/ + }); + assert(!fs.existsSync(dir)); +} + From d4175cb4d58b4668128949297dd526c97657100c Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 18 Apr 2024 14:38:58 +0200 Subject: [PATCH 2/3] fixup! module: skip NODE_COMPILE_CACHE when policy is enabled --- test/parallel/test-compile-cache-policy.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-compile-cache-policy.js b/test/parallel/test-compile-cache-policy.js index 4b05be3439f7d4..d52a3d7c600e95 100644 --- a/test/parallel/test-compile-cache-policy.js +++ b/test/parallel/test-compile-cache-policy.js @@ -33,4 +33,3 @@ const fixtures = require('../common/fixtures'); }); assert(!fs.existsSync(dir)); } - From b0d7f4a77ed90882c4f0b1dd6a94ae85a6097a98 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 22 Apr 2024 17:38:42 +0200 Subject: [PATCH 3/3] fixup! fixup! module: skip NODE_COMPILE_CACHE when policy is enabled --- test/parallel/test-compile-cache-policy.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-compile-cache-policy.js b/test/parallel/test-compile-cache-policy.js index d52a3d7c600e95..fd6fe36bcc0cd9 100644 --- a/test/parallel/test-compile-cache-policy.js +++ b/test/parallel/test-compile-cache-policy.js @@ -2,7 +2,10 @@ // This tests NODE_COMPILE_CACHE is disabled when policy is used. -require('../common'); +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + const { spawnSyncAndAssert } = require('../common/child_process'); const assert = require('assert'); const fs = require('fs');