Skip to content

Commit 9c40a7e

Browse files
zandersocommit-bot@chromium.org
authored andcommitted
Reland: [dart:cli] Adds waitFor(Future)
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 #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]>
1 parent 0d1c495 commit 9c40a7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+946
-13
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
some breaking API changes. See https://goo.gl/y9mW2x for more information.
1919
* Renamed `Zone.ROOT` to `Zone.root`.
2020

21+
* `dart:cli`
22+
* Added function `waitFor` that suspends a stack to wait for a `Future` to
23+
complete.
24+
2125
* `dart:core`
2226
* The `Uri` class now correctly handles paths while running on Node.js on
2327
Windows.

pkg/analyzer_cli/tool/perf.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Set<Source> scanReachableFiles(Uri entryUri) {
149149

150150
var libs = [
151151
"dart:async",
152+
"dart:cli",
152153
"dart:collection",
153154
"dart:convert",
154155
"dart:core",
@@ -158,7 +159,7 @@ Set<Source> scanReachableFiles(Uri entryUri) {
158159
"dart:math",
159160
"dart:mirrors",
160161
"dart:typed_data",
161-
"dart:io"
162+
"dart:io",
162163
];
163164

164165
for (var lib in libs) {

pkg/compiler/lib/src/library_loader.dart

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ abstract class LibraryLoaderTask implements LibraryProvider, CompilerTask {
192192
/// The locations of js patch-files relative to the sdk-descriptors.
193193
static const _patchLocations = const <String, String>{
194194
"async": "_internal/js_runtime/lib/async_patch.dart",
195+
"cli": "_internal/js_runtime/lib/cli_patch.dart",
195196
"collection": "_internal/js_runtime/lib/collection_patch.dart",
196197
"convert": "_internal/js_runtime/lib/convert_patch.dart",
197198
"core": "_internal/js_runtime/lib/core_patch.dart",

pkg/dev_compiler/tool/input_sdk/lib/libraries.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@
110110
}
111111
}
112112
}
113-
}
113+
}

pkg/dev_compiler/tool/input_sdk/libraries.dart

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ const Map<String, LibraryInfo> libraries = const {
115115
implementation: true,
116116
documented: false,
117117
platforms: DART2JS_PLATFORM),
118+
"cli": const LibraryInfo("cli/cli.dart",
119+
categories: "Server",
120+
dart2jsPatchPath: "_internal/js_runtime/lib/cli_patch.dart"),
118121
"svg": const LibraryInfo("svg/dart2js/svg_dart2js.dart",
119122
categories: "Client",
120123
maturity: Maturity.WEB_STABLE,

pkg/dev_compiler/tool/input_sdk/libraries.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@
9999
}
100100
}
101101
}
102-
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'dart:_js_helper' show patch;
6+
7+
@patch
8+
void _waitForEvent(int timeoutMillis) {
9+
throw new UnsupportedError("waitForEvent");
10+
}

