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

Side by Side Diff: runtime/bin/main.cc

Issue 10134015: added package_root flag to standalone dart vm (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: small tweak Created 8 years, 8 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 | Annotate | Revision Log
« runtime/bin/builtin.dart ('K') | « runtime/bin/builtin.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_debugger_api.h" 10 #include "include/dart_debugger_api.h"
(...skipping 28 matching lines...) Expand all
39 // to be generated or not. 39 // to be generated or not.
40 static const char* generate_pprof_symbols_filename = NULL; 40 static const char* generate_pprof_symbols_filename = NULL;
41 41
42 42
43 // Global state that indicates whether there is a debug breakpoint. 43 // Global state that indicates whether there is a debug breakpoint.
44 // This pointer points into an argv buffer and does not need to be 44 // This pointer points into an argv buffer and does not need to be
45 // free'd. 45 // free'd.
46 static const char* breakpoint_at = NULL; 46 static const char* breakpoint_at = NULL;
47 47
48 48
49 // Value of the --package_root flag.
50 // (This pointer points into an argv buffer and does not need to be
51 // free'd.)
52 static const char* package_root;
siva 2012/04/22 00:14:01 need to initialize this to NULL otherwise your che
mattsh 2012/04/23 16:48:09 Actually C/C++ guarantee to initialize statics to
53
54
49 // Global flag that is used to indicate that we want to compile all the 55 // Global flag that is used to indicate that we want to compile all the
50 // dart functions and not run anything. 56 // dart functions and not run anything.
51 static bool has_compile_all = false; 57 static bool has_compile_all = false;
52 58
53 59
54 static bool IsValidFlag(const char* name, 60 static bool IsValidFlag(const char* name,
55 const char* prefix, 61 const char* prefix,
56 intptr_t prefix_length) { 62 intptr_t prefix_length) {
57 intptr_t name_length = strlen(name); 63 intptr_t name_length = strlen(name);
58 return ((name_length > prefix_length) && 64 return ((name_length > prefix_length) &&
59 (strncmp(name, prefix, prefix_length) == 0)); 65 (strncmp(name, prefix, prefix_length) == 0));
60 } 66 }
61 67
62 68
63 static void ProcessBreakpointOption(const char* funcname) { 69 static void ProcessBreakpointOption(const char* funcname) {
64 ASSERT(funcname != NULL); 70 ASSERT(funcname != NULL);
65 breakpoint_at = funcname; 71 breakpoint_at = funcname;
66 } 72 }
67 73
74 static void ProcessPackageRootOption(const char* arg) {
75 ASSERT(arg != NULL);
76 package_root = arg;
77 }
68 78
69 static void ProcessCompileAllOption(const char* compile_all) { 79 static void ProcessCompileAllOption(const char* compile_all) {
70 ASSERT(compile_all != NULL); 80 ASSERT(compile_all != NULL);
71 has_compile_all = true; 81 has_compile_all = true;
72 } 82 }
73 83
74 84
75 static void ProcessPprofOption(const char* filename) { 85 static void ProcessPprofOption(const char* filename) {
76 ASSERT(filename != NULL); 86 ASSERT(filename != NULL);
77 generate_pprof_symbols_filename = filename; 87 generate_pprof_symbols_filename = filename;
78 } 88 }
79 89
80 90
81 static void ProcessImportMapOption(const char* map) { 91 static void ProcessImportMapOption(const char* map) {
82 ASSERT(map != NULL); 92 ASSERT(map != NULL);
83 import_map_options->AddArgument(map); 93 import_map_options->AddArgument(map);
84 } 94 }
85 95
86
87 static struct { 96 static struct {
88 const char* option_name; 97 const char* option_name;
89 void (*process)(const char* option); 98 void (*process)(const char* option);
90 } main_options[] = { 99 } main_options[] = {
91 { "--break_at=", ProcessBreakpointOption }, 100 { "--break_at=", ProcessBreakpointOption },
92 { "--compile_all", ProcessCompileAllOption }, 101 { "--compile_all", ProcessCompileAllOption },
93 { "--generate_pprof_symbols=", ProcessPprofOption }, 102 { "--generate_pprof_symbols=", ProcessPprofOption },
94 { "--import_map=", ProcessImportMapOption }, 103 { "--import_map=", ProcessImportMapOption },
104 { "--package_root=", ProcessPackageRootOption },
95 { NULL, NULL } 105 { NULL, NULL }
96 }; 106 };
97 107
98 108
99 static bool ProcessMainOptions(const char* option) { 109 static bool ProcessMainOptions(const char* option) {
100 int i = 0; 110 int i = 0;
101 const char* name = main_options[0].option_name; 111 const char* name = main_options[0].option_name;
102 while (name != NULL) { 112 while (name != NULL) {
103 int length = strlen(name); 113 int length = strlen(name);
104 if (strncmp(option, name, length) == 0) { 114 if (strncmp(option, name, length) == 0) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (Dart_IsError(builtin_lib)) { 403 if (Dart_IsError(builtin_lib)) {
394 *error = strdup(Dart_GetError(builtin_lib)); 404 *error = strdup(Dart_GetError(builtin_lib));
395 return false; 405 return false;
396 } 406 }
397 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); 407 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib);
398 if (Dart_IsError(library)) { 408 if (Dart_IsError(library)) {
399 *error = strdup(Dart_GetError(library)); 409 *error = strdup(Dart_GetError(library));
400 return false; 410 return false;
401 } 411 }
402 412
413 if (package_root != NULL) {
414 Dart_Handle dart_args[1];
415 dart_args[0] = Dart_NewString(package_root);
siva 2012/04/22 00:14:01 Dart_NewString can return errors and that needs to
mattsh 2012/04/23 16:48:09 Added a TODO
siva 2012/04/23 17:16:45 Not sure why this needs to be a TODO and not fixed
mattsh 2012/04/23 18:12:55 OK, now added the error handling here and removed
416 Dart_Invoke(builtin_lib, Dart_NewString("_setPackageRoot"), 1, dart_args);
siva 2012/04/22 00:14:01 The return value from Dart_NewString and Dart_Invo
mattsh 2012/04/23 16:48:09 Added a TODO to add the error handling.
siva 2012/04/23 17:16:45 Ditto comment about why this needs to be a TODO.
mattsh 2012/04/23 18:12:55 Done.
mattsh 2012/04/23 18:12:55 Done.
417 }
418
403 // Load the specified application script into the newly created isolate. 419 // Load the specified application script into the newly created isolate.
404 library = LoadScript(builtin_lib, import_map_options); 420 library = LoadScript(builtin_lib, import_map_options);
405 if (Dart_IsError(library)) { 421 if (Dart_IsError(library)) {
406 *error = strdup(Dart_GetError(library)); 422 *error = strdup(Dart_GetError(library));
407 Dart_ExitScope(); 423 Dart_ExitScope();
408 Dart_ShutdownIsolate(); 424 Dart_ShutdownIsolate();
409 return false; 425 return false;
410 } 426 }
411 if (!Dart_IsLibrary(library)) { 427 if (!Dart_IsLibrary(library)) {
412 char errbuf[256]; 428 char errbuf[256];
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 Dart_ShutdownIsolate(); 615 Dart_ShutdownIsolate();
600 // Terminate process exit-code handler. 616 // Terminate process exit-code handler.
601 Process::TerminateExitCodeHandler(); 617 Process::TerminateExitCodeHandler();
602 618
603 free(const_cast<char*>(original_script_name)); 619 free(const_cast<char*>(original_script_name));
604 free(const_cast<char*>(original_working_directory)); 620 free(const_cast<char*>(original_working_directory));
605 free(const_cast<char*>(original_script_url)); 621 free(const_cast<char*>(original_script_url));
606 622
607 return 0; 623 return 0;
608 } 624 }
OLDNEW
« runtime/bin/builtin.dart ('K') | « runtime/bin/builtin.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698