mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Add unstable API for bazel summary worker and move the actual worker out of package:front-end
Bug: Change-Id: I0a64d3de46ef55e8185e723d6111fa315ad286ca Reviewed-on: https://dart-review.googlesource.com/30621 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Peter von der Ahé <ahe@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com>
This commit is contained in:
parent
fc297daf5a
commit
22298629e8
61
pkg/front_end/lib/src/api_unstable/summary_worker.dart
Normal file
61
pkg/front_end/lib/src/api_unstable/summary_worker.dart
Normal file
|
@ -0,0 +1,61 @@
|
|||
// 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.
|
||||
|
||||
/// API needed by `utils/front_end/summary_worker.dart`, a tool used to compute
|
||||
/// summaries in build systems like bazel, pub-build, and package-build.
|
||||
|
||||
import 'dart:async' show Future;
|
||||
|
||||
import 'package:front_end/src/api_prototype/file_system.dart';
|
||||
import 'package:front_end/src/base/processed_options.dart';
|
||||
import 'package:front_end/src/kernel_generator_impl.dart';
|
||||
import 'package:kernel/target/targets.dart' show Target;
|
||||
|
||||
import '../api_prototype/compiler_options.dart';
|
||||
import 'compiler_state.dart';
|
||||
|
||||
export 'compiler_state.dart';
|
||||
|
||||
export '../api_prototype/physical_file_system.dart' show PhysicalFileSystem;
|
||||
export '../fasta/fasta_codes.dart' show LocatedMessage;
|
||||
export '../fasta/severity.dart' show Severity;
|
||||
|
||||
Future<InitializedCompilerState> initializeCompiler(
|
||||
InitializedCompilerState oldState,
|
||||
Uri sdkSummary,
|
||||
Uri packagesFile,
|
||||
List<Uri> inputSummaries,
|
||||
Target target,
|
||||
FileSystem fileSystem) async {
|
||||
// TODO(sigmund): use incremental compiler when it supports our use case.
|
||||
// Note: it is common for the summary worker to invoke the compiler with the
|
||||
// same input summary URIs, but with different contents, so we'd need to be
|
||||
// able to track shas or modification time-stamps to be able to invalidate the
|
||||
// old state appropriately.
|
||||
CompilerOptions options = new CompilerOptions()
|
||||
..sdkSummary = sdkSummary
|
||||
..packagesFileUri = packagesFile
|
||||
..inputSummaries = inputSummaries
|
||||
..target = target
|
||||
..fileSystem = fileSystem
|
||||
..chaseDependencies = true;
|
||||
|
||||
ProcessedOptions processedOpts = new ProcessedOptions(options, true, []);
|
||||
|
||||
return new InitializedCompilerState(options, processedOpts);
|
||||
}
|
||||
|
||||
Future<List<int>> compile(InitializedCompilerState compilerState,
|
||||
List<Uri> inputs, ProblemHandler problemHandler) async {
|
||||
CompilerOptions options = compilerState.options;
|
||||
options..onProblem = problemHandler;
|
||||
|
||||
ProcessedOptions processedOpts = compilerState.processedOpts;
|
||||
processedOpts.inputs.clear();
|
||||
processedOpts.inputs.addAll(inputs);
|
||||
|
||||
var result = await generateKernel(processedOpts,
|
||||
buildSummary: true, buildProgram: false);
|
||||
return result?.summary;
|
||||
}
|
|
@ -18,7 +18,6 @@ dependencies:
|
|||
dev_dependencies:
|
||||
analyzer: '>=0.30.0 <0.32.0'
|
||||
args: '>=0.13.0 <2.0.0'
|
||||
bazel_worker: ^0.1.4
|
||||
dart_style: '^1.0.7'
|
||||
json_rpc_2: ^2.0.4
|
||||
mockito: ^2.0.2
|
||||
|
|
|
@ -44,7 +44,7 @@ declare_args() {
|
|||
# ........dartfmt.dart.snapshot
|
||||
# ........dartdevc.dart.snapshot
|
||||
# ........dartdevk.dart.snapshot
|
||||
# ........front_end_worker.dart.snapshot
|
||||
# ........kernel_summary_worker.dart.snapshot
|
||||
# ........pub.dart.snapshot
|
||||
# ........utils_wrapper.dart.snapshot
|
||||
#.........resources/
|
||||
|
@ -163,8 +163,8 @@ _full_sdk_snapshots = [
|
|||
"../utils/dartfmt",
|
||||
],
|
||||
[
|
||||
"front_end_worker",
|
||||
"../utils/front_end:front_end_worker",
|
||||
"kernel_summary_worker",
|
||||
"../utils/bazel:kernel_summary_worker",
|
||||
],
|
||||
[
|
||||
"pub",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import("../application_snapshot.gni")
|
||||
|
||||
application_snapshot("front_end_worker") {
|
||||
main_dart = "../../pkg/front_end/tool/bazel/worker.dart"
|
||||
application_snapshot("kernel_summary_worker") {
|
||||
main_dart = "kernel_summary_worker.dart"
|
||||
training_args = [ "--help" ]
|
||||
}
|
|
@ -1,16 +1,21 @@
|
|||
// 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.
|
||||
|
||||
/// A tool that invokes the CFE to compute kernel summary files.
|
||||
///
|
||||
/// This script can be used as a command-line command or a persistent server.
|
||||
/// The server is implemented using the bazel worker protocol, so it can be used
|
||||
/// within bazel as is. Other tools (like pub-build and package-build) also
|
||||
/// use this persistent worker via the same protocol.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:bazel_worker/bazel_worker.dart';
|
||||
import 'package:front_end/src/api_prototype/front_end.dart'
|
||||
hide FileSystemException;
|
||||
import 'package:front_end/src/fasta/command_line_reporting.dart';
|
||||
import 'package:front_end/src/api_unstable/summary_worker.dart' as fe;
|
||||
import 'package:front_end/src/multi_root_file_system.dart';
|
||||
import 'package:front_end/src/api_prototype/physical_file_system.dart';
|
||||
import 'package:kernel/target/targets.dart';
|
||||
|
||||
main(List<String> args) async {
|
||||
|
@ -108,42 +113,38 @@ Future<bool> computeSummary(List<String> args,
|
|||
var fileSystem = new MultiRootFileSystem(
|
||||
'org-dartlang-multi-root',
|
||||
parsedArgs['multi-root'].map(Uri.parse).toList(),
|
||||
PhysicalFileSystem.instance);
|
||||
var options = new CompilerOptions()
|
||||
..packagesFileUri = Uri.parse(parsedArgs['packages-file'])
|
||||
..inputSummaries = parsedArgs['input-summary'].map(Uri.parse).toList()
|
||||
..sdkSummary = Uri.parse(parsedArgs['dart-sdk-summary'])
|
||||
..fileSystem = fileSystem
|
||||
..target = new NoneTarget(new TargetFlags());
|
||||
fe.PhysicalFileSystem.instance);
|
||||
|
||||
options.onError = (CompilationMessage error) {
|
||||
var message = new StringBuffer()
|
||||
..write(severityName(error.severity, capitalized: true))
|
||||
..write(': ');
|
||||
if (error.span != null) {
|
||||
message.writeln(error.span.message(error.message));
|
||||
} else {
|
||||
message.writeln(error.message);
|
||||
}
|
||||
if (error.tip != null) {
|
||||
message.writeln(error.tip);
|
||||
}
|
||||
var state = await fe.initializeCompiler(
|
||||
// TODO(sigmund): pass an old state once we can make use of it.
|
||||
null,
|
||||
Uri.parse(parsedArgs['dart-sdk-summary']),
|
||||
Uri.parse(parsedArgs['packages-file']),
|
||||
parsedArgs['input-summary'].map(Uri.parse).toList(),
|
||||
new NoneTarget(new TargetFlags()),
|
||||
fileSystem);
|
||||
|
||||
void onProblem(problem, severity, String formatted, line, column) {
|
||||
if (outputBuffer != null) {
|
||||
outputBuffer.writeln(message);
|
||||
outputBuffer.writeln(formatted);
|
||||
} else {
|
||||
print(message);
|
||||
stderr.writeln(formatted);
|
||||
}
|
||||
if (error.severity != Severity.nit) {
|
||||
if (severity != fe.Severity.nit) {
|
||||
succeeded = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var sources = parsedArgs['source'].map(Uri.parse).toList();
|
||||
var program = await summaryFor(sources, options);
|
||||
var summary = await fe.compile(state, sources, onProblem);
|
||||
|
||||
var outputFile = new File(parsedArgs['output']);
|
||||
outputFile.createSync(recursive: true);
|
||||
outputFile.writeAsBytesSync(program);
|
||||
if (summary != null) {
|
||||
var outputFile = new File(parsedArgs['output']);
|
||||
outputFile.createSync(recursive: true);
|
||||
outputFile.writeAsBytesSync(summary);
|
||||
} else {
|
||||
assert(!succeeded);
|
||||
}
|
||||
|
||||
return succeeded;
|
||||
}
|
Loading…
Reference in a new issue