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

Side by Side Diff: sky/tools/packager/main.cc

Issue 1212623002: Support snapshots in sky_shell (again) (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « sky/tools/packager/loader.cc ('k') | sky/tools/packager/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iostream> 5 #include <iostream>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/process/memory.h" 13 #include "base/process/memory.h"
14 #include "dart/runtime/include/dart_api.h" 14 #include "dart/runtime/include/dart_api.h"
15 #include "sky/tools/packager/loader.h" 15 #include "sky/tools/packager/loader.h"
16 #include "sky/tools/packager/logging.h" 16 #include "sky/tools/packager/logging.h"
17 #include "sky/tools/packager/scope.h" 17 #include "sky/tools/packager/scope.h"
18 #include "sky/tools/packager/switches.h" 18 #include "sky/tools/packager/switches.h"
19 #include "sky/tools/packager/vm.h" 19 #include "sky/tools/packager/vm.h"
20 20
21 void Usage() {
22 std::cerr << "Usage: sky_packager"
23 << " --" << switches::kPackageRoot << " --" << switches::kSnapshot
24 << " <sky-app>" << std::endl;
25 }
26
21 void WriteSnapshot(base::FilePath path) { 27 void WriteSnapshot(base::FilePath path) {
22 uint8_t* buffer; 28 uint8_t* buffer;
23 intptr_t size; 29 intptr_t size;
24 CHECK(!LogIfError(Dart_CreateScriptSnapshot(&buffer, &size))); 30 CHECK(!LogIfError(Dart_CreateScriptSnapshot(&buffer, &size)));
25 31
26 CHECK_EQ(base::WriteFile(path, reinterpret_cast<const char*>(buffer), size), 32 CHECK_EQ(base::WriteFile(path, reinterpret_cast<const char*>(buffer), size),
27 size); 33 size);
28 34
29 std::cout << "Successfully wrote snapshot to " << path.LossyDisplayName() 35 std::cout << "Successfully wrote snapshot to " << path.LossyDisplayName()
30 << " (" << size << " bytes)." << std::endl; 36 << " (" << size << " bytes)." << std::endl;
31 } 37 }
32 38
33 int main(int argc, const char* argv[]) { 39 int main(int argc, const char* argv[]) {
34 base::AtExitManager exit_manager; 40 base::AtExitManager exit_manager;
35 base::EnableTerminationOnHeapCorruption(); 41 base::EnableTerminationOnHeapCorruption();
36 base::CommandLine::Init(argc, argv); 42 base::CommandLine::Init(argc, argv);
37 43
44 const base::CommandLine& command_line =
45 *base::CommandLine::ForCurrentProcess();
46
47 if (command_line.HasSwitch(switches::kHelp) ||
48 command_line.GetArgs().empty()) {
49 Usage();
50 return 0;
51 }
52
38 InitDartVM(); 53 InitDartVM();
39 Dart_Isolate isolate = CreateDartIsolate(); 54 Dart_Isolate isolate = CreateDartIsolate();
40 CHECK(isolate); 55 CHECK(isolate);
41 56
42 const base::CommandLine& command_line =
43 *base::CommandLine::ForCurrentProcess();
44
45 DartIsolateScope scope(isolate); 57 DartIsolateScope scope(isolate);
46 DartApiScope api_scope; 58 DartApiScope api_scope;
47 59
48 auto args = command_line.GetArgs(); 60 auto args = command_line.GetArgs();
49 CHECK(args.size() == 1); 61 CHECK(args.size() == 1);
50 LoadScript(args[0]); 62 LoadScript(args[0]);
51 63
52 CHECK(!LogIfError(Dart_FinalizeLoading(true))); 64 CHECK(!LogIfError(Dart_FinalizeLoading(true)));
53 65
54 CHECK(command_line.HasSwitch(kSnapshot)) << "Need --snapshot"; 66 CHECK(command_line.HasSwitch(switches::kSnapshot)) << "Need --snapshot";
55 WriteSnapshot(command_line.GetSwitchValuePath(kSnapshot)); 67 WriteSnapshot(command_line.GetSwitchValuePath(switches::kSnapshot));
56 68
57 return 0; 69 return 0;
58 } 70 }
OLDNEW
« no previous file with comments | « sky/tools/packager/loader.cc ('k') | sky/tools/packager/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698