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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <iostream>
6
7 #include "base/at_exit.h"
8 #include "base/basictypes.h"
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h"
12 #include "base/logging.h"
13 #include "base/process/memory.h"
14 #include "dart/runtime/include/dart_api.h"
15 #include "mojo/dart/dart_snapshotter/loader.h"
16 #include "mojo/dart/dart_snapshotter/logging.h"
17 #include "mojo/dart/dart_snapshotter/scope.h"
18 #include "mojo/dart/dart_snapshotter/switches.h"
19 #include "mojo/dart/dart_snapshotter/vm.h"
20
21 void Usage() {
22 std::cerr << "Usage: dart_snapshotter"
23 << " --" << switches::kPackageRoot << " --" << switches::kSnapshot
24 << " <dart-app>" << std::endl;
25 }
26
27 void WriteSnapshot(base::FilePath path) {
28 uint8_t* buffer;
29 intptr_t size;
30 CHECK(!LogIfError(Dart_CreateScriptSnapshot(&buffer, &size)));
31
32 CHECK_EQ(base::WriteFile(path, reinterpret_cast<const char*>(buffer), size),
33 size);
34 }
35
36 int main(int argc, const char* argv[]) {
37 base::AtExitManager exit_manager;
38 base::EnableTerminationOnHeapCorruption();
39 base::CommandLine::Init(argc, argv);
40
41 const base::CommandLine& command_line =
42 *base::CommandLine::ForCurrentProcess();
43
44 if (command_line.HasSwitch(switches::kHelp) ||
45 command_line.GetArgs().empty()) {
46 Usage();
47 return 0;
48 }
49
50 InitDartVM();
51 Dart_Isolate isolate = CreateDartIsolate();
52 CHECK(isolate);
53
54 DartIsolateScope scope(isolate);
55 DartApiScope api_scope;
56
57 auto args = command_line.GetArgs();
58 CHECK(args.size() == 1);
59 LoadScript(args[0]);
60
61 CHECK(!LogIfError(Dart_FinalizeLoading(true)));
62
63 CHECK(command_line.HasSwitch(switches::kSnapshot)) << "Need --snapshot";
64 WriteSnapshot(command_line.GetSwitchValuePath(switches::kSnapshot));
65
66 return 0;
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698