[ddc] Break import cycle in shared_command.dart
Reduces the number of libraries that must be migrated to null safety
atomically.
Change-Id: I498f2956471be0435558c1b1a4badcba619f15de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247521
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
diff --git a/pkg/dev_compiler/lib/ddc.dart b/pkg/dev_compiler/lib/ddc.dart
index 5911cd9..feaa482 100755
--- a/pkg/dev_compiler/lib/ddc.dart
+++ b/pkg/dev_compiler/lib/ddc.dart
@@ -14,6 +14,7 @@
import 'package:bazel_worker/bazel_worker.dart';
import 'src/compiler/shared_command.dart';
+import 'src/kernel/command.dart';
import 'src/kernel/expression_compiler_worker.dart';
/// The internal entry point for the Dart Dev Compiler.
@@ -66,8 +67,8 @@
}
lastResult = await runZoned(
- () =>
- compile(args, previousResult: context, inputDigests: inputDigests),
+ () => compile(args,
+ compilerState: context?.kernelState, inputDigests: inputDigests),
zoneSpecification:
ZoneSpecification(print: (self, parent, zone, message) {
output.writeln(message.toString());
@@ -95,7 +96,7 @@
String outcome;
try {
- result = await compile(args, previousResult: result);
+ result = await compile(args, compilerState: result?.kernelState);
outcome = result.success ? 'PASS' : (result.crashed ? 'CRASH' : 'FAIL');
} catch (e, s) {
outcome = 'CRASH';
diff --git a/pkg/dev_compiler/lib/src/compiler/shared_command.dart b/pkg/dev_compiler/lib/src/compiler/shared_command.dart
index e97cd33..97e214a 100644
--- a/pkg/dev_compiler/lib/src/compiler/shared_command.dart
+++ b/pkg/dev_compiler/lib/src/compiler/shared_command.dart
@@ -4,7 +4,6 @@
// @dart = 2.9
-import 'dart:async';
import 'dart:io';
import 'package:args/args.dart';
@@ -12,7 +11,6 @@
show InitializedCompilerState, parseExperimentalArguments;
import 'package:path/path.dart' as p;
-import '../kernel/command.dart' as kernel_compiler;
import 'module_builder.dart';
// TODO(nshahan) Merge all of this file the locations where they are used in
@@ -32,7 +30,7 @@
final bool sourceMap;
/// Whether to emit the source mapping file in the program text, so the
- /// runtime can enable synchronous stack trace deobsfuscation.
+ /// runtime can enable synchronous stack trace deobfuscation.
final bool inlineSourceMap;
/// Whether to emit the full compiled kernel.
@@ -67,7 +65,7 @@
/// Whether to emit the debug symbols
///
/// Debugger uses this information about to construct mapping between
- /// dart and js objecys that otherwise requires expensive communication with
+ /// dart and js objects that otherwise requires expensive communication with
/// the browser.
final bool emitDebugSymbols;
@@ -436,28 +434,6 @@
return map;
}
-/// Invoke the compiler with [args], optionally with the kernel backend if
-/// [isKernel] is set.
-///
-/// Returns a [CompilerResult], with a success flag indicating whether the
-/// program compiled without any fatal errors.
-///
-/// The result may also contain a [previousResult], which can be passed back in
-/// for batch/worker executions to attempt to existing state.
-Future<CompilerResult> compile(ParsedArguments args,
- {CompilerResult previousResult, Map<Uri, List<int>> inputDigests}) {
- if (previousResult != null && !args.isBatchOrWorker) {
- throw ArgumentError(
- 'previousResult requires --batch or --bazel_worker mode/');
- }
-
- return kernel_compiler.compile(args.rest,
- compilerState: previousResult?.kernelState,
- isWorker: args.isWorker,
- useIncrementalCompiler: args.useIncrementalCompiler,
- inputDigests: inputDigests);
-}
-
/// The result of a single `dartdevc` compilation.
///
/// Typically used for exiting the process with [exitCode] or checking the
@@ -498,7 +474,7 @@
/// [isBatch]/[isWorker] mode are preprocessed because they can combine
/// argument lists from the initial invocation and from batch/worker jobs.
class ParsedArguments {
- /// The user's arguments to the compiler for this compialtion.
+ /// The user's arguments to the compiler for this compilation.
final List<String> rest;
/// Whether to run in `--batch` mode, e.g the Dart SDK and Language tests.
diff --git a/pkg/dev_compiler/lib/src/kernel/command.dart b/pkg/dev_compiler/lib/src/kernel/command.dart
index bc13226..7e981bd 100644
--- a/pkg/dev_compiler/lib/src/kernel/command.dart
+++ b/pkg/dev_compiler/lib/src/kernel/command.dart
@@ -40,17 +40,23 @@
/// Invoke the compiler with [args].
///
-/// Returns `true` if the program compiled without any fatal errors.
-Future<CompilerResult> compile(List<String> args,
+/// Returns a [CompilerResult], with a success flag indicating whether the
+/// program compiled without any fatal errors.
+///
+/// The result may also contain a [previousResult], which can be passed back in
+/// for batch/worker executions to attempt to existing state.
+Future<CompilerResult> compile(ParsedArguments args,
{fe.InitializedCompilerState compilerState,
- bool isWorker = false,
- bool useIncrementalCompiler = false,
- Map<Uri, List<int>> inputDigests}) async {
+ Map<Uri, List<int>> inputDigests}) {
+ if (compilerState != null && !args.isBatchOrWorker) {
+ throw ArgumentError(
+ 'previousResult requires --batch or --bazel_worker mode/');
+ }
try {
- return await _compile(args,
+ return _compile(args.rest,
compilerState: compilerState,
- isWorker: isWorker,
- useIncrementalCompiler: useIncrementalCompiler,
+ isWorker: args.isWorker,
+ useIncrementalCompiler: args.useIncrementalCompiler,
inputDigests: inputDigests);
} catch (error, stackTrace) {
print('''
@@ -60,13 +66,13 @@
Please include the information below in your report, along with
any other information that may help us track it down. Thanks!
-------------------- %< --------------------
- $_binaryName arguments: ${args.join(' ')}
+ $_binaryName arguments: ${args.rest.join(' ')}
dart --version: ${Platform.version}
$error
$stackTrace
''');
- return CompilerResult(70);
+ return Future.value(CompilerResult(70));
}
}
diff --git a/pkg/dev_compiler/test/sourcemap/README.md b/pkg/dev_compiler/test/sourcemap/README.md
index 65c5ef3..4c3fa68 100644
--- a/pkg/dev_compiler/test/sourcemap/README.md
+++ b/pkg/dev_compiler/test/sourcemap/README.md
@@ -3,11 +3,9 @@
This folder contains two types of tests for validating sourcemaps:
the debugging behavior and the stacktrace behavior.
-For both there are 2 suits: One for (legacy) DDC and one for DDC with kernel (DDK).
-
-Running the tests likely requires the compilation of the correct targets. DDK currently also
+Running the tests requires the compilation of the correct targets. DDC currently also
requires `ddc_sdk.dill` inside
-`{sdkroot}/{out,xcodebuild}/ReleaseX64/ddc_sdk.dill`.
+`{sdkroot}/{out,xcodebuild}/{ReleaseX64,ReleaseARM64}/ddc_sdk.dill`.
Except for that, running them should simply be a matter of executing the `*_suite.dart` files.
@@ -22,19 +20,19 @@
One can filter which tests are run by running (from the sourcemap folder):
```
-dart sourcemaps_ddc_suite.dart -- sourcemaps_ddc//printing_class_fields
+dart sourcemaps_ddk_suite.dart -- sourcemaps_ddk/printing_class_fields
```
One can additionally get debug output for failing tests (i.e. tests with different outcome than
expected), e.g.:
```
-dart sourcemaps_ddc_suite.dart -Ddebug=true -- sourcemaps_ddc//printing_class_fields
+dart sourcemaps_ddk_suite.dart -Ddebug=true -- sourcemaps_ddk/printing_class_fields
```
The latter is also useful in combination with `/*fail*/` when adding new tests to see all the places
where the debugger stopped (both in JS positions and translated to dart positions).
-For instance `-Ddebug=true -- sourcemaps_ddk//next_through_catch_test` with a `/*fail*/`
+For instance `-Ddebug=true -- sourcemaps_ddk/next_through_catch_test` with a `/*fail*/`
currently gives output like the following:
```
diff --git a/pkg/dev_compiler/test/sourcemap/common.dart b/pkg/dev_compiler/test/sourcemap/common.dart
index 19972c4..a443eec 100644
--- a/pkg/dev_compiler/test/sourcemap/common.dart
+++ b/pkg/dev_compiler/test/sourcemap/common.dart
@@ -100,7 +100,11 @@
File findInOutDir(String relative) {
var outerDir = sdkRoot.path;
- for (var outDir in const ['out/ReleaseX64', 'xcodebuild/ReleaseX64']) {
+ for (var outDir in const [
+ 'out/ReleaseX64',
+ 'xcodebuild/ReleaseX64',
+ 'xcodebuild/ReleaseARM64'
+ ]) {
var tryPath = p.join(outerDir, outDir, relative);
var file = File(tryPath);
if (file.existsSync()) return file;
diff --git a/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart b/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart
index e75d3d0..a20cf67 100644
--- a/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart
+++ b/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart
@@ -6,6 +6,7 @@
import 'dart:io';
+import 'package:dev_compiler/src/compiler/shared_command.dart';
import 'package:dev_compiler/src/kernel/command.dart';
import 'package:front_end/src/api_unstable/ddc.dart' as fe;
import 'package:sourcemap_testing/src/stepping_helper.dart';
@@ -62,6 +63,7 @@
var packageConfigPath =
sdkRoot.uri.resolve('.dart_tool/package_config.json').toFilePath();
var args = <String>[
+ '--batch',
'--packages=$packageConfigPath',
'--modules=es6',
'--dart-sdk-summary=${ddcSdkSummary.path}',
@@ -72,7 +74,8 @@
var succeeded = false;
try {
- var result = await compile(args, compilerState: context.compilerState);
+ var result = await compile(ParsedArguments.from(args),
+ compilerState: context.compilerState);
context.compilerState =
result.compilerState as fe.InitializedCompilerState;
succeeded = result.success;
@@ -86,7 +89,7 @@
var ddc = getDdcDir().uri.resolve('bin/dartdevc.dart');
throw 'Error from ddc when executing with something like '
- '$dartExecutable ${ddc.toFilePath()} --kernel '
+ '$dartExecutable ${ddc.toFilePath()} '
"${args.reduce((value, element) => '$value "$element"')}";
}