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

Side by Side Diff: pkg/analyzer/lib/src/dart/sdk/sdk.dart

Issue 2277003003: Attempt to load sdk.ds from the only embedder. (Closed)
Patch Set: Created 4 years, 3 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/embedder_tests.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.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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 /** 259 /**
260 * An SDK backed by URI mappings derived from an `_embedder.yaml` file. 260 * An SDK backed by URI mappings derived from an `_embedder.yaml` file.
261 */ 261 */
262 class EmbedderSdk extends AbstractDartSdk { 262 class EmbedderSdk extends AbstractDartSdk {
263 static const String _DART_COLON_PREFIX = 'dart:'; 263 static const String _DART_COLON_PREFIX = 'dart:';
264 264
265 static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs'; 265 static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs';
266 final Map<String, String> _urlMappings = new HashMap<String, String>(); 266 final Map<String, String> _urlMappings = new HashMap<String, String>();
267 267
268 PackageBundle _embedderBundle;
269
268 EmbedderSdk( 270 EmbedderSdk(
269 ResourceProvider resourceProvider, Map<Folder, YamlMap> embedderYamls) { 271 ResourceProvider resourceProvider, Map<Folder, YamlMap> embedderYamls) {
270 this.resourceProvider = resourceProvider; 272 this.resourceProvider = resourceProvider;
271 embedderYamls?.forEach(_processEmbedderYaml); 273 embedderYamls?.forEach(_processEmbedderYaml);
274 if (embedderYamls?.length == 1) {
275 Folder libFolder = embedderYamls.keys.first;
276 _loadEmbedderBundle(libFolder);
277 }
272 } 278 }
273 279
274 @override 280 @override
275 // TODO(danrubel) Determine SDK version 281 // TODO(danrubel) Determine SDK version
276 String get sdkVersion => '0'; 282 String get sdkVersion => '0';
277 283
278 /** 284 /**
279 * The url mappings for this SDK. 285 * The url mappings for this SDK.
280 */ 286 */
281 Map<String, String> get urlMappings => _urlMappings; 287 Map<String, String> get urlMappings => _urlMappings;
282 288
283 @override 289 @override
284 PackageBundle getLinkedBundle() => null;
285
286 @override
287 String getRelativePathFromFile(File file) => file.path; 290 String getRelativePathFromFile(File file) => file.path;
288 291
289 @override 292 @override
290 PackageBundle getSummarySdkBundle(bool strongMode) => null; 293 PackageBundle getSummarySdkBundle(bool strongMode) {
294 if (strongMode) {
295 return _embedderBundle;
296 }
297 return null;
298 }
291 299
292 @override 300 @override
293 Source internalMapDartUri(String dartUri) { 301 Source internalMapDartUri(String dartUri) {
294 String libraryName; 302 String libraryName;
295 String relativePath; 303 String relativePath;
296 int index = dartUri.indexOf('/'); 304 int index = dartUri.indexOf('/');
297 if (index >= 0) { 305 if (index >= 0) {
298 libraryName = dartUri.substring(0, index); 306 libraryName = dartUri.substring(0, index);
299 relativePath = dartUri.substring(index + 1); 307 relativePath = dartUri.substring(index + 1);
300 } else { 308 } else {
(...skipping 21 matching lines...) Expand all
322 } 330 }
323 String filePath = srcPath.replaceAll('/', separator); 331 String filePath = srcPath.replaceAll('/', separator);
324 try { 332 try {
325 File file = resourceProvider.getFile(filePath); 333 File file = resourceProvider.getFile(filePath);
326 return file.createSource(parseUriWithException(dartUri)); 334 return file.createSource(parseUriWithException(dartUri));
327 } on URISyntaxException { 335 } on URISyntaxException {
328 return null; 336 return null;
329 } 337 }
330 } 338 }
331 339
340 void _loadEmbedderBundle(Folder libFolder) {
341 File bundleFile = libFolder.parent.getChildAssumingFile('sdk.ds');
342 if (bundleFile.exists) {
343 try {
344 List<int> bytes = bundleFile.readAsBytesSync();
345 _embedderBundle = new PackageBundle.fromBuffer(bytes);
346 } on FileSystemException {}
347 }
348 }
349
332 /** 350 /**
333 * Install the mapping from [name] to [libDir]/[file]. 351 * Install the mapping from [name] to [libDir]/[file].
334 */ 352 */
335 void _processEmbeddedLibs(String name, String file, Folder libDir) { 353 void _processEmbeddedLibs(String name, String file, Folder libDir) {
336 if (!name.startsWith(_DART_COLON_PREFIX)) { 354 if (!name.startsWith(_DART_COLON_PREFIX)) {
337 // SDK libraries must begin with 'dart:'. 355 // SDK libraries must begin with 'dart:'.
338 return; 356 return;
339 } 357 }
340 String libPath = libDir.canonicalizePath(file); 358 String libPath = libDir.canonicalizePath(file);
341 _urlMappings[name] = libPath; 359 _urlMappings[name] = libPath;
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 SdkLibrariesReader_LibraryBuilder libraryBuilder = 862 SdkLibrariesReader_LibraryBuilder libraryBuilder =
845 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); 863 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths);
846 // If any syntactic errors were found then don't try to visit the AST 864 // If any syntactic errors were found then don't try to visit the AST
847 // structure. 865 // structure.
848 if (!errorListener.errorReported) { 866 if (!errorListener.errorReported) {
849 unit.accept(libraryBuilder); 867 unit.accept(libraryBuilder);
850 } 868 }
851 return libraryBuilder.librariesMap; 869 return libraryBuilder.librariesMap;
852 } 870 }
853 } 871 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/embedder_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698