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

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

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 years, 3 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 | « runtime/bin/io_sources.gni ('k') | runtime/bin/namespace.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 (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 <stdio.h> 5 #include <stdio.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 if (commandline_root_certs_file != NULL) { 575 if (commandline_root_certs_file != NULL) {
576 Log::PrintErr( 576 Log::PrintErr(
577 "Only one of --root-certs-file and --root-certs-cache " 577 "Only one of --root-certs-file and --root-certs-cache "
578 "may be specified"); 578 "may be specified");
579 return false; 579 return false;
580 } 580 }
581 commandline_root_certs_cache = arg; 581 commandline_root_certs_cache = arg;
582 return true; 582 return true;
583 } 583 }
584 584
585 const char* commandline_namespace = NULL;
586 static bool ProcessNamespaceOption(const char* arg,
587 CommandLineOptions* vm_options) {
588 ASSERT(arg != NULL);
589 if (*arg == '-') {
590 return false;
591 }
592 if (commandline_namespace != NULL) {
593 Log::PrintErr("Only one --namespace argument is allowed.");
594 return false;
595 }
596 commandline_namespace = arg;
597 return true;
598 }
599
585 static struct { 600 static struct {
586 const char* option_name; 601 const char* option_name;
587 bool (*process)(const char* option, CommandLineOptions* vm_options); 602 bool (*process)(const char* option, CommandLineOptions* vm_options);
588 } main_options[] = { 603 } main_options[] = {
589 // Standard options shared with dart2js. 604 // Standard options shared with dart2js.
590 {"-D", ProcessEnvironmentOption}, 605 {"-D", ProcessEnvironmentOption},
591 {"-h", ProcessHelpOption}, 606 {"-h", ProcessHelpOption},
592 {"--help", ProcessHelpOption}, 607 {"--help", ProcessHelpOption},
593 {"--packages=", ProcessPackagesOption}, 608 {"--packages=", ProcessPackagesOption},
594 {"--package-root=", ProcessPackageRootOption}, 609 {"--package-root=", ProcessPackageRootOption},
(...skipping 21 matching lines...) Expand all
616 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption}, 631 {"--load-compilation-trace=", ProcessLoadCompilationTraceOption},
617 {"--save-feedback=", ProcessSaveFeedbackOption}, 632 {"--save-feedback=", ProcessSaveFeedbackOption},
618 {"--load-feedback=", ProcessLoadFeedbackOption}, 633 {"--load-feedback=", ProcessLoadFeedbackOption},
619 {"--trace-loading", ProcessTraceLoadingOption}, 634 {"--trace-loading", ProcessTraceLoadingOption},
620 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, 635 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption},
621 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, 636 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption},
622 {"--short_socket_read", ProcessShortSocketReadOption}, 637 {"--short_socket_read", ProcessShortSocketReadOption},
623 {"--short_socket_write", ProcessShortSocketWriteOption}, 638 {"--short_socket_write", ProcessShortSocketWriteOption},
624 {"--root-certs-file=", ProcessRootCertsFileOption}, 639 {"--root-certs-file=", ProcessRootCertsFileOption},
625 {"--root-certs-cache=", ProcessRootCertsCacheOption}, 640 {"--root-certs-cache=", ProcessRootCertsCacheOption},
641 {"--namespace=", ProcessNamespaceOption},
626 {NULL, NULL}}; 642 {NULL, NULL}};
627 643
628 static bool ProcessMainOptions(const char* option, 644 static bool ProcessMainOptions(const char* option,
629 CommandLineOptions* vm_options) { 645 CommandLineOptions* vm_options) {
630 int i = 0; 646 int i = 0;
631 const char* name = main_options[0].option_name; 647 const char* name = main_options[0].option_name;
632 int option_length = strlen(option); 648 int option_length = strlen(option);
633 while (name != NULL) { 649 while (name != NULL) {
634 int length = strlen(name); 650 int length = strlen(name);
635 if ((option_length >= length) && (strncmp(option, name, length) == 0)) { 651 if ((option_length >= length) && (strncmp(option, name, length) == 0)) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 CHECK_RESULT(result); 921 CHECK_RESULT(result);
906 922
907 // Setup package root if specified. 923 // Setup package root if specified.
908 result = DartUtils::SetupPackageRoot(package_root, packages_config); 924 result = DartUtils::SetupPackageRoot(package_root, packages_config);
909 CHECK_RESULT(result); 925 CHECK_RESULT(result);
910 926
911 result = Dart_SetEnvironmentCallback(EnvironmentCallback); 927 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
912 CHECK_RESULT(result); 928 CHECK_RESULT(result);
913 929
914 if (isolate_run_app_snapshot) { 930 if (isolate_run_app_snapshot) {
915 result = DartUtils::SetupIOLibrary(script_uri); 931 result = DartUtils::SetupIOLibrary(commandline_namespace, script_uri);
916 CHECK_RESULT(result); 932 CHECK_RESULT(result);
917 Loader::InitForSnapshot(script_uri); 933 Loader::InitForSnapshot(script_uri);
918 #if !defined(DART_PRECOMPILED_RUNTIME) 934 #if !defined(DART_PRECOMPILED_RUNTIME)
919 if (is_main_isolate) { 935 if (is_main_isolate) {
920 // Find the canonical uri of the app snapshot. We'll use this to decide if 936 // Find the canonical uri of the app snapshot. We'll use this to decide if
921 // other isolates should use the app snapshot or the core snapshot. 937 // other isolates should use the app snapshot or the core snapshot.
922 const char* resolved_script_uri = NULL; 938 const char* resolved_script_uri = NULL;
923 result = Dart_StringToCString( 939 result = Dart_StringToCString(
924 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)), 940 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)),
925 &resolved_script_uri); 941 &resolved_script_uri);
(...skipping 15 matching lines...) Expand all
941 // relative URIs and perform other related tasks. We need Loader to be 957 // relative URIs and perform other related tasks. We need Loader to be
942 // initialized for this to work because loading from Kernel binary 958 // initialized for this to work because loading from Kernel binary
943 // bypasses normal source code loading paths that initialize it. 959 // bypasses normal source code loading paths that initialize it.
944 Loader::InitForSnapshot(script_uri); 960 Loader::InitForSnapshot(script_uri);
945 } 961 }
946 962
947 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), 963 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(),
948 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, 964 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0,
949 NULL, NULL); 965 NULL, NULL);
950 966
951 result = DartUtils::SetupIOLibrary(script_uri); 967 result = DartUtils::SetupIOLibrary(commandline_namespace, script_uri);
952 CHECK_RESULT(result); 968 CHECK_RESULT(result);
953 } 969 }
954 970
955 // Make the isolate runnable so that it is ready to handle messages. 971 // Make the isolate runnable so that it is ready to handle messages.
956 Dart_ExitScope(); 972 Dart_ExitScope();
957 Dart_ExitIsolate(); 973 Dart_ExitIsolate();
958 bool retval = Dart_IsolateMakeRunnable(isolate); 974 bool retval = Dart_IsolateMakeRunnable(isolate);
959 if (!retval) { 975 if (!retval) {
960 *error = strdup("Invalid isolate state - Unable to make it runnable"); 976 *error = strdup("Invalid isolate state - Unable to make it runnable");
961 Dart_EnterIsolate(isolate); 977 Dart_EnterIsolate(isolate);
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 " (default port number is 8181, default bind address is localhost).\n" 1329 " (default port number is 8181, default bind address is localhost).\n"
1314 #if !defined(HOST_OS_MACOS) 1330 #if !defined(HOST_OS_MACOS)
1315 "\n" 1331 "\n"
1316 "--root-certs-file=<path>\n" 1332 "--root-certs-file=<path>\n"
1317 " The path to a file containing the trusted root certificates to use for\n" 1333 " The path to a file containing the trusted root certificates to use for\n"
1318 " secure socket connections.\n" 1334 " secure socket connections.\n"
1319 "--root-certs-cache=<path>\n" 1335 "--root-certs-cache=<path>\n"
1320 " The path to a cache directory containing the trusted root certificates to\n" 1336 " The path to a cache directory containing the trusted root certificates to\n"
1321 " use for secure socket connections.\n" 1337 " use for secure socket connections.\n"
1322 #endif // !defined(HOST_OS_MACOS) 1338 #endif // !defined(HOST_OS_MACOS)
1339 #if defined(HOST_OS_LINUX)
1340 "--namespace=<path>\n"
1341 " The path to a directory that dart:io calls will treat as the root of the\n"
1342 " filesystem.\n"
1343 #endif // defined(HOST_OS_LINUX)
1323 "\n" 1344 "\n"
1324 "The following options are only used for VM development and may\n" 1345 "The following options are only used for VM development and may\n"
1325 "be changed in any future version:\n"); 1346 "be changed in any future version:\n");
1326 const char* print_flags = "--print_flags"; 1347 const char* print_flags = "--print_flags";
1327 Dart_SetVMFlags(1, &print_flags); 1348 Dart_SetVMFlags(1, &print_flags);
1328 } 1349 }
1329 } 1350 }
1330 // clang-format on 1351 // clang-format on
1331 1352
1332 char* BuildIsolateName(const char* script_name, const char* func_name) { 1353 char* BuildIsolateName(const char* script_name, const char* func_name) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 } 1397 }
1377 } 1398 }
1378 1399
1379 static bool FileModifiedCallback(const char* url, int64_t since) { 1400 static bool FileModifiedCallback(const char* url, int64_t since) {
1380 if (strncmp(url, "file:///", 8) == 0) { 1401 if (strncmp(url, "file:///", 8) == 0) {
1381 // If it isn't a file on local disk, we don't know if it has been 1402 // If it isn't a file on local disk, we don't know if it has been
1382 // modified. 1403 // modified.
1383 return true; 1404 return true;
1384 } 1405 }
1385 int64_t data[File::kStatSize]; 1406 int64_t data[File::kStatSize];
1386 File::Stat(url + 7, data); 1407 File::Stat(NULL, url + 7, data);
1387 if (data[File::kType] == File::kDoesNotExist) { 1408 if (data[File::kType] == File::kDoesNotExist) {
1388 return true; 1409 return true;
1389 } 1410 }
1390 bool modified = data[File::kModifiedTime] > since; 1411 bool modified = data[File::kModifiedTime] > since;
1391 return modified; 1412 return modified;
1392 } 1413 }
1393 1414
1394 static void EmbedderInformationCallback(Dart_EmbedderInformation* info) { 1415 static void EmbedderInformationCallback(Dart_EmbedderInformation* info) {
1395 info->version = DART_EMBEDDER_INFORMATION_CURRENT_VERSION; 1416 info->version = DART_EMBEDDER_INFORMATION_CURRENT_VERSION;
1396 info->name = "Dart VM"; 1417 info->name = "Dart VM";
(...skipping 12 matching lines...) Expand all
1409 if (Dart_IsError(result)) { \ 1430 if (Dart_IsError(result)) { \
1410 const int exit_code = Dart_IsCompilationError(result) \ 1431 const int exit_code = Dart_IsCompilationError(result) \
1411 ? kCompilationErrorExitCode \ 1432 ? kCompilationErrorExitCode \
1412 : kErrorExitCode; \ 1433 : kErrorExitCode; \
1413 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ 1434 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \
1414 } 1435 }
1415 1436
1416 static void WriteFile(const char* filename, 1437 static void WriteFile(const char* filename,
1417 const uint8_t* buffer, 1438 const uint8_t* buffer,
1418 const intptr_t size) { 1439 const intptr_t size) {
1419 File* file = File::Open(filename, File::kWriteTruncate); 1440 File* file = File::Open(NULL, filename, File::kWriteTruncate);
1420 if (file == NULL) { 1441 if (file == NULL) {
1421 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename); 1442 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
1422 } 1443 }
1423 if (!file->WriteFully(buffer, size)) { 1444 if (!file->WriteFully(buffer, size)) {
1424 ErrorExit(kErrorExitCode, "Unable to write file %s\n", filename); 1445 ErrorExit(kErrorExitCode, "Unable to write file %s\n", filename);
1425 } 1446 }
1426 file->Release(); 1447 file->Release();
1427 } 1448 }
1428 1449
1429 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) { 1450 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) {
1430 File* file = File::Open(filename, File::kRead); 1451 File* file = File::Open(NULL, filename, File::kRead);
1431 if (file == NULL) { 1452 if (file == NULL) {
1432 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename); 1453 ErrorExit(kErrorExitCode, "Unable to open file %s\n", filename);
1433 } 1454 }
1434 *size = file->Length(); 1455 *size = file->Length();
1435 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); 1456 *buffer = reinterpret_cast<uint8_t*>(malloc(*size));
1436 if (!file->ReadFully(*buffer, *size)) { 1457 if (!file->ReadFully(*buffer, *size)) {
1437 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename); 1458 ErrorExit(kErrorExitCode, "Unable to read file %s\n", filename);
1438 } 1459 }
1439 file->Release(); 1460 file->Release();
1440 } 1461 }
(...skipping 19 matching lines...) Expand all
1460 {"dart:io", "HandshakeException", "HandshakeException."}, 1481 {"dart:io", "HandshakeException", "HandshakeException."},
1461 {"dart:io", "Link", "Link."}, 1482 {"dart:io", "Link", "Link."},
1462 {"dart:io", "OSError", "OSError."}, 1483 {"dart:io", "OSError", "OSError."},
1463 {"dart:io", "TlsException", "TlsException."}, 1484 {"dart:io", "TlsException", "TlsException."},
1464 {"dart:io", "X509Certificate", "X509Certificate._"}, 1485 {"dart:io", "X509Certificate", "X509Certificate._"},
1465 {"dart:io", "_ExternalBuffer", "get:end"}, 1486 {"dart:io", "_ExternalBuffer", "get:end"},
1466 {"dart:io", "_ExternalBuffer", "get:start"}, 1487 {"dart:io", "_ExternalBuffer", "get:start"},
1467 {"dart:io", "_ExternalBuffer", "set:data"}, 1488 {"dart:io", "_ExternalBuffer", "set:data"},
1468 {"dart:io", "_ExternalBuffer", "set:end"}, 1489 {"dart:io", "_ExternalBuffer", "set:end"},
1469 {"dart:io", "_ExternalBuffer", "set:start"}, 1490 {"dart:io", "_ExternalBuffer", "set:start"},
1491 {"dart:io", "_Namespace", "_setupNamespace"},
1470 {"dart:io", "_Platform", "set:_nativeScript"}, 1492 {"dart:io", "_Platform", "set:_nativeScript"},
1471 {"dart:io", "_ProcessStartStatus", "set:_errorCode"}, 1493 {"dart:io", "_ProcessStartStatus", "set:_errorCode"},
1472 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"}, 1494 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"},
1473 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"}, 1495 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"},
1474 {"dart:io", "_SecureFilterImpl", "get:SIZE"}, 1496 {"dart:io", "_SecureFilterImpl", "get:SIZE"},
1475 {"dart:io", "_SecureFilterImpl", "get:buffers"}, 1497 {"dart:io", "_SecureFilterImpl", "get:buffers"},
1476 {"dart:isolate", "::", "_getIsolateScheduleImmediateClosure"}, 1498 {"dart:isolate", "::", "_getIsolateScheduleImmediateClosure"},
1477 {"dart:isolate", "::", "_setupHooks"}, 1499 {"dart:isolate", "::", "_setupHooks"},
1478 {"dart:isolate", "::", "_startMainIsolate"}, 1500 {"dart:isolate", "::", "_startMainIsolate"},
1479 {"dart:vmservice_io", "::", "main"}, 1501 {"dart:vmservice_io", "::", "main"},
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 Dart_ExitScope(); 1601 Dart_ExitScope();
1580 // Shutdown the isolate. 1602 // Shutdown the isolate.
1581 Dart_ShutdownIsolate(); 1603 Dart_ShutdownIsolate();
1582 return false; 1604 return false;
1583 } 1605 }
1584 1606
1585 if (gen_snapshot_kind == kAppAOT) { 1607 if (gen_snapshot_kind == kAppAOT) {
1586 uint8_t* feedback_buffer = NULL; 1608 uint8_t* feedback_buffer = NULL;
1587 intptr_t feedback_length = 0; 1609 intptr_t feedback_length = 0;
1588 if (load_feedback_filename != NULL) { 1610 if (load_feedback_filename != NULL) {
1589 File* file = File::Open(load_feedback_filename, File::kRead); 1611 File* file = File::Open(NULL, load_feedback_filename, File::kRead);
1590 if (file == NULL) { 1612 if (file == NULL) {
1591 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); 1613 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n");
1592 } 1614 }
1593 feedback_length = file->Length(); 1615 feedback_length = file->Length();
1594 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length)); 1616 feedback_buffer = reinterpret_cast<uint8_t*>(malloc(feedback_length));
1595 if (!file->ReadFully(feedback_buffer, feedback_length)) { 1617 if (!file->ReadFully(feedback_buffer, feedback_length)) {
1596 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n"); 1618 ErrorExit(kErrorExitCode, "Failed to read JIT feedback.\n");
1597 } 1619 }
1598 file->Release(); 1620 file->Release();
1599 } 1621 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 } 1710 }
1689 } 1711 }
1690 1712
1691 if (snapshot_deps_filename != NULL) { 1713 if (snapshot_deps_filename != NULL) {
1692 Loader::ResolveDependenciesAsFilePaths(); 1714 Loader::ResolveDependenciesAsFilePaths();
1693 IsolateData* isolate_data = 1715 IsolateData* isolate_data =
1694 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); 1716 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate));
1695 ASSERT(isolate_data != NULL); 1717 ASSERT(isolate_data != NULL);
1696 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); 1718 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies();
1697 ASSERT(dependencies != NULL); 1719 ASSERT(dependencies != NULL);
1698 File* file = File::Open(snapshot_deps_filename, File::kWriteTruncate); 1720 File* file = File::Open(NULL, snapshot_deps_filename, File::kWriteTruncate);
1699 if (file == NULL) { 1721 if (file == NULL) {
1700 ErrorExit(kErrorExitCode, 1722 ErrorExit(kErrorExitCode,
1701 "Error: Unable to open snapshot depfile: %s\n\n", 1723 "Error: Unable to open snapshot depfile: %s\n\n",
1702 snapshot_deps_filename); 1724 snapshot_deps_filename);
1703 } 1725 }
1704 bool success = true; 1726 bool success = true;
1705 success &= file->Print("%s: ", snapshot_filename); 1727 success &= file->Print("%s: ", snapshot_filename);
1706 for (intptr_t i = 0; i < dependencies->length(); i++) { 1728 for (intptr_t i = 0; i < dependencies->length(); i++) {
1707 char* dep = dependencies->At(i); 1729 char* dep = dependencies->At(i);
1708 success &= file->Print("%s ", dep); 1730 success &= file->Print("%s ", dep);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 Platform::Exit(Process::GlobalExitCode()); 1944 Platform::Exit(Process::GlobalExitCode());
1923 } 1945 }
1924 1946
1925 } // namespace bin 1947 } // namespace bin
1926 } // namespace dart 1948 } // namespace dart
1927 1949
1928 int main(int argc, char** argv) { 1950 int main(int argc, char** argv) {
1929 dart::bin::main(argc, argv); 1951 dart::bin::main(argc, argv);
1930 UNREACHABLE(); 1952 UNREACHABLE();
1931 } 1953 }
OLDNEW
« no previous file with comments | « runtime/bin/io_sources.gni ('k') | runtime/bin/namespace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698