| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 /// Resolves this library and everything it transitively imports and generates | 6 /// Resolves this library and everything it transitively imports and generates |
| 7 /// errors in all of those libraries. Does this in an infinite loop, starting | 7 /// errors in all of those libraries. Does this in an infinite loop, starting |
| 8 /// from scratch each time, to show how VM warm-up affects things and to make | 8 /// from scratch each time, to show how VM warm-up affects things and to make |
| 9 /// it easier to connect to this with observatory. | 9 /// it easier to connect to this with observatory. |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/physical_file_system.dart'; | 14 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 15 import 'package:analyzer/source/package_map_resolver.dart'; |
| 16 import 'package:analyzer/src/context/builder.dart'; |
| 15 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 17 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/java_io.dart'; | |
| 18 import 'package:analyzer/src/generated/sdk.dart'; | |
| 19 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
| 20 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 21 import 'package:analyzer/src/source/source_resource.dart'; | 21 import 'package:analyzer/src/source/source_resource.dart'; |
| 22 import 'package:path/path.dart' as p; | 22 import 'package:path/path.dart' as p; |
| 23 | 23 |
| 24 void main(List<String> args) { | 24 void main(List<String> args) { |
| 25 // Assumes you have run "pub get" in the analyzer directory itself and uses | 25 // Assumes you have run "pub get" in the analyzer directory itself and uses |
| 26 // that "packages" directory as its package root. | 26 // that "packages" directory as its package root. |
| 27 var packageRoot = | 27 var packageRoot = |
| 28 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), "packages")); | 28 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), "packages")); |
| 29 | 29 |
| 30 var best = new Duration(days: 1); | 30 var best = new Duration(days: 1); |
| 31 while (true) { | 31 while (true) { |
| 32 var start = new DateTime.now(); | 32 var start = new DateTime.now(); |
| 33 AnalysisEngine.instance.clearCaches(); | 33 AnalysisEngine.instance.clearCaches(); |
| 34 | 34 |
| 35 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 36 options.strongMode = true; |
| 37 options.strongModeHints = true; |
| 38 |
| 35 PhysicalResourceProvider resourceProvider = | 39 PhysicalResourceProvider resourceProvider = |
| 36 PhysicalResourceProvider.INSTANCE; | 40 PhysicalResourceProvider.INSTANCE; |
| 37 DartSdk sdk = new FolderBasedDartSdk( | 41 FolderBasedDartSdk sdk = new FolderBasedDartSdk( |
| 38 resourceProvider, resourceProvider.getFolder(args[0])); | 42 resourceProvider, resourceProvider.getFolder(args[0])); |
| 43 sdk.analysisOptions = options; |
| 44 |
| 45 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); |
| 39 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 46 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 40 context.sourceFactory = new SourceFactory([ | 47 context.sourceFactory = new SourceFactory([ |
| 41 new DartUriResolver(sdk), | 48 new DartUriResolver(sdk), |
| 42 new ResourceUriResolver(resourceProvider), | 49 new ResourceUriResolver(resourceProvider), |
| 43 new PackageUriResolver([new JavaFile(packageRoot)]) | 50 new PackageMapUriResolver(resourceProvider, |
| 51 builder.convertPackagesToMap(builder.createPackageMap(packageRoot))) |
| 44 ]); | 52 ]); |
| 45 | 53 context.analysisOptions = options; |
| 46 AnalysisOptionsImpl options = context.analysisOptions; | |
| 47 options.strongMode = true; | |
| 48 options.strongModeHints = true; | |
| 49 | 54 |
| 50 var mainSource = | 55 var mainSource = |
| 51 new FileSource(resourceProvider.getFile(p.fromUri(Platform.script))); | 56 new FileSource(resourceProvider.getFile(p.fromUri(Platform.script))); |
| 52 context.applyChanges(new ChangeSet()..addedSource(mainSource)); | 57 context.applyChanges(new ChangeSet()..addedSource(mainSource)); |
| 53 | 58 |
| 54 var initialLibrary = | 59 var initialLibrary = |
| 55 context.resolveCompilationUnit2(mainSource, mainSource); | 60 context.resolveCompilationUnit2(mainSource, mainSource); |
| 56 | 61 |
| 57 // Walk all of the transitively referenced libraries and compute errors. | 62 // Walk all of the transitively referenced libraries and compute errors. |
| 58 var errorCount = 0; | 63 var errorCount = 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 84 if (seen.contains(lib)) return; | 89 if (seen.contains(lib)) return; |
| 85 seen.add(lib); | 90 seen.add(lib); |
| 86 results.add(lib); | 91 results.add(lib); |
| 87 lib.importedLibraries.forEach(find); | 92 lib.importedLibraries.forEach(find); |
| 88 lib.exportedLibraries.forEach(find); | 93 lib.exportedLibraries.forEach(find); |
| 89 } | 94 } |
| 90 | 95 |
| 91 find(start); | 96 find(start); |
| 92 return results; | 97 return results; |
| 93 } | 98 } |
| OLD | NEW |