Skip to content

Commit

Permalink
Reland: [dart:cli] Adds waitFor(Future)
Browse files Browse the repository at this point in the history
This is a reland of https://dart-review.googlesource.com/#/c/sdk/+/28920/
with the following changes:
- It creates a new library dart:cli
- waitFor(Future) goes in dart:cli instead of dart:io
- Removes a flaky test, and adds a missing precompiler entrypoint
- Adds waitFor(Future)
- Improves doc comments

fixes dart-lang#31102

Change-Id: I04d2c46fd0afac049dd4fd1353905dc20da18f90
Reviewed-on: https://dart-review.googlesource.com/29449
Commit-Queue: Zach Anderson <[email protected]>
Reviewed-by: Natalie Weizenbaum <[email protected]>
Reviewed-by: Keerti Parthasarathy <[email protected]>
Reviewed-by: Sigmund Cherem <[email protected]>
Reviewed-by: Siva Annamalai <[email protected]>
  • Loading branch information
zanderso authored and [email protected] committed Jan 18, 2018
1 parent 0d1c495 commit 9c40a7e
Show file tree
Hide file tree
Showing 62 changed files with 946 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
some breaking API changes. See https://goo.gl/y9mW2x for more information.
* Renamed `Zone.ROOT` to `Zone.root`.

* `dart:cli`
* Added function `waitFor` that suspends a stack to wait for a `Future` to
complete.

* `dart:core`
* The `Uri` class now correctly handles paths while running on Node.js on
Windows.
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_cli/tool/perf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Set<Source> scanReachableFiles(Uri entryUri) {

var libs = [
"dart:async",
"dart:cli",
"dart:collection",
"dart:convert",
"dart:core",
Expand All @@ -158,7 +159,7 @@ Set<Source> scanReachableFiles(Uri entryUri) {
"dart:math",
"dart:mirrors",
"dart:typed_data",
"dart:io"
"dart:io",
];

for (var lib in libs) {
Expand Down
1 change: 1 addition & 0 deletions pkg/compiler/lib/src/library_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ abstract class LibraryLoaderTask implements LibraryProvider, CompilerTask {
/// The locations of js patch-files relative to the sdk-descriptors.
static const _patchLocations = const <String, String>{
"async": "_internal/js_runtime/lib/async_patch.dart",
"cli": "_internal/js_runtime/lib/cli_patch.dart",
"collection": "_internal/js_runtime/lib/collection_patch.dart",
"convert": "_internal/js_runtime/lib/convert_patch.dart",
"core": "_internal/js_runtime/lib/core_patch.dart",
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/tool/input_sdk/lib/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@
}
}
}
}
}
3 changes: 3 additions & 0 deletions pkg/dev_compiler/tool/input_sdk/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ const Map<String, LibraryInfo> libraries = const {
implementation: true,
documented: false,
platforms: DART2JS_PLATFORM),
"cli": const LibraryInfo("cli/cli.dart",
categories: "Server",
dart2jsPatchPath: "_internal/js_runtime/lib/cli_patch.dart"),
"svg": const LibraryInfo("svg/dart2js/svg_dart2js.dart",
categories: "Client",
maturity: Maturity.WEB_STABLE,
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/tool/input_sdk/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@
}
}
}
}
}
10 changes: 10 additions & 0 deletions pkg/dev_compiler/tool/input_sdk/patch/cli_patch.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:_js_helper' show patch;

