Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.generated.sdk2; | 5 library analyzer.src.generated.sdk2; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 | 266 |
| 267 /** | 267 /** |
| 268 * An SDK backed by URI mappings derived from an `_embedder.yaml` file. | 268 * An SDK backed by URI mappings derived from an `_embedder.yaml` file. |
| 269 */ | 269 */ |
| 270 class EmbedderSdk extends AbstractDartSdk { | 270 class EmbedderSdk extends AbstractDartSdk { |
| 271 static const String _DART_COLON_PREFIX = 'dart:'; | 271 static const String _DART_COLON_PREFIX = 'dart:'; |
| 272 | 272 |
| 273 static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs'; | 273 static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs'; |
| 274 final Map<String, String> _urlMappings = new HashMap<String, String>(); | 274 final Map<String, String> _urlMappings = new HashMap<String, String>(); |
| 275 | 275 |
| 276 PackageBundle _embedderBundle; | 276 Folder _embedderYamlLibFolder; |
| 277 | 277 |
| 278 EmbedderSdk( | 278 EmbedderSdk( |
| 279 ResourceProvider resourceProvider, Map<Folder, YamlMap> embedderYamls) { | 279 ResourceProvider resourceProvider, Map<Folder, YamlMap> embedderYamls) { |
| 280 this.resourceProvider = resourceProvider; | 280 this.resourceProvider = resourceProvider; |
| 281 embedderYamls?.forEach(_processEmbedderYaml); | 281 embedderYamls?.forEach(_processEmbedderYaml); |
| 282 if (embedderYamls?.length == 1) { | 282 if (embedderYamls?.length == 1) { |
| 283 Folder libFolder = embedderYamls.keys.first; | 283 _embedderYamlLibFolder = embedderYamls.keys.first; |
| 284 _loadEmbedderBundle(libFolder); | |
| 285 } | 284 } |
| 286 } | 285 } |
| 287 | 286 |
| 288 @override | 287 @override |
| 289 // TODO(danrubel) Determine SDK version | 288 // TODO(danrubel) Determine SDK version |
| 290 String get sdkVersion => '0'; | 289 String get sdkVersion => '0'; |
| 291 | 290 |
| 292 /** | 291 /** |
| 293 * The url mappings for this SDK. | 292 * The url mappings for this SDK. |
| 294 */ | 293 */ |
| 295 Map<String, String> get urlMappings => _urlMappings; | 294 Map<String, String> get urlMappings => _urlMappings; |
| 296 | 295 |
| 297 @override | 296 @override |
| 298 String getRelativePathFromFile(File file) => file.path; | 297 String getRelativePathFromFile(File file) => file.path; |
| 299 | 298 |
| 300 @override | 299 @override |
| 301 PackageBundle getSummarySdkBundle(bool strongMode) { | 300 PackageBundle getSummarySdkBundle(bool strongMode) { |
| 302 if (strongMode) { | 301 String name = strongMode ? 'strong.sum' : 'spec.sum'; |
| 303 return _embedderBundle; | 302 File file = _embedderYamlLibFolder.parent.getChildAssumingFile(name); |
| 303 try { | |
| 304 if (file.exists) { | |
| 305 List<int> bytes = file.readAsBytesSync(); | |
| 306 return new PackageBundle.fromBuffer(bytes); | |
| 307 } | |
| 308 } catch (exception, stackTrace) { | |
| 309 AnalysisEngine.instance.logger.logError( | |
| 310 'Failed to load SDK analysis summary from $file', | |
|
devoncarew
2017/01/13 18:26:21
awesome!
| |
| 311 new CaughtException(exception, stackTrace)); | |
| 304 } | 312 } |
| 305 return null; | 313 return null; |
| 306 } | 314 } |
| 307 | 315 |
| 308 @override | 316 @override |
| 309 Source internalMapDartUri(String dartUri) { | 317 Source internalMapDartUri(String dartUri) { |
| 310 String libraryName; | 318 String libraryName; |
| 311 String relativePath; | 319 String relativePath; |
| 312 int index = dartUri.indexOf('/'); | 320 int index = dartUri.indexOf('/'); |
| 313 if (index >= 0) { | 321 if (index >= 0) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 338 } | 346 } |
| 339 String filePath = srcPath.replaceAll('/', separator); | 347 String filePath = srcPath.replaceAll('/', separator); |
| 340 try { | 348 try { |
| 341 File file = resourceProvider.getFile(filePath); | 349 File file = resourceProvider.getFile(filePath); |
| 342 return file.createSource(Uri.parse(dartUri)); | 350 return file.createSource(Uri.parse(dartUri)); |
| 343 } on FormatException { | 351 } on FormatException { |
| 344 return null; | 352 return null; |
| 345 } | 353 } |
| 346 } | 354 } |
| 347 | 355 |
| 348 void _loadEmbedderBundle(Folder libFolder) { | |
| 349 File bundleFile = libFolder.parent.getChildAssumingFile('sdk.ds'); | |
| 350 if (bundleFile.exists) { | |
| 351 try { | |
| 352 List<int> bytes = bundleFile.readAsBytesSync(); | |
| 353 _embedderBundle = new PackageBundle.fromBuffer(bytes); | |
| 354 } on FileSystemException {} | |
| 355 } | |
| 356 } | |
| 357 | |
| 358 /** | 356 /** |
| 359 * Install the mapping from [name] to [libDir]/[file]. | 357 * Install the mapping from [name] to [libDir]/[file]. |
| 360 */ | 358 */ |
| 361 void _processEmbeddedLibs(String name, String file, Folder libDir) { | 359 void _processEmbeddedLibs(String name, String file, Folder libDir) { |
| 362 if (!name.startsWith(_DART_COLON_PREFIX)) { | 360 if (!name.startsWith(_DART_COLON_PREFIX)) { |
| 363 // SDK libraries must begin with 'dart:'. | 361 // SDK libraries must begin with 'dart:'. |
| 364 return; | 362 return; |
| 365 } | 363 } |
| 366 String libPath = libDir.canonicalizePath(file); | 364 String libPath = libDir.canonicalizePath(file); |
| 367 _urlMappings[name] = libPath; | 365 _urlMappings[name] = libPath; |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 890 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
| 893 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 891 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
| 894 // If any syntactic errors were found then don't try to visit the AST | 892 // If any syntactic errors were found then don't try to visit the AST |
| 895 // structure. | 893 // structure. |
| 896 if (!errorListener.errorReported) { | 894 if (!errorListener.errorReported) { |
| 897 unit.accept(libraryBuilder); | 895 unit.accept(libraryBuilder); |
| 898 } | 896 } |
| 899 return libraryBuilder.librariesMap; | 897 return libraryBuilder.librariesMap; |
| 900 } | 898 } |
| 901 } | 899 } |
| OLD | NEW |