OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'dart:async'; |
5 import 'dart:io'; | 6 import 'dart:io'; |
6 import 'dart:convert'; | 7 import 'dart:convert'; |
7 | 8 |
8 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
9 | 10 |
10 import 'package:sdk_library_metadata/libraries.dart' | 11 import 'package:sdk_library_metadata/libraries.dart' |
11 show libraries, LibraryInfo; | 12 show libraries, LibraryInfo; |
12 | 13 |
13 import '../../lib/src/mirrors/analyze.dart' | 14 import '../../lib/src/mirrors/analyze.dart' |
14 show analyze; | 15 show analyze; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 59 |
59 // Turn the names into uris by prepending dart: to them. | 60 // Turn the names into uris by prepending dart: to them. |
60 List<Uri> uris = names.map((String name) => Uri.parse('dart:$name')).toList(); | 61 List<Uri> uris = names.map((String name) => Uri.parse('dart:$name')).toList(); |
61 | 62 |
62 analyze(uris, libraryRoot, packageRoot, handler.provider, handler) | 63 analyze(uris, libraryRoot, packageRoot, handler.provider, handler) |
63 .then(jsonify); | 64 .then(jsonify); |
64 } | 65 } |
65 | 66 |
66 jsonify(MirrorSystem mirrors) { | 67 jsonify(MirrorSystem mirrors) { |
67 var map = <String, String>{}; | 68 var map = <String, String>{}; |
| 69 List<Future> futures = <Future>[]; |
| 70 |
| 71 Future mapUri(Uri uri) { |
| 72 String filename = relativize(sdkRoot, uri, false); |
| 73 return handler.provider.readStringFromUri(uri).then((contents) { |
| 74 map['sdk:/$filename'] = contents; |
| 75 }); |
| 76 } |
68 | 77 |
69 mirrors.libraries.forEach((_, LibraryMirror library) { | 78 mirrors.libraries.forEach((_, LibraryMirror library) { |
70 BackDoor.compilationUnitsOf(library).forEach((compilationUnit) { | 79 BackDoor.compilationUnitsOf(library).forEach((compilationUnit) { |
71 Uri uri = compilationUnit.uri; | 80 futures.add(mapUri(compilationUnit.uri)); |
72 String filename = relativize(sdkRoot, uri, false); | |
73 SourceFile file = handler.provider.sourceFiles[uri]; | |
74 map['sdk:/$filename'] = file.slowText(); | |
75 }); | 81 }); |
76 }); | 82 }); |
77 | 83 |
78 libraries.forEach((name, info) { | 84 libraries.forEach((name, info) { |
79 var patch = info.dart2jsPatchPath; | 85 var patch = info.dart2jsPatchPath; |
80 if (patch != null) { | 86 if (patch != null) { |
81 Uri uri = sdkRoot.resolve('sdk/lib/$patch'); | 87 futures.add(mapUri(sdkRoot.resolve('sdk/lib/$patch'))); |
82 String filename = relativize(sdkRoot, uri, false); | |
83 SourceFile file = handler.provider.sourceFiles[uri]; | |
84 map['sdk:/$filename'] = file.slowText(); | |
85 } | 88 } |
86 }); | 89 }); |
87 | 90 |
88 if (outputJson) { | 91 for (String filename in ["dart_client.platform", |
89 output.writeStringSync(JSON.encode(map)); | 92 "dart_server.platform", |
90 } else { | 93 "dart_shared.platform"]) { |
91 output.writeStringSync(''' | 94 futures.add(mapUri(sdkRoot.resolve('sdk/lib/$filename'))); |
| 95 } |
| 96 |
| 97 Future.wait(futures).then((_) { |
| 98 if (outputJson) { |
| 99 output.writeStringSync(JSON.encode(map)); |
| 100 } else { |
| 101 output.writeStringSync(''' |
92 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 102 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
93 // for details. All rights reserved. Use of this source code is governed by a | 103 // for details. All rights reserved. Use of this source code is governed by a |
94 // BSD-style license that can be found in the LICENSE file. | 104 // BSD-style license that can be found in the LICENSE file. |
95 | 105 |
96 // DO NOT EDIT. | 106 // DO NOT EDIT. |
97 // This file is generated by jsonify.dart. | 107 // This file is generated by jsonify.dart. |
98 | 108 |
99 library dart.sdk_sources; | 109 library dart.sdk_sources; |
100 | 110 |
101 const Map<String, String> SDK_SOURCES = const <String, String>'''); | 111 const Map<String, String> SDK_SOURCES = const <String, String>'''); |
102 output.writeStringSync(JSON.encode(map).replaceAll(r'$', r'\$')); | 112 output.writeStringSync(JSON.encode(map).replaceAll(r'$', r'\$')); |
103 output.writeStringSync(';\n'); | 113 output.writeStringSync(';\n'); |
104 } | 114 } |
105 output.closeSync(); | 115 output.closeSync(); |
| 116 }); |
106 } | 117 } |
OLD | NEW |