mirror of
https://github.com/nodejs/node.git
synced 2026-11-15 10:36:53 -05:00
This implements the execArgvExtension configuration field for SEA, which takes one of three string values to specify whether and how execution arguments can be extended for the SEA at run time: * `"none"`: No extension is allowed. Only the arguments specified in `execArgv` will be used, and the `NODE_OPTIONS` environment variable will be ignored. * `"env"`: _(Default)_ The `NODE_OPTIONS` environment variable can extend the execution arguments. This is the default behavior to maintain backward compatibility. * `"cli"`: The executable can be launched with `--node-options="--flag1 --flag2"`, and those flags will be parsed as execution arguments for Node.js instead of being passed to the user script. This allows using arguments that are not supported by the `NODE_OPTIONS` environment variable. PR-URL: https://github.com/nodejs/node/pull/59560 Fixes: https://github.com/nodejs/node/issues/55573 Fixes: https://github.com/nodejs/single-executable/issues/100 Refs: https://github.com/nodejs/node/issues/51688 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
#ifndef SRC_NODE_SEA_H_
|
|
#define SRC_NODE_SEA_H_
|
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#include <cinttypes>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <tuple>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include "node_exit_code.h"
|
|
|
|
namespace node {
|
|
class Environment;
|
|
namespace sea {
|
|
// A special number that will appear at the beginning of the single executable
|
|
// preparation blobs ready to be injected into the binary. We use this to check
|
|
// that the data given to us are intended for building single executable
|
|
// applications.
|
|
const uint32_t kMagic = 0x143da20;
|
|
|
|
enum class SeaFlags : uint32_t {
|
|
kDefault = 0,
|
|
kDisableExperimentalSeaWarning = 1 << 0,
|
|
kUseSnapshot = 1 << 1,
|
|
kUseCodeCache = 1 << 2,
|
|
kIncludeAssets = 1 << 3,
|
|
kIncludeExecArgv = 1 << 4,
|
|
};
|
|
|
|
enum class SeaExecArgvExtension : uint8_t {
|
|
kNone = 0,
|
|
kEnv = 1,
|
|
kCli = 2,
|
|
};
|
|
|
|
struct SeaResource {
|
|
SeaFlags flags = SeaFlags::kDefault;
|
|
SeaExecArgvExtension exec_argv_extension = SeaExecArgvExtension::kEnv;
|
|
std::string_view code_path;
|
|
std::string_view main_code_or_snapshot;
|
|
std::optional<std::string_view> code_cache;
|
|
std::unordered_map<std::string_view, std::string_view> assets;
|
|
std::vector<std::string_view> exec_argv;
|
|
|
|
bool use_snapshot() const;
|
|
bool use_code_cache() const;
|
|
|
|
static constexpr size_t kHeaderSize =
|
|
sizeof(kMagic) + sizeof(SeaFlags) + sizeof(SeaExecArgvExtension);
|
|
};
|
|
|
|
bool IsSingleExecutable();
|
|
SeaResource FindSingleExecutableResource();
|
|
std::tuple<int, char**> FixupArgsForSEA(int argc, char** argv);
|
|
node::ExitCode BuildSingleExecutableBlob(
|
|
const std::string& config_path,
|
|
const std::vector<std::string>& args,
|
|
const std::vector<std::string>& exec_args);
|
|
|
|
// Try loading the Environment as a single-executable application.
|
|
// Returns true if it is loaded as a single-executable application.
|
|
// Otherwise returns false and the caller is expected to call LoadEnvironment()
|
|
// differently.
|
|
bool MaybeLoadSingleExecutableApplication(Environment* env);
|
|
} // namespace sea
|
|
} // namespace node
|
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#endif // SRC_NODE_SEA_H_
|