@patch
void _waitForEvent(int timeoutMillis) {
throw new UnsupportedError("waitForEvent");
}
1 change: 1 addition & 0 deletions pkg/front_end/test/src/incremental/mock_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ TargetLibrariesSpecification createSdkFiles(MemoryFileSystem fileSystem) {
addSdkLibrary('convert', 'library dart.convert;');
addSdkLibrary('developer', 'library dart.developer;');
addSdkLibrary('io', 'library dart.io;');
addSdkLibrary('cli', 'library dart.cli;');
addSdkLibrary('isolate', 'library dart.isolate;');
addSdkLibrary('math', '''
library dart.math;
Expand Down
1 change: 1 addition & 0 deletions pkg/kernel/lib/target/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class VmTarget extends Target {
'dart:_builtin',
'dart:nativewrappers',
'dart:io',
'dart:cli',
];

@override
Expand Down
33 changes: 31 additions & 2 deletions runtime/bin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import("../../build/compiled_action.gni")
import("../../sdk/lib/_http/http_sources.gni")
import("../../sdk/lib/io/io_sources.gni")
import("../../sdk/lib/cli/cli_sources.gni")
import("../runtime_args.gni")
import("../vm/compiler/compiler_sources.gni")
import("../vm/vm_sources.gni")
import("builtin_impl_sources.gni")
import("builtin_sources.gni")
import("io_impl_sources.gni")
import("io_sources.gni")
import("cli_impl_sources.gni")
import("cli_sources.gni")
import("vmservice/vmservice_sources.gni")

# Generate a resources.cc file for the service isolate without Observatory.
Expand Down Expand Up @@ -109,6 +112,22 @@ gen_library_src_path("generate_http_cc_file") {
output = "$target_gen_dir/http_gen.cc"
}

rebased_cli_sdk_sources = rebase_path(cli_sdk_sources, ".", "../../sdk/lib/cli")

gen_library_src_path("generate_cli_cc_file") {
name = "cli"
kind = "source"
sources = [ "../../sdk/lib/cli/cli.dart" ] + rebased_cli_sdk_sources
output = "$target_gen_dir/cli_gen.cc"
}

gen_library_src_path("generate_cli_patch_cc_file") {
name = "cli"
kind = "patch"
sources = cli_runtime_sources
output = "$target_gen_dir/cli_patch_gen.cc"
}

gen_library_src_path("generate_html_cc_file") {
name = "html"
kind = "source"
Expand Down Expand Up @@ -235,6 +254,8 @@ template("build_libdart_builtin") {
public_configs = [ ":libdart_builtin_config" ]
deps = [
":generate_builtin_cc_file",
":generate_cli_cc_file",
":generate_cli_patch_cc_file",
":generate_html_cc_file",
":generate_html_common_cc_file",
":generate_http_cc_file",
Expand Down Expand Up @@ -297,11 +318,15 @@ template("build_gen_snapshot") {
":generate_http_cc_file",
":generate_io_cc_file",
":generate_io_patch_cc_file",
":generate_cli_cc_file",
":generate_cli_patch_cc_file",
] + extra_deps

sources = [
# Include generated source files.
"$target_gen_dir/builtin_gen.cc",
"$target_gen_dir/cli_gen.cc",
"$target_gen_dir/cli_patch_gen.cc",
"$target_gen_dir/http_gen.cc",
"$target_gen_dir/io_gen.cc",
"$target_gen_dir/io_patch_gen.cc",
Expand Down Expand Up @@ -417,7 +442,7 @@ template("build_gen_snapshot_dart_io") {

defines = [ "DART_IO_SECURE_SOCKET_DISABLED" ]

sources = io_impl_sources + builtin_impl_sources
sources = io_impl_sources + builtin_impl_sources + cli_impl_sources
sources += [
"io_natives.cc",
"io_natives.h",
Expand Down Expand Up @@ -494,7 +519,7 @@ template("dart_io") {
libs = [ "launchpad" ]
}

sources = io_impl_sources + builtin_impl_sources
sources = io_impl_sources + builtin_impl_sources + cli_impl_sources
sources += [
"builtin_natives.cc",
"io_natives.cc",
Expand Down Expand Up @@ -840,6 +865,8 @@ dart_executable("dart_bootstrap") {
":generate_js_util_cc_file",
":generate_metadata_cc_file",
":generate_svg_cc_file",
":generate_cli_cc_file",
":generate_cli_patch_cc_file",
":generate_web_audio_cc_file",
":generate_web_gl_cc_file",
":generate_web_sql_cc_file",
Expand Down Expand Up @@ -871,6 +898,8 @@ dart_executable("dart_bootstrap") {
"$target_gen_dir/metadata_gen.cc",
"$target_gen_dir/resources_gen.cc",
"$target_gen_dir/svg_gen.cc",
"$target_gen_dir/cli_gen.cc",
"$target_gen_dir/cli_patch_gen.cc",
"$target_gen_dir/web_audio_gen.cc",
"$target_gen_dir/web_gl_gen.cc",
"$target_gen_dir/web_sql_gen.cc",
Expand Down
2 changes: 2 additions & 0 deletions runtime/bin/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
{DartUtils::kIOLibURL, io_source_paths_, DartUtils::kIOLibPatchURL,
io_patch_paths_, true},
{DartUtils::kHttpLibURL, _http_source_paths_, NULL, NULL, false},
{DartUtils::kCLILibURL, cli_source_paths_, DartUtils::kCLILibPatchURL,
cli_patch_paths_, true},

#if defined(DART_NO_SNAPSHOT)
// Only include these libraries in the dart_bootstrap case for now.
Expand Down
3 changes: 3 additions & 0 deletions runtime/bin/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Builtin {
kBuiltinLibrary = 0,
kIOLibrary,
kHttpLibrary,
kCLILibrary,
};

// Get source corresponding to built in library specified in 'id'.
Expand Down Expand Up @@ -79,6 +80,8 @@ class Builtin {
static const char* web_gl_source_paths_[];
static const char* metadata_source_paths_[];
static const char* web_sql_source_paths_[];
static const char* cli_source_paths_[];
static const char* cli_patch_paths_[];
static const char* svg_source_paths_[];
static const char* web_audio_source_paths_[];

Expand Down
1 change: 1 addition & 0 deletions runtime/bin/builtin_nolib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
{DartUtils::kBuiltinLibURL, NULL, NULL, NULL, true},
{DartUtils::kIOLibURL, NULL, NULL, NULL, true},
{DartUtils::kHttpLibURL, NULL, NULL, NULL, false},
{DartUtils::kCLILibURL, NULL, NULL, NULL, true},
// End marker.
{NULL, NULL, NULL, NULL, false}};

Expand Down
27 changes: 27 additions & 0 deletions runtime/bin/cli.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "bin/builtin.h"
#include "bin/dartutils.h"

#include "include/dart_api.h"

namespace dart {
namespace bin {

void FUNCTION_NAME(CLI_WaitForEvent)(Dart_NativeArguments args) {
int64_t timeout_millis;
Dart_Handle result = Dart_GetNativeIntegerArgument(args, 0, &timeout_millis);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
result = Dart_WaitForEvent(timeout_millis);
if (Dart_IsError(result)) {
Dart_PropagateError(result);
}
Dart_SetReturnValue(args, result);
}

} // namespace bin
} // namespace dart
6 changes: 6 additions & 0 deletions runtime/bin/cli_impl_sources.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# This file contains some C++ sources for the dart:cli library.
cli_impl_sources = [ "cli.cc" ]
8 changes: 8 additions & 0 deletions runtime/bin/cli_patch.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import "dart:_internal" show patch;

@patch
void _waitForEvent(int timeoutMillis) native "CLI_WaitForEvent";
6 changes: 6 additions & 0 deletions runtime/bin/cli_sources.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# This file contains all sources for the dart:cli library.
cli_runtime_sources = [ "cli_patch.dart" ]
18 changes: 18 additions & 0 deletions runtime/bin/dartutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const char* const DartUtils::kIsolateLibURL = "dart:isolate";
const char* const DartUtils::kHttpLibURL = "dart:_http";
const char* const DartUtils::kIOLibURL = "dart:io";
const char* const DartUtils::kIOLibPatchURL = "dart:io-patch";
const char* const DartUtils::kCLILibURL = "dart:cli";
const char* const DartUtils::kCLILibPatchURL = "dart:cli-patch";
const char* const DartUtils::kUriLibURL = "dart:uri";
const char* const DartUtils::kHttpScheme = "http:";
const char* const DartUtils::kVMServiceLibURL = "dart:vmservice";
Expand Down Expand Up @@ -169,6 +171,10 @@ bool DartUtils::IsDartIOLibURL(const char* url_name) {
return (strcmp(url_name, kIOLibURL) == 0);
}

bool DartUtils::IsDartCLILibURL(const char* url_name) {
return (strcmp(url_name, kCLILibURL) == 0);
}

bool DartUtils::IsDartHttpLibURL(const char* url_name) {
return (strcmp(url_name, kHttpLibURL) == 0);
}
Expand Down Expand Up @@ -477,6 +483,14 @@ Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) {
return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL);
}

Dart_Handle DartUtils::PrepareCLILibrary(Dart_Handle cli_lib) {
Dart_Handle wait_for_event_handle =
Dart_Invoke(cli_lib, NewString("_getWaitForEvent"), 0, NULL);
RETURN_IF_ERROR(wait_for_event_handle);
return Dart_SetField(cli_lib, NewString("_waitForEventClosure"),
wait_for_event_handle);
}

Dart_Handle DartUtils::SetupServiceLoadPort() {
// Wait for the service isolate to initialize the load port.
Dart_Port load_port = Dart_ServiceWaitForLoadPort();
Expand Down Expand Up @@ -539,6 +553,9 @@ Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate,
Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
RETURN_IF_ERROR(io_lib);
Builtin::SetNativeResolver(Builtin::kIOLibrary);
Dart_Handle cli_lib = Builtin::LoadAndCheckLibrary(Builtin::kCLILibrary);
RETURN_IF_ERROR(cli_lib);
Builtin::SetNativeResolver(Builtin::kCLILibrary);

// Setup the builtin library in a persistent handle attached the isolate
// specific data as we seem to lookup and use builtin lib a lot.
Expand All @@ -560,6 +577,7 @@ Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate,
RETURN_IF_ERROR(PrepareCoreLibrary(core_lib, io_lib, is_service_isolate));
RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib));
RETURN_IF_ERROR(PrepareIOLibrary(io_lib));
RETURN_IF_ERROR(PrepareCLILibrary(cli_lib));
return result;
}

Expand Down
4 changes: 4 additions & 0 deletions runtime/bin/dartutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class DartUtils {
static bool IsDartSchemeURL(const char* url_name);
static bool IsDartExtensionSchemeURL(const char* url_name);
static bool IsDartIOLibURL(const char* url_name);
static bool IsDartCLILibURL(const char* url_name);
static bool IsDartHttpLibURL(const char* url_name);
static bool IsDartBuiltinLibURL(const char* url_name);
static bool IsHttpSchemeURL(const char* url_name);
Expand Down Expand Up @@ -235,6 +236,8 @@ class DartUtils {
static const char* const kHttpLibURL;
static const char* const kIOLibURL;
static const char* const kIOLibPatchURL;
static const char* const kCLILibURL;
static const char* const kCLILibPatchURL;
static const char* const kUriLibURL;
static const char* const kHttpScheme;
static const char* const kVMServiceLibURL;
Expand All @@ -254,6 +257,7 @@ class DartUtils {
Dart_Handle isolate_lib);
static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib);
static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib);
static Dart_Handle PrepareCLILibrary(Dart_Handle cli_lib);

DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils);
Expand Down
7 changes: 7 additions & 0 deletions runtime/bin/gen_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ static Builtin::BuiltinLibraryId BuiltinId(const char* url) {
if (DartUtils::IsDartHttpLibURL(url)) {
return Builtin::kHttpLibrary;
}
if (DartUtils::IsDartCLILibURL(url)) {
return Builtin::kCLILibrary;
}
return Builtin::kInvalidLibrary;
}

Expand Down Expand Up @@ -1302,6 +1305,9 @@ static void SetupForGenericSnapshotCreation() {

Dart_Handle library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary);
CHECK_RESULT(library);
Dart_Handle standalone_library =
LoadGenericSnapshotCreationScript(Builtin::kCLILibrary);
CHECK_RESULT(standalone_library);
Dart_Handle result = Dart_FinalizeLoading(false);
if (Dart_IsError(result)) {
const char* err_msg = Dart_GetError(library);
Expand Down Expand Up @@ -1344,6 +1350,7 @@ static Dart_Isolate CreateServiceIsolate(const char* script_uri,
// Setup the native resolver.
Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
Builtin::LoadAndCheckLibrary(Builtin::kCLILibrary);

ASSERT(Dart_IsServiceIsolate(isolate));
// Load embedder specific bits and return. Will not start http server.
Expand Down
1 change: 1 addition & 0 deletions runtime/bin/io_natives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace bin {
// Some classes, like File and Directory, list their implementations in
// builtin_natives.cc instead.
#define IO_NATIVE_LIST(V) \
V(CLI_WaitForEvent, 1) \
V(Crypto_GetRandomBytes, 1) \
V(Directory_Create, 2) \
V(Directory_CreateTemp, 2) \
Expand Down
Loading

0 comments on commit 9c40a7e

Please sign in to comment.