Chromium Code Reviews| Index: pkg/analyzer/lib/src/summary/pub_summary.dart |
| diff --git a/pkg/analyzer/lib/src/summary/pub_summary.dart b/pkg/analyzer/lib/src/summary/pub_summary.dart |
| index 589118361ebeaf0a3c81b3eae9d4183ad6ace9e4..2f1d2a79d87cfe13076fc83643af9ced0a7640b3 100644 |
| --- a/pkg/analyzer/lib/src/summary/pub_summary.dart |
| +++ b/pkg/analyzer/lib/src/summary/pub_summary.dart |
| @@ -33,6 +33,12 @@ import 'package:meta/meta.dart'; |
| import 'package:path/path.dart' as pathos; |
| /** |
| + * Return the raw string value of the variable with the given [name], |
| + * or `null` of the variable is not defined. |
| + */ |
| +typedef String _GetDeclaredVariable(String name); |
| + |
| +/** |
| * Unlinked and linked information about a [PubPackage]. |
| */ |
| class LinkedPubPackage { |
| @@ -84,6 +90,12 @@ class PubSummaryManager { |
| static const UNLINKED_SPEC_NAME = 'unlinked_spec.ds'; |
| /** |
| + * If `true` (by default), then linking new bundles is allowed. |
| + * Otherwise only using existing cached bundles can be used. |
| + */ |
| + final bool allowLinking; |
| + |
| + /** |
| * See [PackageBundleAssembler.currentMajorVersion]. |
| */ |
| final int majorVersion; |
| @@ -126,7 +138,8 @@ class PubSummaryManager { |
| Completer _onUnlinkedCompleteCompleter; |
| PubSummaryManager(this.resourceProvider, this.tempFileName, |
| - {@visibleForTesting this.majorVersion: |
| + {@visibleForTesting this.allowLinking: true, |
| + @visibleForTesting this.majorVersion: |
| PackageBundleAssembler.currentMajorVersion}); |
| /** |
| @@ -196,7 +209,12 @@ class PubSummaryManager { |
| Map<String, _LinkedNode> packageToNode = <String, _LinkedNode>{}; |
| unlinkedBundles.forEach((package, unlinked) { |
| _LinkedNode node = new _LinkedNode( |
| - sdkBundle, listedPackages, package, unlinked, packageToNode); |
| + sdkBundle, |
| + context.declaredVariables.get, |
| + listedPackages, |
| + package, |
| + unlinked, |
| + packageToNode); |
| nodes.add(node); |
| packageToNode[package.name] = node; |
| }); |
| @@ -211,28 +229,31 @@ class PubSummaryManager { |
| _readLinked(node, strong); |
| } |
| - // Fill the store with bundles. |
| - // Append the linked SDK bundle. |
| - // Append unlinked and (if read from a cache) linked package bundles. |
| - SummaryDataStore store = new SummaryDataStore(const <String>[]); |
| - store.addBundle(null, sdkBundle); |
| - for (_LinkedNode node in nodes) { |
| - store.addBundle(null, node.unlinked); |
| - if (node.linked != null) { |
| - store.addBundle(null, node.linked); |
| + // Link new bundles, if allowed. |
| + if (allowLinking) { |
| + // Fill the store with bundles. |
| + // Append the linked SDK bundle. |
| + // Append unlinked and (if read from a cache) linked package bundles. |
| + SummaryDataStore store = new SummaryDataStore(const <String>[]); |
| + store.addBundle(null, sdkBundle); |
| + for (_LinkedNode node in nodes) { |
| + store.addBundle(null, node.unlinked); |
| + if (node.linked != null) { |
| + store.addBundle(null, node.linked); |
| + } |
| } |
| - } |
| - // Link each package node. |
| - for (_LinkedNode node in nodes) { |
| - if (!node.isEvaluated) { |
| - new _LinkedWalker(listedPackages, store, strong).walk(node); |
| + // Link each package node. |
| + for (_LinkedNode node in nodes) { |
| + if (!node.isEvaluated) { |
| + new _LinkedWalker(listedPackages, store, strong).walk(node); |
| + } |
| } |
| - } |
| - // Write newly linked bundles. |
| - for (_LinkedNode node in nodes) { |
| - _writeLinked(node, strong); |
| + // Write newly linked bundles. |
| + for (_LinkedNode node in nodes) { |
| + _writeLinked(node, strong); |
| + } |
| } |
| // Create successfully linked packages. |
| @@ -240,7 +261,7 @@ class PubSummaryManager { |
| for (_LinkedNode node in nodes) { |
| if (node.linked != null) { |
| linkedPackages.add(new LinkedPubPackage( |
| - node.package, node.unlinked, node.linked, node._linkedHash)); |
| + node.package, node.unlinked, node.linked, node.linkedHash)); |
| } |
| } |
| @@ -604,6 +625,7 @@ class PubSummaryManager { |
| */ |
| class _LinkedNode extends Node<_LinkedNode> { |
| final PackageBundle sdkBundle; |
| + final _GetDeclaredVariable getDeclaredVariable; |
| final _ListedPackages listedPackages; |
| final PubPackage package; |
| final PackageBundle unlinked; |
| @@ -616,30 +638,31 @@ class _LinkedNode extends Node<_LinkedNode> { |
| List<int> linkedNewBytes; |
| PackageBundle linked; |
| - _LinkedNode(this.sdkBundle, this.listedPackages, this.package, this.unlinked, |
| - this.packageToNode); |
| + _LinkedNode(this.sdkBundle, this.getDeclaredVariable, this.listedPackages, |
| + this.package, this.unlinked, this.packageToNode); |
| @override |
| bool get isEvaluated => linked != null || failed; |
| /** |
| * Return the hash string that corresponds to this linked bundle in the |
| - * context of its [sdkBundles] and transitive dependencies. Return `null` if |
| + * context of its [sdkBundle] and transitive dependencies. Return `null` if |
| * the hash computation fails, because for example the full transitive |
| * dependencies cannot computed. |
| */ |
| String get linkedHash { |
| if (_linkedHash == null && transitiveDependencies != null) { |
| - // Collect all unlinked API signatures. |
| + ApiSignature signature = new ApiSignature(); |
| + // Add all unlinked API signatures. |
| List<String> signatures = <String>[]; |
| signatures.add(sdkBundle.apiSignature); |
| transitiveDependencies |
| .map((node) => node.unlinked.apiSignature) |
| .forEach(signatures.add); |
| signatures.sort(); |
| - // Combine sorted unlinked API signatures into a single hash. |
| - ApiSignature signature = new ApiSignature(); |
| signatures.forEach(signature.addString); |
| + // Combine into a single hash. |
| + _appendDeclaredVariables(signature); |
| _linkedHash = signature.toHex(); |
| } |
| return _linkedHash; |
| @@ -709,6 +732,32 @@ class _LinkedNode extends Node<_LinkedNode> { |
| @override |
| String toString() => package.toString(); |
| + |
| + /** |
| + * Append names and values of all referenced declared variables (even the |
| + * ones without actually declared values) to the given [signature]. |
| + */ |
| + void _appendDeclaredVariables(ApiSignature signature) { |
| + Set<String> names = new Set<String>(); |
| + for (_LinkedNode node in transitiveDependencies) { |
| + for (UnlinkedUnit unit in node.unlinked.unlinkedUnits) { |
| + for (UnlinkedImport import in unit.imports) { |
| + for (UnlinkedConfiguration configuration in import.configurations) { |
| + names.add(configuration.name); |
| + } |
| + } |
| + for (UnlinkedExportPublic export in unit.publicNamespace.exports) { |
| + for (UnlinkedConfiguration configuration in export.configurations) { |
| + names.add(configuration.name); |
| + } |
| + } |
| + } |
| + } |
| + for (String name in names) { |
|
Paul Berry
2016/09/21 19:47:22
Before the for loop, add:
signature.addInt(names.
scheglov
2016/09/21 20:34:49
Done.
|
| + signature.addString(name); |
| + signature.addString(getDeclaredVariable(name) ?? ''); |
| + } |
| + } |
| } |
| /** |