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

Unified Diff: pkg/dev_compiler/lib/src/compiler/compiler.dart

Issue 2598593003: support --options flag and other analysis options flags in DDC (Closed)
Patch Set: add missing tests Created 4 years 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 side-by-side diff with in-line comments
Download patch
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..65fc61cf83996cf71d51ed512c7ed55a7c531ee3 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,27 @@ 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,
+ {ResourceProvider resourceProvider, List<UriResolver> fileResolvers}) {
AnalysisEngine.instance.processRequiredPlugins();
- 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);
vsm 2017/01/03 17:56:28 Hmm, looks like this is the library-root being pas
danrubel 2017/01/03 18:51:48 Correct. It will start looking in the projRoot dir
+ (analysisOptions as AnalysisOptionsImpl)
+ ..strongMode = true
vsm 2017/01/03 17:56:28 Why do we need to set this here and in the context
danrubel 2017/01/03 18:51:48 Hmmm... good point. Removed. And I moved trackCac
+ ..trackCacheDependencies = false;
+ var sdk = contextBuilder.findSdk(null, analysisOptions);
+
+ var sdkResolver = new DartUriResolver(sdk);
// Read the summaries.
var summaryData =
@@ -89,7 +92,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 +106,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) {

Powered by Google App Engine
This is Rietveld 408576698