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

Side by Side Diff: lib/src/analyzer/context.dart

Issue 1982853002: Allow the SDK to be set via a summary file (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 4 years, 7 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 | « lib/runtime/dart_sdk.sum ('k') | pubspec.yaml » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 2
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 import 'package:args/args.dart' show ArgParser, ArgResults; 6 import 'package:args/args.dart' show ArgParser, ArgResults;
7 import 'package:analyzer/src/generated/engine.dart' 7 import 'package:analyzer/src/generated/engine.dart'
8 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; 8 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl;
9 import 'package:analyzer/src/generated/java_io.dart' show JavaFile; 9 import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
10 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; 10 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk;
11 import 'package:analyzer/src/generated/source_io.dart' 11 import 'package:analyzer/src/generated/source_io.dart'
12 show 12 show
13 CustomUriResolver, 13 CustomUriResolver,
14 DartUriResolver, 14 DartUriResolver,
15 FileUriResolver, 15 FileUriResolver,
16 PackageUriResolver, 16 PackageUriResolver,
17 SourceFactory, 17 SourceFactory,
18 UriResolver; 18 UriResolver;
19 import 'package:analyzer/src/summary/package_bundle_reader.dart' 19 import 'package:analyzer/src/summary/package_bundle_reader.dart'
20 show 20 show
21 InSummaryPackageUriResolver, 21 InSummaryPackageUriResolver,
22 InputPackagesResultProvider, 22 InputPackagesResultProvider,
23 SummaryDataStore; 23 SummaryDataStore;
24 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
24 import 'package:cli_util/cli_util.dart' show getSdkDir; 25 import 'package:cli_util/cli_util.dart' show getSdkDir;
25 import 'package:path/path.dart' as path; 26 import 'package:path/path.dart' as path;
26 27
27 import 'dart_sdk.dart' show MockDartSdk, mockSdkSources; 28 import 'dart_sdk.dart' show MockDartSdk, mockSdkSources;
28 import 'multi_package_resolver.dart' show MultiPackageResolver; 29 import 'multi_package_resolver.dart' show MultiPackageResolver;
29 30
30 /// Options used to set up Source URI resolution in the analysis context. 31 /// Options used to set up Source URI resolution in the analysis context.
31 class AnalyzerOptions { 32 class AnalyzerOptions {
32 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" 33 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart"
33 final Map<String, String> customUrlMappings; 34 final Map<String, String> customUrlMappings;
34 35
35 /// Package root when resolving 'package:' urls the standard way. 36 /// Package root when resolving 'package:' urls the standard way.
36 final String packageRoot; 37 final String packageRoot;
37 38
38 /// List of summary file paths. 39 /// List of summary file paths.
39 final List<String> summaryPaths; 40 final List<String> summaryPaths;
40 41
41 /// List of paths used for the multi-package resolver. 42 /// List of paths used for the multi-package resolver.
42 final List<String> packagePaths; 43 final List<String> packagePaths;
43 44
44 /// Whether to use a mock-sdk during compilation. 45 /// Whether to use a mock-sdk during compilation.
45 final bool useMockSdk; 46 final bool useMockSdk;
46 47
47 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't 48 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't
48 /// be determined 49 /// be determined
49 final String dartSdkPath; 50 final String dartSdkPath;
50 51
52 /// Path to the dart-sdk summary. If this is set, it will be used in favor
53 /// of the unsummarized one.
54 final String dartSdkSummaryPath;
55
51 AnalyzerOptions( 56 AnalyzerOptions(
52 {this.summaryPaths: const [], 57 {this.summaryPaths: const [],
53 this.useMockSdk: false, 58 this.useMockSdk: false,
54 String dartSdkPath, 59 String dartSdkPath,
60 this.dartSdkSummaryPath,
55 this.customUrlMappings: const {}, 61 this.customUrlMappings: const {},
56 this.packageRoot: 'packages/', 62 this.packageRoot: 'packages/',
57 this.packagePaths: const []}) 63 this.packagePaths: const []})
58 : dartSdkPath = dartSdkPath ?? getSdkDir().path; 64 : dartSdkPath = dartSdkPath ?? getSdkDir().path;
59 65
60 AnalyzerOptions.fromArguments(ArgResults args) 66 AnalyzerOptions.fromArguments(ArgResults args)
61 : summaryPaths = args['summary'], 67 : summaryPaths = args['summary'],
62 useMockSdk = false, 68 useMockSdk = false,
63 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path, 69 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path,
70 dartSdkSummaryPath = args['dart-sdk-summary'],
64 customUrlMappings = _parseUrlMappings(args['url-mapping']), 71 customUrlMappings = _parseUrlMappings(args['url-mapping']),
65 packageRoot = args['package-root'], 72 packageRoot = args['package-root'],
66 packagePaths = args['package-paths']?.split(',') ?? []; 73 packagePaths = args['package-paths']?.split(',') ?? [];
67 74
68 /// Whether to resolve 'package:' uris using the multi-package resolver. 75 /// Whether to resolve 'package:' uris using the multi-package resolver.
69 bool get useMultiPackage => packagePaths.isNotEmpty; 76 bool get useMultiPackage => packagePaths.isNotEmpty;
70 77
71 static ArgParser addArguments(ArgParser parser) { 78 static ArgParser addArguments(ArgParser parser) {
72 return parser 79 return parser
73 ..addOption('summary', 80 ..addOption('summary',
74 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) 81 abbr: 's', help: 'summary file(s) to include', allowMultiple: true)
75 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) 82 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
83 ..addOption('dart-sdk-summary',
84 help: 'Dart SDK Summary Path', defaultsTo: null)
76 ..addOption('package-root', 85 ..addOption('package-root',
77 abbr: 'p', 86 abbr: 'p',
78 help: 'Package root to resolve "package:" imports', 87 help: 'Package root to resolve "package:" imports',
79 defaultsTo: 'packages/') 88 defaultsTo: 'packages/')
80 ..addOption('url-mapping', 89 ..addOption('url-mapping',
81 help: '--url-mapping=libraryUri,/path/to/library.dart uses \n' 90 help: '--url-mapping=libraryUri,/path/to/library.dart uses \n'
82 'library.dart as the source for an import of of "libraryUri".', 91 'library.dart as the source for an import of of "libraryUri".',
83 allowMultiple: true, 92 allowMultiple: true,
84 splitCommas: false) 93 splitCommas: false)
85 ..addOption('package-paths', 94 ..addOption('package-paths',
(...skipping 13 matching lines...) Expand all
99 } 108 }
100 109
101 /// Creates an [AnalysisContext] with dev_compiler type rules and inference, 110 /// Creates an [AnalysisContext] with dev_compiler type rules and inference,
102 /// using [createSourceFactory] to set up its [SourceFactory]. 111 /// using [createSourceFactory] to set up its [SourceFactory].
103 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options, 112 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options,
104 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) { 113 {DartUriResolver sdkResolver, List<UriResolver> fileResolvers}) {
105 AnalysisEngine.instance.processRequiredPlugins(); 114 AnalysisEngine.instance.processRequiredPlugins();
106 115
107 sdkResolver ??= options.useMockSdk 116 sdkResolver ??= options.useMockSdk
108 ? createMockSdkResolver(mockSdkSources) 117 ? createMockSdkResolver(mockSdkSources)
109 : createSdkPathResolver(options.dartSdkPath); 118 : createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath);
110 119
111 // Read the summaries. 120 // Read the summaries.
112 SummaryDataStore summaryData; 121 SummaryDataStore summaryData;
113 if (options.summaryPaths.isNotEmpty) { 122 if (options.summaryPaths.isNotEmpty) {
114 summaryData = new SummaryDataStore(options.summaryPaths); 123 summaryData = new SummaryDataStore(options.summaryPaths);
115 } 124 }
116 125
117 var srcFactory = _createSourceFactory(options, 126 var srcFactory = _createSourceFactory(options,
118 sdkResolver: sdkResolver, 127 sdkResolver: sdkResolver,
119 fileResolvers: fileResolvers, 128 fileResolvers: fileResolvers,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 options.useMultiPackage 176 options.useMultiPackage
168 ? new MultiPackageResolver(options.packagePaths) 177 ? new MultiPackageResolver(options.packagePaths)
169 : new PackageUriResolver([new JavaFile(options.packageRoot)]) 178 : new PackageUriResolver([new JavaFile(options.packageRoot)])
170 ]; 179 ];
171 } 180 }
172 181
173 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents. 182 /// Creates a [DartUriResolver] that uses a mock 'dart:' library contents.
174 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) => 183 DartUriResolver createMockSdkResolver(Map<String, String> mockSources) =>
175 new MockDartSdk(mockSources, reportMissing: true).resolver; 184 new MockDartSdk(mockSources, reportMissing: true).resolver;
176 185
177 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. 186 DirectoryBasedDartSdk _createDirectoryBasedDartSdk(String sdkPath) {
178 DartUriResolver createSdkPathResolver(String sdkPath) {
179 var sdk = new DirectoryBasedDartSdk( 187 var sdk = new DirectoryBasedDartSdk(
180 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true); 188 new JavaFile(sdkPath), /*useDart2jsPaths:*/ true);
181 sdk.useSummary = true; 189 sdk.useSummary = true;
182 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; 190 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true;
191 return sdk;
192 }
193
194 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath].
195 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) {
196 var sdk = (sdkSummaryPath != null)
197 ? new SummaryBasedDartSdk(sdkSummaryPath, true)
198 : _createDirectoryBasedDartSdk(sdkPath);
183 return new DartUriResolver(sdk); 199 return new DartUriResolver(sdk);
184 } 200 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.sum ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698