Skip to content

Commit

Permalink
src: make build_snapshot a per-Isolate option, rather than a global one
Browse files Browse the repository at this point in the history
PR-URL: #45888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
addaleax authored and MylesBorins committed Feb 18, 2023
1 parent 6801d37 commit 658d2f4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/node.cc
Expand Up @@ -307,7 +307,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
return StartExecution(env, "internal/main/inspect");
}

if (per_process::cli_options->build_snapshot) {
if (env->isolate_data()->options()->build_snapshot) {
return StartExecution(env, "internal/main/mksnapshot");
}

Expand Down Expand Up @@ -1221,7 +1221,7 @@ static ExitCode StartInternal(int argc, char** argv) {
uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);

// --build-snapshot indicates that we are in snapshot building mode.
if (per_process::cli_options->build_snapshot) {
if (per_process::cli_options->per_isolate->build_snapshot) {
if (result->args().size() < 2) {
fprintf(stderr,
"--build-snapshot must be used with an entry point script.\n"
Expand Down
10 changes: 5 additions & 5 deletions src/node_options.cc
Expand Up @@ -777,6 +777,11 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
Implies("--experimental-shadow-realm", "--harmony-shadow-realm");
Implies("--harmony-shadow-realm", "--experimental-shadow-realm");
ImpliesNot("--no-harmony-shadow-realm", "--experimental-shadow-realm");
AddOption("--build-snapshot",
"Generate a snapshot blob when the process exits."
" Currently only supported in the node_mksnapshot binary.",
&PerIsolateOptions::build_snapshot,
kDisallowedInEnvvar);

Insert(eop, &PerIsolateOptions::get_per_env_options);
}
Expand Down Expand Up @@ -815,11 +820,6 @@ PerProcessOptionsParser::PerProcessOptionsParser(
"disable Object.prototype.__proto__",
&PerProcessOptions::disable_proto,
kAllowedInEnvvar);
AddOption("--build-snapshot",
"Generate a snapshot blob when the process exits."
" Currently only supported in the node_mksnapshot binary.",
&PerProcessOptions::build_snapshot,
kDisallowedInEnvvar);
AddOption("--node-snapshot",
"", // It's a debug-only option.
&PerProcessOptions::node_snapshot,
Expand Down
2 changes: 1 addition & 1 deletion src/node_options.h
Expand Up @@ -224,6 +224,7 @@ class PerIsolateOptions : public Options {
bool report_on_signal = false;
bool experimental_shadow_realm = false;
std::string report_signal = "SIGUSR2";
bool build_snapshot = false;
inline EnvironmentOptions* get_per_env_options();
void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) override;
Expand All @@ -248,7 +249,6 @@ class PerProcessOptions : public Options {
bool zero_fill_all_buffers = false;
bool debug_arraybuffer_allocations = false;
std::string disable_proto;
bool build_snapshot = false;
// We enable the shared read-only heap which currently requires that the
// snapshot used in different isolates in the same process to be the same.
// Therefore --node-snapshot is a per-process option.
Expand Down
2 changes: 1 addition & 1 deletion src/node_snapshotable.cc
Expand Up @@ -1136,7 +1136,7 @@ ExitCode SnapshotBuilder::Generate(SnapshotData* out,

// It's only possible to be kDefault in node_mksnapshot.
SnapshotMetadata::Type snapshot_type =
per_process::cli_options->build_snapshot
per_process::cli_options->per_isolate->build_snapshot
? SnapshotMetadata::Type::kFullyCustomized
: SnapshotMetadata::Type::kDefault;

Expand Down
2 changes: 1 addition & 1 deletion tools/snapshot/node_mksnapshot.cc
Expand Up @@ -72,7 +72,7 @@ int BuildSnapshot(int argc, char* argv[]) {
CHECK_EQ(result->exit_code(), 0);

std::string out_path;
if (node::per_process::cli_options->build_snapshot) {
if (node::per_process::cli_options->per_isolate->build_snapshot) {
out_path = result->args()[2];
} else {
out_path = result->args()[1];
Expand Down

0 comments on commit 658d2f4

Please sign in to comment.