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

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

Issue 2405953002: Support for Bazel workspaces in ContextBuilder. (Closed)
Patch Set: Created 4 years, 2 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 | pkg/analyzer/test/src/context/builder_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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer.src.context.context_builder; 5 library analyzer.src.context.context_builder;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analyzer/context/declared_variables.dart'; 10 import 'package:analyzer/context/declared_variables.dart';
11 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/plugin/options.dart'; 12 import 'package:analyzer/plugin/options.dart';
13 import 'package:analyzer/plugin/resolver_provider.dart'; 13 import 'package:analyzer/plugin/resolver_provider.dart';
14 import 'package:analyzer/source/analysis_options_provider.dart'; 14 import 'package:analyzer/source/analysis_options_provider.dart';
15 import 'package:analyzer/source/package_map_resolver.dart'; 15 import 'package:analyzer/source/package_map_resolver.dart';
16 import 'package:analyzer/src/dart/sdk/sdk.dart'; 16 import 'package:analyzer/src/dart/sdk/sdk.dart';
17 import 'package:analyzer/src/generated/bazel.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/sdk.dart'; 19 import 'package:analyzer/src/generated/sdk.dart';
19 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
20 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 21 import 'package:analyzer/src/summary/package_bundle_reader.dart';
21 import 'package:analyzer/src/summary/pub_summary.dart'; 22 import 'package:analyzer/src/summary/pub_summary.dart';
22 import 'package:analyzer/src/task/options.dart'; 23 import 'package:analyzer/src/task/options.dart';
23 import 'package:package_config/packages.dart'; 24 import 'package:package_config/packages.dart';
24 import 'package:package_config/packages_file.dart'; 25 import 'package:package_config/packages_file.dart';
25 import 'package:package_config/src/packages_impl.dart'; 26 import 'package:package_config/src/packages_impl.dart';
26 import 'package:path/src/context.dart'; 27 import 'package:path/src/context.dart';
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 64
64 /** 65 /**
65 * The cache containing the contents of overlaid files. 66 * The cache containing the contents of overlaid files.
66 */ 67 */
67 final ContentCache contentCache; 68 final ContentCache contentCache;
68 69
69 /** 70 /**
70 * The resolver provider used to create a package: URI resolver, or `null` if 71 * The resolver provider used to create a package: URI resolver, or `null` if
71 * the normal (Package Specification DEP) lookup mechanism is to be used. 72 * the normal (Package Specification DEP) lookup mechanism is to be used.
72 */ 73 */
74 @deprecated
73 ResolverProvider packageResolverProvider; 75 ResolverProvider packageResolverProvider;
74 76
75 /** 77 /**
76 * The resolver provider used to create a file: URI resolver, or `null` if 78 * The resolver provider used to create a file: URI resolver, or `null` if
77 * the normal file URI resolver is to be used. 79 * the normal file URI resolver is to be used.
78 */ 80 */
81 @deprecated
79 ResolverProvider fileResolverProvider; 82 ResolverProvider fileResolverProvider;
80 83
81 /** 84 /**
82 * The file path of the .packages file that should be used in place of any 85 * The file path of the .packages file that should be used in place of any
83 * file found using the normal (Package Specification DEP) lookup mechanism, 86 * file found using the normal (Package Specification DEP) lookup mechanism,
84 * or `null` if the normal lookup mechanism should be used. 87 * or `null` if the normal lookup mechanism should be used.
85 */ 88 */
86 String defaultPackageFilePath; 89 String defaultPackageFilePath;
87 90
88 /** 91 /**
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 Map<String, Uri> map = parse(bytes, configFile.toUri()); 216 Map<String, Uri> map = parse(bytes, configFile.toUri());
214 resolveSymbolicLinks(map); 217 resolveSymbolicLinks(map);
215 return new MapPackages(map); 218 return new MapPackages(map);
216 } else if (defaultPackagesDirectoryPath != null) { 219 } else if (defaultPackagesDirectoryPath != null) {
217 Folder folder = resourceProvider.getFolder(defaultPackagesDirectoryPath); 220 Folder folder = resourceProvider.getFolder(defaultPackagesDirectoryPath);
218 return getPackagesFromFolder(folder); 221 return getPackagesFromFolder(folder);
219 } 222 }
220 return findPackagesFromFile(rootDirectoryPath); 223 return findPackagesFromFile(rootDirectoryPath);
221 } 224 }
222 225
223 SourceFactory createSourceFactory( 226 SourceFactory createSourceFactory(String rootPath, AnalysisOptions options) {
224 String rootDirectoryPath, AnalysisOptions options) { 227 BazelWorkspace bazelWorkspace =
225 Folder _folder = null; 228 BazelWorkspace.find(resourceProvider, rootPath);
226 Folder folder() { 229 if (bazelWorkspace != null) {
227 return _folder ??= resourceProvider.getFolder(rootDirectoryPath); 230 UriResolver fileResolver = new BazelFileUriResolver(bazelWorkspace);
231 UriResolver packageResolver = new BazelPackageUriResolver(bazelWorkspace);
232 // TODO(brianwilkerson) This doesn't support either embedder files or
Brian Wilkerson 2016/10/10 20:47:43 I think we can remove this comment.
233 // sdk extensions because we don't have a way to get the package map
234 // from the resolver.
235 List<UriResolver> resolvers = <UriResolver>[
236 new DartUriResolver(findSdk(null, options)),
237 packageResolver,
238 fileResolver
239 ];
240 return new SourceFactory(resolvers, null, resourceProvider);
228 } 241 }
229 242
230 UriResolver fileResolver; 243 Packages packages = createPackageMap(rootPath);
231 if (fileResolverProvider != null) {
232 fileResolver = fileResolverProvider(folder());
233 }
234 fileResolver ??= new ResourceUriResolver(resourceProvider);
235 if (packageResolverProvider != null) {
236 UriResolver packageResolver = packageResolverProvider(folder());
237 if (packageResolver != null) {
238 // TODO(brianwilkerson) This doesn't support either embedder files or
239 // sdk extensions because we don't have a way to get the package map
240 // from the resolver.
241 List<UriResolver> resolvers = <UriResolver>[
242 new DartUriResolver(findSdk(null, options)),
243 packageResolver,
244 fileResolver
245 ];
246 return new SourceFactory(resolvers, null, resourceProvider);
247 }
248 }
249 Packages packages = createPackageMap(rootDirectoryPath);
250 Map<String, List<Folder>> packageMap = convertPackagesToMap(packages); 244 Map<String, List<Folder>> packageMap = convertPackagesToMap(packages);
251 List<UriResolver> resolvers = <UriResolver>[ 245 List<UriResolver> resolvers = <UriResolver>[
252 new DartUriResolver(findSdk(packageMap, options)), 246 new DartUriResolver(findSdk(packageMap, options)),
253 new PackageMapUriResolver(resourceProvider, packageMap), 247 new PackageMapUriResolver(resourceProvider, packageMap),
254 fileResolver 248 new ResourceUriResolver(resourceProvider)
255 ]; 249 ];
256 return new SourceFactory(resolvers, packages, resourceProvider); 250 return new SourceFactory(resolvers, packages, resourceProvider);
257 } 251 }
258 252
259 /** 253 /**
260 * Add any [declaredVariables] to the list of declared variables used by the 254 * Add any [declaredVariables] to the list of declared variables used by the
261 * given [context]. 255 * given [context].
262 */ 256 */
263 void declareVariables(InternalAnalysisContext context) { 257 void declareVariables(InternalAnalysisContext context) {
264 if (declaredVariables != null && declaredVariables.isNotEmpty) { 258 if (declaredVariables != null && declaredVariables.isNotEmpty) {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 String _readEmbedderYaml(Folder libDir) { 585 String _readEmbedderYaml(Folder libDir) {
592 File file = libDir.getChild(EMBEDDER_FILE_NAME); 586 File file = libDir.getChild(EMBEDDER_FILE_NAME);
593 try { 587 try {
594 return file.readAsStringSync(); 588 return file.readAsStringSync();
595 } on FileSystemException { 589 } on FileSystemException {
596 // File can't be read. 590 // File can't be read.
597 return null; 591 return null;
598 } 592 }
599 } 593 }
600 } 594 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/builder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698