Skip to content

Commit

Permalink
Remove SDK extension support from PubSummaryManager.
Browse files Browse the repository at this point in the history
As we discussed, the Flutter SDK bundle contains everything - the
libraries from the Flutter embedder, and also the extension library.

R=brianwilkerson@google.com, paulberry@google.com
BUG=

Review URL: https://codereview.chromium.org/2278603003 .
  • Loading branch information
scheglov committed Aug 24, 2016
1 parent 6df6a3b commit 2b087ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 392 deletions.
105 changes: 6 additions & 99 deletions pkg/analyzer/lib/src/summary/pub_summary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/scanner/reader.dart';
import 'package:analyzer/src/dart/scanner/scanner.dart';
import 'package:analyzer/src/dart/sdk/sdk.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/parser.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
import 'package:analyzer/src/summary/api_signature.dart';
import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary/idl.dart';
Expand Down Expand Up @@ -138,86 +136,6 @@ class PubSummaryManager {
*/
pathos.Context get pathContext => resourceProvider.pathContext;

/**
* Compute and return the linked bundle for the SDK extension for the given
* [context], or `null` if none of the packages has an SDK extension. At most
* one extension library is supported, if more than one is found, then an
* error will be logged, and `null` returned.
*/
PackageBundle computeSdkExtension(
AnalysisContext context, PackageBundle sdkBundle) {
// Prepare SDK extension library files.
String libUriStr;
String libPath;
{
Map<String, List<Folder>> packageMap = context.sourceFactory.packageMap;
SdkExtensionFinder extFinder = new SdkExtensionFinder(packageMap);
Map<String, String> sdkExtMappings = extFinder.urlMappings;
if (sdkExtMappings.length == 1) {
libUriStr = sdkExtMappings.keys.first;
libPath = sdkExtMappings.values.first;
} else if (sdkExtMappings.length > 1) {
AnalysisEngine.instance.logger
.logError('At most one _sdkext file is supported, '
'with at most one extension library. $sdkExtMappings found.');
return null;
} else {
return null;
}
}
// Compute the extension unlinked bundle.
bool strong = context.analysisOptions.strongMode;
PackageBundleAssembler assembler = new PackageBundleAssembler();
try {
File libFile = resourceProvider.getFile(libPath);
Uri libUri = FastUri.parse(libUriStr);
Source libSource = libFile.createSource(libUri);
CompilationUnit libraryUnit = _parse(libSource, strong);
// Add the library unit.
assembler.addUnlinkedUnit(libSource, serializeAstUnlinked(libraryUnit));
// Add part units.
for (Directive directive in libraryUnit.directives) {
if (directive is PartDirective) {
Source partSource;
{
String partUriStr = directive.uri.stringValue;
Uri partUri = resolveRelativeUri(libUri, FastUri.parse(partUriStr));
pathos.Context pathContext = resourceProvider.pathContext;
String partPath =
pathContext.join(pathContext.dirname(libPath), partUriStr);
File partFile = resourceProvider.getFile(partPath);
partSource = partFile.createSource(partUri);
}
CompilationUnit partUnit = _parse(partSource, strong);
assembler.addUnlinkedUnit(partSource, serializeAstUnlinked(partUnit));
}
}
// Add the SDK and the unlinked extension bundle.
PackageBundleBuilder unlinkedBuilder = assembler.assemble();
SummaryDataStore store = new SummaryDataStore(const <String>[]);
store.addBundle(null, sdkBundle);
store.addBundle(null, unlinkedBuilder);
// Link the extension bundle.
Map<String, LinkedLibraryBuilder> linkedLibraries =
link([libUriStr].toSet(), (String absoluteUri) {
return store.linkedMap[absoluteUri];
}, (String absoluteUri) {
return store.unlinkedMap[absoluteUri];
}, strong);
if (linkedLibraries.length != 1) {
return null;
}
// Append linked libraries into the assembler.
linkedLibraries.forEach((uri, library) {
assembler.addLinkedLibrary(uri, library);
});
List<int> bytes = assembler.assemble().toBuffer();
return new PackageBundle.fromBuffer(bytes);
} on FileSystemException {
return null;
}
}

/**
* Complete when the unlinked bundles for the package with the given [name]
* and the [libFolder] are computed and written to the files.
Expand Down Expand Up @@ -249,15 +167,6 @@ class PubSummaryManager {
return const <LinkedPubPackage>[];
}

// Prepare all SDK bundles.
List<PackageBundle> sdkBundles = <PackageBundle>[sdkBundle];
{
PackageBundle extension = computeSdkExtension(context, sdkBundle);
if (extension != null) {
sdkBundles.add(extension);
}
}

bool strong = context.analysisOptions.strongMode;
Map<PubPackage, PackageBundle> unlinkedBundles =
getUnlinkedBundles(context);
Expand All @@ -277,7 +186,7 @@ class PubSummaryManager {
Map<String, _LinkedNode> packageToNode = <String, _LinkedNode>{};
unlinkedBundles.forEach((package, unlinked) {
_LinkedNode node = new _LinkedNode(
sdkBundles, listedPackages, package, unlinked, packageToNode);
sdkBundle, listedPackages, package, unlinked, packageToNode);
nodes.add(node);
packageToNode[package.name] = node;
});
Expand All @@ -293,10 +202,10 @@ class PubSummaryManager {
}

// Fill the store with bundles.
// Append linked SDK bundles.
// Append the linked SDK bundle.
// Append unlinked and (if read from a cache) linked package bundles.
SummaryDataStore store = new SummaryDataStore(const <String>[]);
sdkBundles.forEach((bundle) => store.addBundle(null, bundle));
store.addBundle(null, sdkBundle);
for (_LinkedNode node in nodes) {
store.addBundle(null, node.unlinked);
if (node.linked != null) {
Expand Down Expand Up @@ -626,7 +535,7 @@ class PubSummaryManager {
* Specialization of [Node] for linking packages in proper dependency order.
*/
class _LinkedNode extends Node<_LinkedNode> {
final List<PackageBundle> sdkBundles;
final PackageBundle sdkBundle;
final _ListedPackages listedPackages;
final PubPackage package;
final PackageBundle unlinked;
Expand All @@ -639,7 +548,7 @@ class _LinkedNode extends Node<_LinkedNode> {
List<int> linkedNewBytes;
PackageBundle linked;

_LinkedNode(this.sdkBundles, this.listedPackages, this.package, this.unlinked,
_LinkedNode(this.sdkBundle, this.listedPackages, this.package, this.unlinked,
this.packageToNode);

@override
Expand All @@ -655,9 +564,7 @@ class _LinkedNode extends Node<_LinkedNode> {
if (_linkedHash == null && transitiveDependencies != null) {
// Collect all unlinked API signatures.
List<String> signatures = <String>[];
sdkBundles
.map((sdkBundle) => sdkBundle.apiSignature)
.forEach(signatures.add);
signatures.add(sdkBundle.apiSignature);
transitiveDependencies
.map((node) => node.unlinked.apiSignature)
.forEach(signatures.add);
Expand Down
Loading

0 comments on commit 2b087ee

Please sign in to comment.