Chromium Code Reviews| Index: pkg/dev_compiler/lib/src/compiler/compiler.dart |
| diff --git a/pkg/dev_compiler/lib/src/compiler/compiler.dart b/pkg/dev_compiler/lib/src/compiler/compiler.dart |
| index 62921bd3ae3beb6b956b74b0658464d68c3751f4..fbd4cc6ff485ba0dcfe34db3fa3f3c50a362c2b8 100644 |
| --- a/pkg/dev_compiler/lib/src/compiler/compiler.dart |
| +++ b/pkg/dev_compiler/lib/src/compiler/compiler.dart |
| @@ -9,9 +9,15 @@ import 'package:analyzer/dart/element/element.dart' show LibraryElement; |
| import 'package:analyzer/analyzer.dart' |
| show AnalysisError, CompilationUnit, ErrorSeverity; |
| import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; |
| +import 'package:analyzer/file_system/physical_file_system.dart' |
| + show PhysicalResourceProvider; |
| +import 'package:analyzer/src/context/builder.dart' show ContextBuilder; |
| +import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; |
| import 'package:analyzer/src/generated/engine.dart' |
| - show AnalysisContext, AnalysisEngine; |
| -import 'package:analyzer/src/generated/source.dart' show DartUriResolver; |
| + show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; |
| +import 'package:analyzer/src/generated/sdk.dart' show DartSdkManager; |
| +import 'package:analyzer/src/generated/source.dart' |
| + show ContentCache, DartUriResolver; |
| import 'package:analyzer/src/generated/source_io.dart' |
| show Source, SourceKind, UriResolver; |
| import 'package:analyzer/src/summary/package_bundle_reader.dart' |
| @@ -23,12 +29,7 @@ import 'package:func/func.dart' show Func1; |
| import 'package:path/path.dart' as path; |
| import 'package:source_maps/source_maps.dart'; |
| -import '../analyzer/context.dart' |
| - show |
| - AnalyzerOptions, |
| - createAnalysisContext, |
| - createSdkPathResolver, |
| - createSourceFactory; |
| +import '../analyzer/context.dart' show AnalyzerOptions, createSourceFactory; |
| import '../js_ast/js_ast.dart' as JS; |
| import 'code_generator.dart' show CodeGenerator; |
| import 'error_helpers.dart' show errorSeverity, formatError, sortErrors; |
| @@ -59,25 +60,24 @@ class ModuleCompiler { |
| final SummaryDataStore summaryData; |
| final ExtensionTypeSet _extensionTypes; |
| - ModuleCompiler.withContext(AnalysisContext context, this.summaryData) |
| + ModuleCompiler._(AnalysisContext context, this.summaryData) |
| : context = context, |
| - _extensionTypes = new ExtensionTypeSet(context) { |
| - if (!context.analysisOptions.strongMode) { |
| - throw new ArgumentError('AnalysisContext must be strong mode'); |
| - } |
| - if (!context.sourceFactory.dartSdk.context.analysisOptions.strongMode) { |
| - throw new ArgumentError('AnalysisContext must have strong mode SDK'); |
| - } |
| - } |
| + _extensionTypes = new ExtensionTypeSet(context); |
| - factory ModuleCompiler(AnalyzerOptions options, |
| - {DartUriResolver sdkResolver, |
| - ResourceProvider resourceProvider, |
| - List<UriResolver> fileResolvers}) { |
| + factory ModuleCompiler(String projRoot, AnalyzerOptions options, |
|
vsm
2017/01/04 20:20:39
Perhaps rename projRoot to analysisOptionsPath or
danrubel
2017/01/04 20:41:20
The analyzer-cli looks in the current working dire
vsm
2017/01/04 20:46:20
Yes, I think it would make sense to act the same a
danrubel
2017/01/04 21:37:42
Done.
|
| + {ResourceProvider resourceProvider, List<UriResolver> fileResolvers}) { |
| AnalysisEngine.instance.processRequiredPlugins(); |
|
vsm
2017/01/04 20:20:39
Would it make sense to push much of the logic here
danrubel
2017/01/04 20:41:19
Yes, that's my long term goal, but I'm working tow
vsm
2017/01/04 20:46:20
SGTM :-) Do you mind adding a comment / todo here
danrubel
2017/01/04 21:37:42
Good point. Done.
|
| - sdkResolver ??= |
| - createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath); |
| + resourceProvider ??= PhysicalResourceProvider.INSTANCE; |
| + |
| + var contextBuilder = new ContextBuilder(resourceProvider, |
| + new DartSdkManager(options.dartSdkPath, true), new ContentCache(), |
| + options: options.contextBuilderOptions); |
| + |
| + var analysisOptions = contextBuilder.getAnalysisOptions(projRoot); |
| + var sdk = contextBuilder.findSdk(null, analysisOptions); |
| + |
| + var sdkResolver = new DartUriResolver(sdk); |
| // Read the summaries. |
| var summaryData = |
| @@ -89,7 +89,9 @@ class ModuleCompiler { |
| summaryData: summaryData, |
| resourceProvider: resourceProvider); |
| - var context = createAnalysisContext(); |
| + var context = |
| + AnalysisEngine.instance.createAnalysisContext() as AnalysisContextImpl; |
| + context.analysisOptions = analysisOptions; |
| context.sourceFactory = srcFactory; |
| context.typeProvider = sdkResolver.dartSdk.context.typeProvider; |
| context.resultProvider = |
| @@ -101,7 +103,14 @@ class ModuleCompiler { |
| context.declaredVariables.define('dart.library.html', 'true'); |
| context.declaredVariables.define('dart.library.io', 'false'); |
| - return new ModuleCompiler.withContext(context, summaryData); |
| + if (!context.analysisOptions.strongMode) { |
| + throw new ArgumentError('AnalysisContext must be strong mode'); |
| + } |
| + if (!context.sourceFactory.dartSdk.context.analysisOptions.strongMode) { |
| + throw new ArgumentError('AnalysisContext must have strong mode SDK'); |
| + } |
| + |
| + return new ModuleCompiler._(context, summaryData); |
| } |
| bool _isFatalError(AnalysisError e, CompilerOptions options) { |