Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Unified Diff: mojo/dart/dart_snapshotter/main.cc

Issue 1273743005: Dart: Adds a program to create snapshots of Mojo apps. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix asan build Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/dart/dart_snapshotter/loader.cc ('k') | mojo/dart/dart_snapshotter/test/dart_snapshotter_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/dart/dart_snapshotter/main.cc
diff --git a/mojo/dart/dart_snapshotter/main.cc b/mojo/dart/dart_snapshotter/main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ec1e142d7f6aca8be25078205b654cb08efe4808
--- /dev/null
+++ b/mojo/dart/dart_snapshotter/main.cc
@@ -0,0 +1,73 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <iostream>
+
+#include "base/at_exit.h"
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/process/memory.h"
+#include "dart/runtime/include/dart_api.h"
+#include "mojo/dart/dart_snapshotter/loader.h"
+#include "mojo/dart/dart_snapshotter/vm.h"
+#include "tonic/dart_error.h"
+#include "tonic/dart_isolate_scope.h"
+
+const char kHelp[] = "help";
+const char kPackageRoot[] = "package-root";
+const char kSnapshot[] = "snapshot";
+
+void Usage() {
+ std::cerr << "Usage: dart_snapshotter"
+ << " --" << kPackageRoot << " --" << kSnapshot
+ << " <dart-app>" << std::endl;
+}
+
+void WriteSnapshot(base::FilePath path) {
+ uint8_t* buffer;
+ intptr_t size;
+ CHECK(!tonic::LogIfError(Dart_CreateScriptSnapshot(&buffer, &size)));
+
+ CHECK_EQ(base::WriteFile(path, reinterpret_cast<const char*>(buffer), size),
+ size);
+}
+
+int main(int argc, const char* argv[]) {
+ base::AtExitManager exit_manager;
+ base::EnableTerminationOnHeapCorruption();
+ base::CommandLine::Init(argc, argv);
+
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+
+ if (command_line.HasSwitch(kHelp) || command_line.GetArgs().empty()) {
+ Usage();
+ return 0;
+ }
+
+ InitDartVM();
+
+ CHECK(command_line.HasSwitch(kPackageRoot)) << "Need --package-root";
+ InitLoader(command_line.GetSwitchValuePath(kPackageRoot));
+
+ Dart_Isolate isolate = CreateDartIsolate();
+ CHECK(isolate);
+
+ tonic::DartIsolateScope scope(isolate);
+ tonic::DartApiScope api_scope;
+
+ auto args = command_line.GetArgs();
+ CHECK(args.size() == 1);
+ LoadScript(args[0]);
+
+ CHECK(!tonic::LogIfError(Dart_FinalizeLoading(true)));
+
+ CHECK(command_line.HasSwitch(kSnapshot)) << "Need --snapshot";
+ WriteSnapshot(command_line.GetSwitchValuePath(kSnapshot));
+
+ return 0;
+}
« no previous file with comments | « mojo/dart/dart_snapshotter/loader.cc ('k') | mojo/dart/dart_snapshotter/test/dart_snapshotter_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698