| Index: pkg/analyzer_cli/lib/src/build_mode.dart
|
| diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart
|
| index 042cde2de86bd07996654de619d1d6e6cd26fdaf..511c6c099ddb23d18eae2b513c724a92eaeb2252 100644
|
| --- a/pkg/analyzer_cli/lib/src/build_mode.dart
|
| +++ b/pkg/analyzer_cli/lib/src/build_mode.dart
|
| @@ -7,8 +7,6 @@ library analyzer_cli.src.build_mode;
|
| import 'dart:core' hide Resource;
|
| import 'dart:io' as io;
|
|
|
| -import 'package:protobuf/protobuf.dart';
|
| -
|
| import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit;
|
| import 'package:analyzer/dart/element/element.dart';
|
| import 'package:analyzer/file_system/file_system.dart';
|
| @@ -21,8 +19,8 @@ import 'package:analyzer/src/generated/source.dart';
|
| import 'package:analyzer/src/generated/source_io.dart';
|
| import 'package:analyzer/src/summary/format.dart';
|
| import 'package:analyzer/src/summary/idl.dart';
|
| +import 'package:analyzer/src/summary/link.dart';
|
| import 'package:analyzer/src/summary/package_bundle_reader.dart';
|
| -import 'package:analyzer/src/summary/prelink.dart';
|
| import 'package:analyzer/src/summary/summarize_ast.dart';
|
| import 'package:analyzer/src/summary/summarize_elements.dart';
|
| import 'package:analyzer/task/dart.dart';
|
| @@ -30,6 +28,7 @@ import 'package:analyzer_cli/src/analyzer_impl.dart';
|
| import 'package:analyzer_cli/src/driver.dart';
|
| import 'package:analyzer_cli/src/error_formatter.dart';
|
| import 'package:analyzer_cli/src/options.dart';
|
| +import 'package:protobuf/protobuf.dart';
|
|
|
| import 'message_grouper.dart';
|
| import 'worker_protocol.pb.dart';
|
| @@ -99,21 +98,23 @@ class BuildMode {
|
|
|
| // Write summary.
|
| if (options.buildSummaryOutput != null) {
|
| - for (Source source in explicitSources) {
|
| - if (context.computeKindOf(source) == SourceKind.LIBRARY) {
|
| + if (options.buildSummaryOnlyAst && !options.buildSummaryFallback) {
|
| + _serializeAstBasedSummary(explicitSources);
|
| + } else {
|
| + for (Source source in explicitSources) {
|
| + if (context.computeKindOf(source) == SourceKind.LIBRARY) {
|
| + if (options.buildSummaryFallback) {
|
| + assembler.addFallbackLibrary(source);
|
| + } else {
|
| + LibraryElement libraryElement =
|
| + context.computeLibraryElement(source);
|
| + assembler.serializeLibraryElement(libraryElement);
|
| + }
|
| + }
|
| if (options.buildSummaryFallback) {
|
| - assembler.addFallbackLibrary(source);
|
| - } else if (options.buildSummaryOnlyAst) {
|
| - _serializeAstBasedSummary(source);
|
| - } else {
|
| - LibraryElement libraryElement =
|
| - context.computeLibraryElement(source);
|
| - assembler.serializeLibraryElement(libraryElement);
|
| + assembler.addFallbackUnit(source);
|
| }
|
| }
|
| - if (options.buildSummaryFallback) {
|
| - assembler.addFallbackUnit(source);
|
| - }
|
| }
|
| // Write the whole package bundle.
|
| PackageBundleBuilder sdkBundle = assembler.assemble();
|
| @@ -216,33 +217,28 @@ class BuildMode {
|
| }
|
|
|
| /**
|
| - * Serialize the library with the given [source] into [assembler] using only
|
| - * its AST, [UnlinkedUnit]s of input packages and ASTs (via [UnlinkedUnit]s)
|
| - * of package sources.
|
| + * Serialize the package with the given [sources] into [assembler] using only
|
| + * their ASTs and [LinkedUnit]s of input packages.
|
| */
|
| - void _serializeAstBasedSummary(Source source) {
|
| - Source resolveRelativeUri(String relativeUri) {
|
| - Source resolvedSource =
|
| - context.sourceFactory.resolveUri(source, relativeUri);
|
| - if (resolvedSource == null) {
|
| - context.sourceFactory.resolveUri(source, relativeUri);
|
| - throw new StateError('Could not resolve $relativeUri in the context of '
|
| - '$source (${source.runtimeType})');
|
| - }
|
| - return resolvedSource;
|
| - }
|
| + void _serializeAstBasedSummary(List<Source> sources) {
|
| + Set<String> sourceUris =
|
| + sources.map((Source s) => s.uri.toString()).toSet();
|
|
|
| - UnlinkedUnit _getUnlinkedUnit(Source source) {
|
| + LinkedLibrary _getDependency(String absoluteUri) =>
|
| + summaryDataStore.linkedMap[absoluteUri];
|
| +
|
| + UnlinkedUnit _getUnit(String absoluteUri) {
|
| // Maybe an input package contains the source.
|
| {
|
| - String uriStr = source.uri.toString();
|
| - UnlinkedUnit unlinkedUnit = summaryDataStore.unlinkedMap[uriStr];
|
| + UnlinkedUnit unlinkedUnit = summaryDataStore.unlinkedMap[absoluteUri];
|
| if (unlinkedUnit != null) {
|
| return unlinkedUnit;
|
| }
|
| }
|
| // Parse the source and serialize its AST.
|
| - return uriToUnit.putIfAbsent(source.uri, () {
|
| + Uri uri = Uri.parse(absoluteUri);
|
| + Source source = context.sourceFactory.forUri2(uri);
|
| + return uriToUnit.putIfAbsent(uri, () {
|
| CompilationUnit unit = context.computeResult(source, PARSED_UNIT);
|
| UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit);
|
| assembler.addUnlinkedUnit(source, unlinkedUnit);
|
| @@ -250,18 +246,9 @@ class BuildMode {
|
| });
|
| }
|
|
|
| - UnlinkedUnit getPart(String relativeUri) {
|
| - return _getUnlinkedUnit(resolveRelativeUri(relativeUri));
|
| - }
|
| -
|
| - UnlinkedPublicNamespace getImport(String relativeUri) {
|
| - return getPart(relativeUri).publicNamespace;
|
| - }
|
| -
|
| - UnlinkedUnitBuilder definingUnit = _getUnlinkedUnit(source);
|
| - LinkedLibraryBuilder linkedLibrary =
|
| - prelink(definingUnit, getPart, getImport);
|
| - assembler.addLinkedLibrary(source.uri.toString(), linkedLibrary);
|
| + Map<String, LinkedLibraryBuilder> linkResult =
|
| + link(sourceUris, _getDependency, _getUnit, options.strongMode);
|
| + linkResult.forEach(assembler.addLinkedLibrary);
|
| }
|
|
|
| /**
|
| @@ -288,6 +275,36 @@ class BuildMode {
|
| }
|
|
|
| /**
|
| + * Default implementation of [WorkerConnection] that works with stdio.
|
| + */
|
| +class StdWorkerConnection implements WorkerConnection {
|
| + final MessageGrouper _messageGrouper;
|
| + final io.Stdout _stdoutStream;
|
| +
|
| + StdWorkerConnection(io.Stdin stdinStream, this._stdoutStream)
|
| + : _messageGrouper = new MessageGrouper(stdinStream);
|
| +
|
| + @override
|
| + WorkRequest readRequest() {
|
| + var buffer = _messageGrouper.next;
|
| + if (buffer == null) return null;
|
| +
|
| + return new WorkRequest.fromBuffer(buffer);
|
| + }
|
| +
|
| + @override
|
| + void writeResponse(WorkResponse response) {
|
| + var responseBuffer = response.writeToBuffer();
|
| +
|
| + var writer = new CodedBufferWriter();
|
| + writer.writeInt32NoTag(responseBuffer.length);
|
| + writer.writeRawBytes(responseBuffer);
|
| +
|
| + _stdoutStream.add(writer.toBuffer());
|
| + }
|
| +}
|
| +
|
| +/**
|
| * Connection between a worker and input / output.
|
| */
|
| abstract class WorkerConnection {
|
| @@ -395,33 +412,3 @@ class WorkerLoop {
|
| return msg;
|
| }
|
| }
|
| -
|
| -/**
|
| - * Default implementation of [WorkerConnection] that works with stdio.
|
| - */
|
| -class StdWorkerConnection implements WorkerConnection {
|
| - final MessageGrouper _messageGrouper;
|
| - final io.Stdout _stdoutStream;
|
| -
|
| - StdWorkerConnection(io.Stdin stdinStream, this._stdoutStream)
|
| - : _messageGrouper = new MessageGrouper(stdinStream);
|
| -
|
| - @override
|
| - WorkRequest readRequest() {
|
| - var buffer = _messageGrouper.next;
|
| - if (buffer == null) return null;
|
| -
|
| - return new WorkRequest.fromBuffer(buffer);
|
| - }
|
| -
|
| - @override
|
| - void writeResponse(WorkResponse response) {
|
| - var responseBuffer = response.writeToBuffer();
|
| -
|
| - var writer = new CodedBufferWriter();
|
| - writer.writeInt32NoTag(responseBuffer.length);
|
| - writer.writeRawBytes(responseBuffer);
|
| -
|
| - _stdoutStream.add(writer.toBuffer());
|
| - }
|
| -}
|
|
|