Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: lib/src/barback/dependency_computer.dart

Issue 1220223008: Fix an edge case in the dependency computer. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/dependency_computer/dev_transformers_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library pub.barback.dependency_computer; 5 library pub.barback.dependency_computer;
6 6
7 import 'package:barback/barback.dart'; 7 import 'package:barback/barback.dart';
8 import 'package:path/path.dart' as p; 8 import 'package:path/path.dart' as p;
9 9
10 import '../dart.dart'; 10 import '../dart.dart';
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 traversePackage(packageName) { 166 traversePackage(packageName) {
167 if (seen.contains(packageName)) return; 167 if (seen.contains(packageName)) return;
168 seen.add(packageName); 168 seen.add(packageName);
169 169
170 var package = _graph.packages[packageName]; 170 var package = _graph.packages[packageName];
171 for (var phase in package.pubspec.transformers) { 171 for (var phase in package.pubspec.transformers) {
172 for (var config in phase) { 172 for (var config in phase) {
173 var id = config.id; 173 var id = config.id;
174 if (id.isBuiltInTransformer) continue; 174 if (id.isBuiltInTransformer) continue;
175 if (packageName != _graph.entrypoint.root.name &&
176 !config.canTransformPublicFiles) {
177 continue;
178 }
179
175 if (_loadingPackageComputers.contains(id.package)) { 180 if (_loadingPackageComputers.contains(id.package)) {
176 throw new CycleException("$packageName is transformed by $id"); 181 throw new CycleException("$packageName is transformed by $id");
177 } 182 }
183
178 results.add(id); 184 results.add(id);
179 } 185 }
180 } 186 }
181 187
182 var dependencies = packageName == _graph.entrypoint.root.name ? 188 var dependencies = packageName == _graph.entrypoint.root.name ?
183 package.immediateDependencies : package.dependencies; 189 package.immediateDependencies : package.dependencies;
184 for (var dep in dependencies) { 190 for (var dep in dependencies) {
185 try { 191 try {
186 traversePackage(dep.name); 192 traversePackage(dep.name);
187 } on CycleException catch (error) { 193 } on CycleException catch (error) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 var isRootPackage = 263 var isRootPackage =
258 packageName == _dependencyComputer._graph.entrypoint.root.name; 264 packageName == _dependencyComputer._graph.entrypoint.root.name;
259 265
260 // If [_package] uses its own transformers, there will be fewer transformers 266 // If [_package] uses its own transformers, there will be fewer transformers
261 // running on [_package] while its own transformers are loading than there 267 // running on [_package] while its own transformers are loading than there
262 // will be once all its transformers are finished loading. To handle this, 268 // will be once all its transformers are finished loading. To handle this,
263 // we run [_transformersNeededByTransformer] to pre-populate 269 // we run [_transformersNeededByTransformer] to pre-populate
264 // [_transformersNeededByLibraries] while [_applicableTransformers] is 270 // [_transformersNeededByLibraries] while [_applicableTransformers] is
265 // smaller. 271 // smaller.
266 for (var phase in _package.pubspec.transformers) { 272 for (var phase in _package.pubspec.transformers) {
267 for (var config in phase) { 273 _applicableTransformers.addAll(phase.where((config) {
268 // Ignore non-root transformers on non-public files. 274 // Ignore non-root transformers on non-public files.
269 if (!isRootPackage && !config.canTransformPublicFiles) continue; 275 if (!isRootPackage && !config.canTransformPublicFiles) return false;
270 276
271 var id = config.id; 277 var id = config.id;
272 try { 278 try {
273 if (id.package != _package.name) { 279 if (id.package != _package.name) {
274 // Probe [id]'s transformer dependencies to ensure that it doesn't 280 // Probe [id]'s transformer dependencies to ensure that it doesn't
275 // depend on this package. If it does, a CycleError will be thrown. 281 // depend on this package. If it does, a CycleError will be thrown.
276 _dependencyComputer._transformersNeededByTransformer(id); 282 _dependencyComputer._transformersNeededByTransformer(id);
277 } else { 283 } else {
278 // Store the transformers needed specifically with the current set 284 // Store the transformers needed specifically with the current set
279 // of [_applicableTransformers]. When reporting this transformer's 285 // of [_applicableTransformers]. When reporting this transformer's
280 // dependencies, [computeTransformersNeededByTransformers] will use 286 // dependencies, [computeTransformersNeededByTransformers] will use
281 // this stored set of dependencies rather than the potentially wider 287 // this stored set of dependencies rather than the potentially wider
282 // set that would be recomputed if [transformersNeededByLibrary] 288 // set that would be recomputed if [transformersNeededByLibrary]
283 // were called anew. 289 // were called anew.
284 _transformersNeededByTransformers[id] = 290 _transformersNeededByTransformers[id] =
285 transformersNeededByLibrary(_package.transformerPath(id)); 291 transformersNeededByLibrary(_package.transformerPath(id));
286 } 292 }
287 } on CycleException catch (error) { 293 } on CycleException catch (error) {
288 throw error.prependStep("$packageName is transformed by $id"); 294 throw error.prependStep("$packageName is transformed by $id");
289 } 295 }
290 } 296
297 return true;
298 }));
291 299
292 // Clear the cached imports and exports because the new transformers may 300 // Clear the cached imports and exports because the new transformers may
293 // start transforming a library whose directives were previously 301 // start transforming a library whose directives were previously
294 // statically analyzable. 302 // statically analyzable.
295 _transitiveExternalDirectives.clear(); 303 _transitiveExternalDirectives.clear();
296 _applicableTransformers.addAll(phase);
297 } 304 }
298 } 305 }
299 306
300 /// Returns the set of all transformers that need to be loaded before [id] is 307 /// Returns the set of all transformers that need to be loaded before [id] is
301 /// loaded. 308 /// loaded.
302 /// 309 ///
303 /// [id] must refer to a transformer in [_package]. 310 /// [id] must refer to a transformer in [_package].
304 Set<TransformerId> _transformersNeededByTransformer(TransformerId id) { 311 Set<TransformerId> _transformersNeededByTransformer(TransformerId id) {
305 assert(id.package == _package.name); 312 assert(id.package == _package.name);
306 if (_transformersNeededByTransformers.containsKey(id)) { 313 if (_transformersNeededByTransformers.containsKey(id)) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return null; 444 return null;
438 } 445 }
439 446
440 _directives[libraryUri] = 447 _directives[libraryUri] =
441 parseImportsAndExports(readTextFile(library), name: library) 448 parseImportsAndExports(readTextFile(library), name: library)
442 .map((directive) => Uri.parse(directive.uri.stringValue)) 449 .map((directive) => Uri.parse(directive.uri.stringValue))
443 .toSet(); 450 .toSet();
444 return _directives[libraryUri]; 451 return _directives[libraryUri];
445 } 452 }
446 } 453 }
OLDNEW
« no previous file with comments | « no previous file | test/dependency_computer/dev_transformers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698