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

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: code review fixes Created 8 years, 7 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 = NULL;
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
68 74
75 static void ProcessPackageRootOption(const char* arg) {
76 ASSERT(arg != NULL);
77 package_root = arg;
78 }
79
80
69 static void ProcessCompileAllOption(const char* compile_all) { 81 static void ProcessCompileAllOption(const char* compile_all) {
70 ASSERT(compile_all != NULL); 82 ASSERT(compile_all != NULL);
71 has_compile_all = true; 83 has_compile_all = true;
72 } 84 }
73 85
74 86
75 static void ProcessPprofOption(const char* filename) { 87 static void ProcessPprofOption(const char* filename) {
76 ASSERT(filename != NULL); 88 ASSERT(filename != NULL);
77 generate_pprof_symbols_filename = filename; 89 generate_pprof_symbols_filename = filename;
78 } 90 }
79 91
80 92
81 static void ProcessImportMapOption(const char* map) { 93 static void ProcessImportMapOption(const char* map) {
82 ASSERT(map != NULL); 94 ASSERT(map != NULL);
83 import_map_options->AddArgument(map); 95 import_map_options->AddArgument(map);
84 } 96 }
85 97
Ivan Posva 2012/04/26 05:32:09 Two lines.
86
87 static struct { 98 static struct {
88 const char* option_name; 99 const char* option_name;
89 void (*process)(const char* option); 100 void (*process)(const char* option);
90 } main_options[] = { 101 } main_options[] = {
91 { "--break_at=", ProcessBreakpointOption }, 102 { "--break_at=", ProcessBreakpointOption },
92 { "--compile_all", ProcessCompileAllOption }, 103 { "--compile_all", ProcessCompileAllOption },
93 { "--generate_pprof_symbols=", ProcessPprofOption }, 104 { "--generate_pprof_symbols=", ProcessPprofOption },
94 { "--import_map=", ProcessImportMapOption }, 105 { "--import_map=", ProcessImportMapOption },
106 { "--package-root=", ProcessPackageRootOption },
95 { NULL, NULL } 107 { NULL, NULL }
96 }; 108 };
97 109
98 110
99 static bool ProcessMainOptions(const char* option) { 111 static bool ProcessMainOptions(const char* option) {
100 int i = 0; 112 int i = 0;
101 const char* name = main_options[0].option_name; 113 const char* name = main_options[0].option_name;
102 while (name != NULL) { 114 while (name != NULL) {
103 int length = strlen(name); 115 int length = strlen(name);
104 if (strncmp(option, name, length) == 0) { 116 if (strncmp(option, name, length) == 0) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 370 Dart_ListSetAt(import_map, index, Dart_NewString(name));
359 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); 371 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name));
360 } else { 372 } else {
361 Dart_ListSetAt(import_map, index, Dart_NewString(name)); 373 Dart_ListSetAt(import_map, index, Dart_NewString(name));
362 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); 374 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(""));
363 } 375 }
364 free(name); 376 free(name);
365 } 377 }
366 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); 378 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map);
367 } 379 }
368 380
siva 2012/04/25 23:26:12 Missing blank line.
mattsh 2012/04/26 17:52:02 Done.
369 381 // Returns true on success, false on failure.
370 static bool CreateIsolateAndSetup(const char* name_prefix, 382 static bool CreateIsolateAndSetup(const char* name_prefix,
371 void* data, char** error) { 383 void* data, char** error) {
372 Dart_Isolate isolate = 384 Dart_Isolate isolate =
373 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); 385 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error);
374 if (isolate == NULL) { 386 if (isolate == NULL) {
375 return false; 387 return false;
376 } 388 }
377 389
378 Dart_EnterScope(); 390 Dart_EnterScope();
379 391
(...skipping 13 matching lines...) Expand all
393 if (Dart_IsError(builtin_lib)) { 405 if (Dart_IsError(builtin_lib)) {
394 *error = strdup(Dart_GetError(builtin_lib)); 406 *error = strdup(Dart_GetError(builtin_lib));
395 return false; 407 return false;
396 } 408 }
397 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); 409 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib);
398 if (Dart_IsError(library)) { 410 if (Dart_IsError(library)) {
399 *error = strdup(Dart_GetError(library)); 411 *error = strdup(Dart_GetError(library));
400 return false; 412 return false;
401 } 413 }
402 414
415 if (package_root != NULL) {
416 Dart_Handle dart_args[1];
417
418 Dart_Handle handle = Dart_NewString(package_root);
419 if (Dart_IsError(handle)) {
420 return false;
Ivan Posva 2012/04/26 05:32:09 This place is also missing the setup of the error
mattsh 2012/04/26 17:52:02 Done.
421 }
422 dart_args[0] = handle;
423
424 Dart_Handle result = Dart_Invoke(builtin_lib,
425 Dart_NewString("_setPackageRoot"), 1, dart_args);
426 if (Dart_IsError(result)) {
siva 2012/04/25 23:26:12 *error = strdup(Dart_GetError(result));
mattsh 2012/04/26 17:52:02 Done.
427 return false;
428 }
429 }
430
403 // Load the specified application script into the newly created isolate. 431 // Load the specified application script into the newly created isolate.
404 library = LoadScript(builtin_lib, import_map_options); 432 library = LoadScript(builtin_lib, import_map_options);
405 if (Dart_IsError(library)) { 433 if (Dart_IsError(library)) {
406 *error = strdup(Dart_GetError(library)); 434 *error = strdup(Dart_GetError(library));
407 Dart_ExitScope(); 435 Dart_ExitScope();
408 Dart_ShutdownIsolate(); 436 Dart_ShutdownIsolate();
409 return false; 437 return false;
410 } 438 }
411 if (!Dart_IsLibrary(library)) { 439 if (!Dart_IsLibrary(library)) {
412 char errbuf[256]; 440 char errbuf[256];
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 Dart_ShutdownIsolate(); 627 Dart_ShutdownIsolate();
600 // Terminate process exit-code handler. 628 // Terminate process exit-code handler.
601 Process::TerminateExitCodeHandler(); 629 Process::TerminateExitCodeHandler();
602 630
603 free(const_cast<char*>(original_script_name)); 631 free(const_cast<char*>(original_script_name));
604 free(const_cast<char*>(original_working_directory)); 632 free(const_cast<char*>(original_working_directory));
605 free(const_cast<char*>(original_script_url)); 633 free(const_cast<char*>(original_script_url));
606 634
607 return 0; 635 return 0;
608 } 636 }
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