pkg/front_end/test/src/incremental/mock_sdk.dart

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ TargetLibrariesSpecification createSdkFiles(MemoryFileSystem fileSystem) {
302302
addSdkLibrary('convert', 'library dart.convert;');
303303
addSdkLibrary('developer', 'library dart.developer;');
304304
addSdkLibrary('io', 'library dart.io;');
305+
addSdkLibrary('cli', 'library dart.cli;');
305306
addSdkLibrary('isolate', 'library dart.isolate;');
306307
addSdkLibrary('math', '''
307308
library dart.math;

pkg/kernel/lib/target/vm.dart

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class VmTarget extends Target {
5252
'dart:_builtin',
5353
'dart:nativewrappers',
5454
'dart:io',
55+
'dart:cli',
5556
];
5657

5758
@override

runtime/bin/BUILD.gn

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import("../../build/compiled_action.gni")
66
import("../../sdk/lib/_http/http_sources.gni")
77
import("../../sdk/lib/io/io_sources.gni")
8+
import("../../sdk/lib/cli/cli_sources.gni")
89
import("../runtime_args.gni")
910
import("../vm/compiler/compiler_sources.gni")
1011
import("../vm/vm_sources.gni")
1112
import("builtin_impl_sources.gni")
1213
import("builtin_sources.gni")
1314
import("io_impl_sources.gni")
1415
import("io_sources.gni")
16+
import("cli_impl_sources.gni")
17+
import("cli_sources.gni")
1518
import("vmservice/vmservice_sources.gni")
1619

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

115+
rebased_cli_sdk_sources = rebase_path(cli_sdk_sources, ".", "../../sdk/lib/cli")
116+
117+
gen_library_src_path("generate_cli_cc_file") {
118+
name = "cli"
119+
kind = "source"
120+
sources = [ "../../sdk/lib/cli/cli.dart" ] + rebased_cli_sdk_sources
121+
output = "$target_gen_dir/cli_gen.cc"
122+
}
123+
124+
gen_library_src_path("generate_cli_patch_cc_file") {
125+
name = "cli"
126+
kind = "patch"
127+
sources = cli_runtime_sources
128+
output = "$target_gen_dir/cli_patch_gen.cc"
129+
}
130+
112131
gen_library_src_path("generate_html_cc_file") {
113132
name = "html"
114133
kind = "source"
@@ -235,6 +254,8 @@ template("build_libdart_builtin") {
235254
public_configs = [ ":libdart_builtin_config" ]
236255
deps = [
237256
":generate_builtin_cc_file",
257+
":generate_cli_cc_file",
258+
":generate_cli_patch_cc_file",
238259
":generate_html_cc_file",
239260
":generate_html_common_cc_file",
240261
":generate_http_cc_file",
@@ -297,11 +318,15 @@ template("build_gen_snapshot") {
297318
":generate_http_cc_file",
298319
":generate_io_cc_file",
299320
":generate_io_patch_cc_file",
321+
":generate_cli_cc_file",
322+
":generate_cli_patch_cc_file",
300323
] + extra_deps
301324

302325
sources = [
303326
# Include generated source files.
304327
"$target_gen_dir/builtin_gen.cc",
328+
"$target_gen_dir/cli_gen.cc",
329+
"$target_gen_dir/cli_patch_gen.cc",
305330
"$target_gen_dir/http_gen.cc",
306331
"$target_gen_dir/io_gen.cc",
307332
"$target_gen_dir/io_patch_gen.cc",
@@ -417,7 +442,7 @@ template("build_gen_snapshot_dart_io") {
417442

418443
defines = [ "DART_IO_SECURE_SOCKET_DISABLED" ]
419444

420-
sources = io_impl_sources + builtin_impl_sources
445+
sources = io_impl_sources + builtin_impl_sources + cli_impl_sources
421446
sources += [
422447
"io_natives.cc",
423448
"io_natives.h",
@@ -494,7 +519,7 @@ template("dart_io") {
494519
libs = [ "launchpad" ]
495520
}
496521

497-
sources = io_impl_sources + builtin_impl_sources
522+
sources = io_impl_sources + builtin_impl_sources + cli_impl_sources
498523
sources += [
499524
"builtin_natives.cc",
500525
"io_natives.cc",
@@ -840,6 +865,8 @@ dart_executable("dart_bootstrap") {
840865
":generate_js_util_cc_file",
841866
":generate_metadata_cc_file",
842867
":generate_svg_cc_file",
868+
":generate_cli_cc_file",
869+
":generate_cli_patch_cc_file",
843870
":generate_web_audio_cc_file",
844871
":generate_web_gl_cc_file",
845872
":generate_web_sql_cc_file",
@@ -871,6 +898,8 @@ dart_executable("dart_bootstrap") {
871898
"$target_gen_dir/metadata_gen.cc",
872899
"$target_gen_dir/resources_gen.cc",
873900
"$target_gen_dir/svg_gen.cc",
901+
"$target_gen_dir/cli_gen.cc",
902+
"$target_gen_dir/cli_patch_gen.cc",
874903
"$target_gen_dir/web_audio_gen.cc",
875904
"$target_gen_dir/web_gl_gen.cc",
876905
"$target_gen_dir/web_sql_gen.cc",

runtime/bin/builtin.cc

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
2323
{DartUtils::kIOLibURL, io_source_paths_, DartUtils::kIOLibPatchURL,
2424
io_patch_paths_, true},
2525
{DartUtils::kHttpLibURL, _http_source_paths_, NULL, NULL, false},
26+
{DartUtils::kCLILibURL, cli_source_paths_, DartUtils::kCLILibPatchURL,
27+
cli_patch_paths_, true},
2628

2729
#if defined(DART_NO_SNAPSHOT)
2830
// Only include these libraries in the dart_bootstrap case for now.

runtime/bin/builtin.h

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Builtin {
3030
kBuiltinLibrary = 0,
3131
kIOLibrary,
3232
kHttpLibrary,
33+
kCLILibrary,
3334
};
3435

3536
// Get source corresponding to built in library specified in 'id'.
@@ -79,6 +80,8 @@ class Builtin {
7980
static const char* web_gl_source_paths_[];
8081
static const char* metadata_source_paths_[];
8182
static const char* web_sql_source_paths_[];
83+
static const char* cli_source_paths_[];
84+
static const char* cli_patch_paths_[];
8285
static const char* svg_source_paths_[];
8386
static const char* web_audio_source_paths_[];
8487

runtime/bin/builtin_nolib.cc

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
1818
{DartUtils::kBuiltinLibURL, NULL, NULL, NULL, true},
1919
{DartUtils::kIOLibURL, NULL, NULL, NULL, true},
2020
{DartUtils::kHttpLibURL, NULL, NULL, NULL, false},
21+
{DartUtils::kCLILibURL, NULL, NULL, NULL, true},
2122
// End marker.
2223
{NULL, NULL, NULL, NULL, false}};
2324

runtime/bin/cli.cc

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
#include "bin/builtin.h"
6+
#include "bin/dartutils.h"
7+
8+
#include "include/dart_api.h"
9+
10+
namespace dart {
11+
namespace bin {
12+
13+
void FUNCTION_NAME(CLI_WaitForEvent)(Dart_NativeArguments args) {
14+
int64_t timeout_millis;
15+
Dart_Handle result = Dart_GetNativeIntegerArgument(args, 0, &timeout_millis);
16+
if (Dart_IsError(result)) {
17+
Dart_PropagateError(result);
18+
}
19+
result = Dart_WaitForEvent(timeout_millis);
20+
if (Dart_IsError(result)) {
21+
Dart_PropagateError(result);
22+
}
23+
Dart_SetReturnValue(args, result);
24+
}
25+
26+
} // namespace bin
27+
} // namespace dart

runtime/bin/cli_impl_sources.gni

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
# This file contains some C++ sources for the dart:cli library.
6+
cli_impl_sources = [ "cli.cc" ]

runtime/bin/cli_patch.dart

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "dart:_internal" show patch;
6+
7+
@patch
8+
void _waitForEvent(int timeoutMillis) native "CLI_WaitForEvent";

runtime/bin/cli_sources.gni

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
# This file contains all sources for the dart:cli library.
6+
cli_runtime_sources = [ "cli_patch.dart" ]

runtime/bin/dartutils.cc

+18
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const char* const DartUtils::kIsolateLibURL = "dart:isolate";
4646
const char* const DartUtils::kHttpLibURL = "dart:_http";
4747
const char* const DartUtils::kIOLibURL = "dart:io";
4848
const char* const DartUtils::kIOLibPatchURL = "dart:io-patch";
49+
const char* const DartUtils::kCLILibURL = "dart:cli";
50+
const char* const DartUtils::kCLILibPatchURL = "dart:cli-patch";
4951
const char* const DartUtils::kUriLibURL = "dart:uri";
5052
const char* const DartUtils::kHttpScheme = "http:";
5153
const char* const DartUtils::kVMServiceLibURL = "dart:vmservice";
@@ -169,6 +171,10 @@ bool DartUtils::IsDartIOLibURL(const char* url_name) {
169171
return (strcmp(url_name, kIOLibURL) == 0);
170172
}
171173

174+
bool DartUtils::IsDartCLILibURL(const char* url_name) {
175+
return (strcmp(url_name, kCLILibURL) == 0);
176+
}
177+
172178
bool DartUtils::IsDartHttpLibURL(const char* url_name) {
173179
return (strcmp(url_name, kHttpLibURL) == 0);
174180
}
@@ -477,6 +483,14 @@ Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) {
477483
return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL);
478484
}
479485

486+
Dart_Handle DartUtils::PrepareCLILibrary(Dart_Handle cli_lib) {
487+
Dart_Handle wait_for_event_handle =
488+
Dart_Invoke(cli_lib, NewString("_getWaitForEvent"), 0, NULL);
489+
RETURN_IF_ERROR(wait_for_event_handle);
490+
return Dart_SetField(cli_lib, NewString("_waitForEventClosure"),
491+
wait_for_event_handle);
492+
}
493+
480494
Dart_Handle DartUtils::SetupServiceLoadPort() {
481495
// Wait for the service isolate to initialize the load port.
482496
Dart_Port load_port = Dart_ServiceWaitForLoadPort();
@@ -539,6 +553,9 @@ Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate,
539553
Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
540554
RETURN_IF_ERROR(io_lib);
541555
Builtin::SetNativeResolver(Builtin::kIOLibrary);
556+
Dart_Handle cli_lib = Builtin::LoadAndCheckLibrary(Builtin::kCLILibrary);
557+
RETURN_IF_ERROR(cli_lib);
558+
Builtin::SetNativeResolver(Builtin::kCLILibrary);
542559

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

runtime/bin/dartutils.h

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class DartUtils {
113113
static bool IsDartSchemeURL(const char* url_name);
114114
static bool IsDartExtensionSchemeURL(const char* url_name);
115115
static bool IsDartIOLibURL(const char* url_name);
116+
static bool IsDartCLILibURL(const char* url_name);
116117
static bool IsDartHttpLibURL(const char* url_name);
117118
static bool IsDartBuiltinLibURL(const char* url_name);
118119
static bool IsHttpSchemeURL(const char* url_name);
@@ -235,6 +236,8 @@ class DartUtils {
235236
static const char* const kHttpLibURL;
236237
static const char* const kIOLibURL;
237238
static const char* const kIOLibPatchURL;
239+
static const char* const kCLILibURL;
240+
static const char* const kCLILibPatchURL;
238241
static const char* const kUriLibURL;
239242
static const char* const kHttpScheme;
240243
static const char* const kVMServiceLibURL;
@@ -254,6 +257,7 @@ class DartUtils {
254257
Dart_Handle isolate_lib);
255258
static Dart_Handle PrepareIOLibrary(Dart_Handle io_lib);
256259
static Dart_Handle PrepareIsolateLibrary(Dart_Handle isolate_lib);
260+
static Dart_Handle PrepareCLILibrary(Dart_Handle cli_lib);
257261

258262
DISALLOW_ALLOCATION();
259263
DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils);

runtime/bin/gen_snapshot.cc

+7
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ static Builtin::BuiltinLibraryId BuiltinId(const char* url) {
462462
if (DartUtils::IsDartHttpLibURL(url)) {
463463
return Builtin::kHttpLibrary;
464464
}
465+
if (DartUtils::IsDartCLILibURL(url)) {
466+
return Builtin::kCLILibrary;
467+
}
465468
return Builtin::kInvalidLibrary;
466469
}
467470

@@ -1302,6 +1305,9 @@ static void SetupForGenericSnapshotCreation() {
13021305

13031306
Dart_Handle library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary);
13041307
CHECK_RESULT(library);
1308+
Dart_Handle standalone_library =
1309+
LoadGenericSnapshotCreationScript(Builtin::kCLILibrary);
1310+
CHECK_RESULT(standalone_library);
13051311
Dart_Handle result = Dart_FinalizeLoading(false);
13061312
if (Dart_IsError(result)) {
13071313
const char* err_msg = Dart_GetError(library);
@@ -1344,6 +1350,7 @@ static Dart_Isolate CreateServiceIsolate(const char* script_uri,
13441350
// Setup the native resolver.
13451351
Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
13461352
Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
1353+
Builtin::LoadAndCheckLibrary(Builtin::kCLILibrary);
13471354

13481355
ASSERT(Dart_IsServiceIsolate(isolate));
13491356
// Load embedder specific bits and return. Will not start http server.

runtime/bin/io_natives.cc

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace bin {
1919
// Some classes, like File and Directory, list their implementations in
2020
// builtin_natives.cc instead.
2121
#define IO_NATIVE_LIST(V) \
22+
V(CLI_WaitForEvent, 1) \
2223
V(Crypto_GetRandomBytes, 1) \
2324
V(Directory_Create, 2) \
2425
V(Directory_CreateTemp, 2) \

0 commit comments

Comments
 (0)