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

Side by Side Diff: lib/src/mirror_loader.dart

Issue 977943005: update mirror-based crawling to only run from relative path libraries that are unreachable by the m… (Closed) Base URL: git@github.com:dart-lang/static-init.git@master
Patch Set: only crawl relative libraries in dartium Created 5 years, 9 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 | « CHANGELOG.md ('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 // 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 library initialize.mirror_loader; 4 library initialize.mirror_loader;
5 5
6 import 'dart:collection' show Queue; 6 import 'dart:collection' show Queue;
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 import 'package:initialize/initialize.dart'; 9 import 'package:initialize/initialize.dart';
10 10
(...skipping 19 matching lines...) Expand all
30 // function will be processed. 30 // function will be processed.
31 final InitializerFilter customFilter; 31 final InitializerFilter customFilter;
32 32
33 InitializationCrawler(this.typeFilter, this.customFilter); 33 InitializationCrawler(this.typeFilter, this.customFilter);
34 34
35 // The primary function in this class, invoke it to crawl and collect all the 35 // The primary function in this class, invoke it to crawl and collect all the
36 // annotations into a queue of init functions. 36 // annotations into a queue of init functions.
37 Queue<Function> run() { 37 Queue<Function> run() {
38 var librariesSeen = new Set<LibraryMirror>(); 38 var librariesSeen = new Set<LibraryMirror>();
39 var queue = new Queue<Function>(); 39 var queue = new Queue<Function>();
40 var libraries = currentMirrorSystem().libraries;
40 41
41 var libraries = currentMirrorSystem().libraries; 42 var trampolineUri = Uri.parse('${_root.uri}\$trampoline');
42 var nonDartOrPackageImports = new List.from(libraries.keys.where( 43 if (libraries.containsKey(trampolineUri)) {
43 (uri) => uri.scheme != 'package' && uri.scheme != 'dart')); 44 // In dartium, process all relative libraries in reverse order of when
Siggi Cherem (dart-lang) 2015/03/04 22:12:25 let's add the TODO here saying that this logic sho
jakemac 2015/03/06 19:06:39 Done.
45 // they were seen.
46 var relativeLibraryUris = new List.from(libraries.keys.where(
47 (uri) => uri.scheme != 'package' && uri.scheme != 'dart'));
44 48
45 for (var import in nonDartOrPackageImports.reversed) { 49 for (var import in relativeLibraryUris.reversed) {
46 // Always load the package: version of a library if available. 50 // Always load the package: version of a library if available for
47 var libToRun; 51 // canonicalization purposes.
48 if (_isHttpStylePackageUrl(import)) { 52 var libToRun;
49 var packageUri = _packageUriFor(import); 53 if (_isHttpStylePackageUrl(import)) {
50 libToRun = libraries[packageUri]; 54 var packageUri = _packageUriFor(import);
55 libToRun = libraries[packageUri];
56 }
57 if (libToRun == null) libToRun = libraries[import];
58
59 // Dartium creates an extra trampoline lib that loads the main dart scri pt
60 // and breaks our ordering, we should skip it.
61 if (librariesSeen.contains(libToRun) ||
62 libToRun.uri.path.endsWith('\$trampoline')) {
63 continue;
64 }
65 _readLibraryDeclarations(libToRun, librariesSeen, queue);
51 } 66 }
52 if (libToRun == null) libToRun = libraries[import]; 67 } else {
53 68 // Not in dartium, just process from the root library.
54 // Dartium creates an extra trampoline lib that loads the main dart script 69 _readLibraryDeclarations(_root, librariesSeen, queue);
55 // and breaks our ordering.
56 if (librariesSeen.contains(libToRun) ||
57 libToRun.uri.path.endsWith('\$trampoline')) {
58 continue;
59 }
60 _readLibraryDeclarations(libToRun, librariesSeen, queue);
61 } 70 }
62 71
63 return queue; 72 return queue;
64 } 73 }
65 74
75 // Crawls all imports that are not dart: or package: urls from a given [root]
76 // and return them as a [Set]
77 Set<LibraryMirror> _visibleRelativeLibraries(
Siggi Cherem (dart-lang) 2015/03/04 22:12:25 we can delete this now I think
jakemac 2015/03/06 19:06:39 Done.
78 LibraryMirror root, [Set<LibraryMirror> libraries]) {
79 if (libraries == null) libraries = new Set<LibraryMirror>();
80 for (var import in root.libraryDependencies) {
81 var library = import.targetLibrary;
82 var scheme = library.uri.scheme;
83 if (scheme == 'dart' || scheme == 'package') continue;
84 if (libraries.contains(library)) continue;
85 libraries.add(library);
86 _visibleRelativeLibraries(library, libraries);
87 }
88 return libraries;
89 }
90
91
66 /// Whether [uri] is an http URI that contains a 'packages' segment, and 92 /// Whether [uri] is an http URI that contains a 'packages' segment, and
67 /// therefore could be converted into a 'package:' URI. 93 /// therefore could be converted into a 'package:' URI.
68 bool _isHttpStylePackageUrl(Uri uri) { 94 bool _isHttpStylePackageUrl(Uri uri) {
69 var uriPath = uri.path; 95 var uriPath = uri.path;
70 return uri.scheme == _root.uri.scheme && 96 return uri.scheme == _root.uri.scheme &&
71 // Don't process cross-domain uris. 97 // Don't process cross-domain uris.
72 uri.authority == _root.uri.authority && 98 uri.authority == _root.uri.authority &&
73 uriPath.endsWith('.dart') && 99 uriPath.endsWith('.dart') &&
74 (uriPath.contains('/packages/') || uriPath.startsWith('packages/')); 100 (uriPath.contains('/packages/') || uriPath.startsWith('packages/'));
75 } 101 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return true; 253 return true;
228 } 254 }
229 } 255 }
230 256
231 final _TOP_LEVEL_FUNCTIONS_ONLY = new UnsupportedError( 257 final _TOP_LEVEL_FUNCTIONS_ONLY = new UnsupportedError(
232 'Only top level methods are supported for initializers'); 258 'Only top level methods are supported for initializers');
233 259
234 final _UNSUPPORTED_DECLARATION = new UnsupportedError( 260 final _UNSUPPORTED_DECLARATION = new UnsupportedError(
235 'Initializers are only supported on libraries, classes, and top level ' 261 'Initializers are only supported on libraries, classes, and top level '
236 'methods'); 262 'methods');
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698