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

Side by Side Diff: dart/pkg/compiler/lib/src/library_loader.dart

Issue 803543002: Resolve libraries against their canonical URI. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42358. Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart2jslib.dart' 8 import 'dart2jslib.dart'
9 show Compiler, 9 show Compiler,
10 CompilerTask, 10 CompilerTask,
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 }); 428 });
429 }).then((_) { 429 }).then((_) {
430 return Future.forEach(libraryDependencies.toList(), (tag) { 430 return Future.forEach(libraryDependencies.toList(), (tag) {
431 return compiler.withCurrentElement(library, () { 431 return compiler.withCurrentElement(library, () {
432 return registerLibraryFromTag(handler, library, tag); 432 return registerLibraryFromTag(handler, library, tag);
433 }); 433 });
434 }); 434 });
435 }); 435 });
436 } 436 }
437 437
438 /// True if the uris are pointing to a library that is shared between dart2js
439 /// and the core libraries. By construction they must be imported into the
440 /// runtime, and, at the same time, into dart2js. This can lead to
441 /// duplicated imports, like in the docgen.
442 // TODO(johnniwinther): is this necessary, or should we change docgen not
443 // to include both libraries (compiler and lib) at the same time?
444 bool _isSharedDart2jsLibrary(Uri uri1, Uri uri2) {
445 bool inJsLibShared(Uri uri) {
446 List<String> segments = uri.pathSegments;
447 if (segments.length < 3) return false;
448 if (segments[segments.length - 2] != 'shared') return false;
449 return (segments[segments.length - 3] == 'js_lib');
450 }
451 return inJsLibShared(uri1) && inJsLibShared(uri2);
452 }
453
454 void checkDuplicatedLibraryName(LibraryElement library) { 438 void checkDuplicatedLibraryName(LibraryElement library) {
439 if (library.isInternalLibrary) return;
455 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; 440 Uri resourceUri = library.entryCompilationUnit.script.resourceUri;
456 LibraryName tag = library.libraryTag; 441 LibraryName tag = library.libraryTag;
457 LibraryElement existing = 442 LibraryElement existing =
458 libraryResourceUriMap.putIfAbsent(resourceUri, () => library); 443 libraryResourceUriMap.putIfAbsent(resourceUri, () => library);
459 if (!identical(existing, library)) { 444 if (!identical(existing, library)) {
460 if (tag != null) { 445 if (tag != null) {
461 compiler.withCurrentElement(library, () { 446 compiler.withCurrentElement(library, () {
462 compiler.reportWarning(tag.name, 447 compiler.reportWarning(tag.name,
463 MessageKind.DUPLICATED_LIBRARY_RESOURCE, 448 MessageKind.DUPLICATED_LIBRARY_RESOURCE,
464 {'libraryName': tag.name, 449 {'libraryName': tag.name,
465 'resourceUri': resourceUri, 450 'resourceUri': resourceUri,
466 'canonicalUri1': library.canonicalUri, 451 'canonicalUri1': library.canonicalUri,
467 'canonicalUri2': existing.canonicalUri}); 452 'canonicalUri2': existing.canonicalUri});
468 }); 453 });
469 } else { 454 } else {
470 compiler.reportHint(library, 455 compiler.reportHint(library,
471 MessageKind.DUPLICATED_RESOURCE, 456 MessageKind.DUPLICATED_RESOURCE,
472 {'resourceUri': resourceUri, 457 {'resourceUri': resourceUri,
473 'canonicalUri1': library.canonicalUri, 458 'canonicalUri1': library.canonicalUri,
474 'canonicalUri2': existing.canonicalUri}); 459 'canonicalUri2': existing.canonicalUri});
475 } 460 }
476 } else if (tag != null) { 461 } else if (tag != null) {
477 String name = library.getLibraryOrScriptName(); 462 String name = library.getLibraryOrScriptName();
478 existing = libraryNames.putIfAbsent(name, () => library); 463 existing = libraryNames.putIfAbsent(name, () => library);
479 if (!identical(existing, library) && 464 if (!identical(existing, library)) {
480 !_isSharedDart2jsLibrary(resourceUri, existing.canonicalUri)) {
481 compiler.withCurrentElement(library, () { 465 compiler.withCurrentElement(library, () {
482 compiler.reportWarning(tag.name, 466 compiler.reportWarning(tag.name,
483 MessageKind.DUPLICATED_LIBRARY_NAME, 467 MessageKind.DUPLICATED_LIBRARY_NAME,
484 {'libraryName': name}); 468 {'libraryName': name});
485 }); 469 });
486 compiler.withCurrentElement(existing, () { 470 compiler.withCurrentElement(existing, () {
487 compiler.reportWarning(existing.libraryTag.name, 471 compiler.reportWarning(existing.libraryTag.name,
488 MessageKind.DUPLICATED_LIBRARY_NAME, 472 MessageKind.DUPLICATED_LIBRARY_NAME,
489 {'libraryName': name}); 473 {'libraryName': name});
490 }); 474 });
(...skipping 27 matching lines...) Expand all
518 } 502 }
519 503
520 /** 504 /**
521 * Handle an import/export tag by loading the referenced library and 505 * Handle an import/export tag by loading the referenced library and
522 * registering its dependency in [handler] for the computation of the import/ 506 * registering its dependency in [handler] for the computation of the import/
523 * export scope. 507 * export scope.
524 */ 508 */
525 Future registerLibraryFromTag(LibraryDependencyHandler handler, 509 Future registerLibraryFromTag(LibraryDependencyHandler handler,
526 LibraryElement library, 510 LibraryElement library,
527 LibraryDependency tag) { 511 LibraryDependency tag) {
528 Uri base = library.entryCompilationUnit.script.readableUri; 512 Uri base = library.canonicalUri;
529 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); 513 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString());
530 return createLibrary(handler, library, resolvedUri, tag.uri) 514 return createLibrary(handler, library, resolvedUri, tag.uri)
531 .then((LibraryElement loadedLibrary) { 515 .then((LibraryElement loadedLibrary) {
532 if (loadedLibrary == null) return; 516 if (loadedLibrary == null) return;
533 compiler.withCurrentElement(library, () { 517 compiler.withCurrentElement(library, () {
534 handler.registerDependency(library, tag, loadedLibrary); 518 handler.registerDependency(library, tag, loadedLibrary);
535 }); 519 });
536 }); 520 });
537 } 521 }
538 522
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 } 1141 }
1158 suffixes.add(const Link<Uri>().prepend(canonicalUri)); 1142 suffixes.add(const Link<Uri>().prepend(canonicalUri));
1159 } 1143 }
1160 suffixChainMap[library] = suffixes; 1144 suffixChainMap[library] = suffixes;
1161 return; 1145 return;
1162 } 1146 }
1163 1147
1164 computeSuffixes(rootLibrary, const Link<Uri>()); 1148 computeSuffixes(rootLibrary, const Link<Uri>());
1165 } 1149 }
1166 } 1150 }
OLDNEW
« no previous file with comments | « dart/pkg/compiler/lib/src/apiimpl.dart ('k') | dart/pkg/compiler/lib/src/scanner/scanner_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698