From 085deb8bc4f733a6e72f3d1b84a31c61ba4671cb Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Mon, 7 Oct 2024 22:54:09 +0000 Subject: [PATCH] [ddc] Create new result.dart library This is a step towards organizing the code from shared_command.dart and eventually deleting it. - Move `CompilerResult` from shared_command.dart. Change-Id: Ibe4b8bbd5c6deb2558392255f3818773fa4ea80e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388049 Reviewed-by: Sigmund Cherem Commit-Queue: Nicholas Shahan Reviewed-by: Nate Biggs --- pkg/dev_compiler/lib/ddc.dart | 1 + pkg/dev_compiler/lib/src/command/result.dart | 37 +++++++++++++++++++ .../lib/src/compiler/shared_command.dart | 33 ----------------- pkg/dev_compiler/lib/src/kernel/command.dart | 1 + 4 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 pkg/dev_compiler/lib/src/command/result.dart diff --git a/pkg/dev_compiler/lib/ddc.dart b/pkg/dev_compiler/lib/ddc.dart index 87e3b186152..e688b31c933 100755 --- a/pkg/dev_compiler/lib/ddc.dart +++ b/pkg/dev_compiler/lib/ddc.dart @@ -16,6 +16,7 @@ import 'package:bazel_worker/bazel_worker.dart'; import 'package:kernel/ast.dart' show clearDummyTreeNodesParentPointer; import 'src/command/arguments.dart'; +import 'src/command/result.dart'; import 'src/compiler/shared_command.dart'; import 'src/kernel/command.dart'; import 'src/kernel/expression_compiler_worker.dart'; diff --git a/pkg/dev_compiler/lib/src/command/result.dart b/pkg/dev_compiler/lib/src/command/result.dart new file mode 100644 index 00000000000..8a3e969b6b3 --- /dev/null +++ b/pkg/dev_compiler/lib/src/command/result.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2024, 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 'package:front_end/src/api_unstable/ddc.dart' + show InitializedCompilerState; + +/// The result of a single `dartdevc` compilation. +/// +/// Typically used for exiting the process with [exitCode] or checking the +/// [success] of the compilation. +/// +/// For batch/worker compilations, the [compilerState] provides an opportunity +/// to reuse state from the previous run, if the options/input summaries are +/// equivalent. Otherwise it will be discarded. +class CompilerResult { + /// Optionally provides the front_end state from the previous compilation, + /// which can be passed to [compile] to potentially speed up the next + /// compilation. + final InitializedCompilerState? kernelState; + + /// The process exit code of the compiler. + final int exitCode; + + CompilerResult(this.exitCode, {this.kernelState}); + + /// Gets the kernel compiler state, if any. + Object? get compilerState => kernelState; + + /// Whether the program compiled without any fatal errors (equivalent to + /// [exitCode] == 0). + bool get success => exitCode == 0; + + /// Whether the compiler crashed (i.e. threw an unhandled exception, + /// typically indicating an internal error in DDC itself or its front end). + bool get crashed => exitCode == 70; +} diff --git a/pkg/dev_compiler/lib/src/compiler/shared_command.dart b/pkg/dev_compiler/lib/src/compiler/shared_command.dart index de808240e3a..cc6595d555b 100644 --- a/pkg/dev_compiler/lib/src/compiler/shared_command.dart +++ b/pkg/dev_compiler/lib/src/compiler/shared_command.dart @@ -6,8 +6,6 @@ import 'dart:io'; import 'package:front_end/src/api_prototype/macros.dart' as macros show isMacroLibraryUri; -import 'package:front_end/src/api_unstable/ddc.dart' - show InitializedCompilerState; import 'package:path/path.dart' as p; // TODO(nshahan) Merge all of this file the locations where they are used in @@ -121,34 +119,3 @@ Map placeSourceMap(Map sourceMap, map['file'] != null ? makeRelative(map['file'] as String) : null; return map; } - -/// The result of a single `dartdevc` compilation. -/// -/// Typically used for exiting the process with [exitCode] or checking the -/// [success] of the compilation. -/// -/// For batch/worker compilations, the [compilerState] provides an opportunity -/// to reuse state from the previous run, if the options/input summaries are -/// equivalent. Otherwise it will be discarded. -class CompilerResult { - /// Optionally provides the front_end state from the previous compilation, - /// which can be passed to [compile] to potentially speed up the next - /// compilation. - final InitializedCompilerState? kernelState; - - /// The process exit code of the compiler. - final int exitCode; - - CompilerResult(this.exitCode, {this.kernelState}); - - /// Gets the kernel compiler state, if any. - Object? get compilerState => kernelState; - - /// Whether the program compiled without any fatal errors (equivalent to - /// [exitCode] == 0). - bool get success => exitCode == 0; - - /// Whether the compiler crashed (i.e. threw an unhandled exception, - /// typically indicating an internal error in DDC itself or its front end). - bool get crashed => exitCode == 70; -} diff --git a/pkg/dev_compiler/lib/src/kernel/command.dart b/pkg/dev_compiler/lib/src/kernel/command.dart index 39bcc2562c3..8b3b7bbd7cb 100644 --- a/pkg/dev_compiler/lib/src/kernel/command.dart +++ b/pkg/dev_compiler/lib/src/kernel/command.dart @@ -21,6 +21,7 @@ import 'package:source_maps/source_maps.dart' show SourceMapBuilder; import '../command/arguments.dart'; import '../command/options.dart'; +import '../command/result.dart'; import '../compiler/js_names.dart' as js_ast; import '../compiler/module_builder.dart'; import '../compiler/shared_command.dart';