| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Tracks the shape of the import/export graph and dependencies between files. | 5 /// Tracks the shape of the import/export graph and dependencies between files. |
| 6 library dev_compiler.src.dependency_graph; | 6 library dev_compiler.src.dependency_graph; |
| 7 | 7 |
| 8 import 'dart:collection' show HashSet, HashMap; | 8 import 'dart:collection' show HashSet, HashMap; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart' show parseDirectives; | 10 import 'package:analyzer/analyzer.dart' show parseDirectives; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void clearSummary() {} | 150 void clearSummary() {} |
| 151 | 151 |
| 152 void saveUpdatedContents() {} | 152 void saveUpdatedContents() {} |
| 153 | 153 |
| 154 String toString() { | 154 String toString() { |
| 155 var simpleUri = uri.scheme == 'file' ? path.relative(uri.path) : "$uri"; | 155 var simpleUri = uri.scheme == 'file' ? path.relative(uri.path) : "$uri"; |
| 156 return '[$runtimeType: $simpleUri]'; | 156 return '[$runtimeType: $simpleUri]'; |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 /// A unique node representing all entry points in the graph. This is just for |
| 161 /// graph algorthm convenience. |
| 162 class EntryNode extends SourceNode { |
| 163 final Iterable<SourceNode> entryPoints; |
| 164 |
| 165 @override |
| 166 Iterable<SourceNode> get allDeps => entryPoints; |
| 167 |
| 168 @override |
| 169 Iterable<SourceNode> get depsWithoutParts => entryPoints; |
| 170 |
| 171 EntryNode(SourceGraph graph, Uri uri, Iterable<SourceNode> nodes) |
| 172 : entryPoints = nodes, |
| 173 super(graph, uri, null); |
| 174 } |
| 175 |
| 160 /// A node representing an entry HTML source file. | 176 /// A node representing an entry HTML source file. |
| 161 class HtmlSourceNode extends SourceNode { | 177 class HtmlSourceNode extends SourceNode { |
| 162 /// Resources included by default on any application. | 178 /// Resources included by default on any application. |
| 163 final runtimeDeps; | 179 final runtimeDeps; |
| 164 | 180 |
| 165 /// Libraries referred to via script tags. | 181 /// Libraries referred to via script tags. |
| 166 Set<DartSourceNode> scripts = new Set<DartSourceNode>(); | 182 Set<DartSourceNode> scripts = new Set<DartSourceNode>(); |
| 167 | 183 |
| 168 /// Link-rel stylesheets, images, and other specified files. | 184 /// Link-rel stylesheets, images, and other specified files. |
| 169 Set<SourceNode> resources = new Set<SourceNode>(); | 185 Set<SourceNode> resources = new Set<SourceNode>(); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // cases anways require using summaries to understand what parts of the public | 476 // cases anways require using summaries to understand what parts of the public |
| 461 // API may be affected by transitive changes. The re-export case is just one | 477 // API may be affected by transitive changes. The re-export case is just one |
| 462 // of those transitive cases, but is not sufficient. See | 478 // of those transitive cases, but is not sufficient. See |
| 463 // https://github.com/dart-lang/dev_compiler/issues/76 | 479 // https://github.com/dart-lang/dev_compiler/issues/76 |
| 464 var apiChangeDetected = new HashSet<SourceNode>(); | 480 var apiChangeDetected = new HashSet<SourceNode>(); |
| 465 bool htmlNeedsRebuild = false; | 481 bool htmlNeedsRebuild = false; |
| 466 | 482 |
| 467 bool shouldBuildNode(SourceNode n) { | 483 bool shouldBuildNode(SourceNode n) { |
| 468 if (n.needsRebuild) return true; | 484 if (n.needsRebuild) return true; |
| 469 if (n is HtmlSourceNode) return htmlNeedsRebuild; | 485 if (n is HtmlSourceNode) return htmlNeedsRebuild; |
| 470 if (n is ResourceSourceNode) return false; | 486 if (n is ResourceSourceNode || n is EntryNode) return false; |
| 471 return (n as DartSourceNode) | 487 return (n as DartSourceNode) |
| 472 .imports | 488 .imports |
| 473 .any((i) => apiChangeDetected.contains(i)); | 489 .any((i) => apiChangeDetected.contains(i)); |
| 474 } | 490 } |
| 475 | 491 |
| 476 visitInPostOrder(start, (n) { | 492 visitInPostOrder(start, (n) { |
| 477 if (n.structureChanged) htmlNeedsRebuild = true; | 493 if (n.structureChanged) htmlNeedsRebuild = true; |
| 478 if (shouldBuildNode(n)) { | 494 if (shouldBuildNode(n)) { |
| 479 var oldHash = n.cachingHash; | 495 var oldHash = n.cachingHash; |
| 480 if (build(n)) apiChangeDetected.add(n); | 496 if (build(n)) apiChangeDetected.add(n); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 var deps = includeParts ? node.allDeps : node.depsWithoutParts; | 535 var deps = includeParts ? node.allDeps : node.depsWithoutParts; |
| 520 deps.forEach(helper); | 536 deps.forEach(helper); |
| 521 action(node); | 537 action(node); |
| 522 } | 538 } |
| 523 helper(start); | 539 helper(start); |
| 524 } | 540 } |
| 525 | 541 |
| 526 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); | 542 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); |
| 527 | 543 |
| 528 final _log = new Logger('dev_compiler.dependency_graph'); | 544 final _log = new Logger('dev_compiler.dependency_graph'); |
| OLD | NEW |