Files
node/tools/snapshot/node_mksnapshot.cc
T
Joyee Cheung b44323f3de tools: implement node_mksnapshot
Implements a node_mksnapshot target that generates a snapshot blob
from a Node.js main instance's isolate, and serializes the data blob
with other additional data into a C++ file that can be embedded into
the Node.js binary.

PR-URL: https://github.com/nodejs/node/pull/27321
Refs: https://github.com/nodejs/node/issues/17058
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2019-04-27 11:36:00 +02:00

52 lines
1.1 KiB
C++

#include <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "libplatform/libplatform.h"
#include "node_internals.h"
#include "snapshot_builder.h"
#include "v8.h"
#ifdef _WIN32
#include <windows.h>
int wmain(int argc, wchar_t* argv[]) {
#else // UNIX
int main(int argc, char* argv[]) {
#endif // _WIN32
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <path/to/output.cc>\n";
return 1;
}
std::ofstream out;
out.open(argv[1], std::ios::out | std::ios::binary);
if (!out.is_open()) {
std::cerr << "Cannot open " << argv[1] << "\n";
return 1;
}
int node_argc = 1;
char argv0[] = "node";
char* node_argv[] = {argv0, nullptr};
node::InitializationResult result =
node::InitializeOncePerProcess(node_argc, node_argv);
CHECK(!result.early_return);
CHECK_EQ(result.exit_code, 0);
{
std::string snapshot =
node::SnapshotBuilder::Generate(result.args, result.exec_args);
out << snapshot;
out.close();
}
node::TearDownOncePerProcess();
return 0;
}