| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:io'; | |
| 6 import 'dart:convert'; | |
| 7 | |
| 8 import 'dart:mirrors'; | |
| 9 | |
| 10 import '../../../libraries.dart' | |
| 11 show LIBRARIES, LibraryInfo; | |
| 12 | |
| 13 import '../../implementation/mirrors/analyze.dart' | |
| 14 show analyze; | |
| 15 import '../../implementation/mirrors/dart2js_mirrors.dart' | |
| 16 show BackDoor; | |
| 17 | |
| 18 import '../../implementation/filenames.dart'; | |
| 19 import '../../implementation/source_file.dart'; | |
| 20 import '../../implementation/source_file_provider.dart'; | |
| 21 import '../../implementation/util/uri_extras.dart'; | |
| 22 | |
| 23 const DART2JS = '../../implementation/dart2js.dart'; | |
| 24 const DART2JS_MIRROR = '../../implementation/mirrors/dart2js_mirror.dart'; | |
| 25 const SDK_ROOT = '../../../../../'; | |
| 26 | |
| 27 bool isPublicDart2jsLibrary(String name) { | |
| 28 return !name.startsWith('_') && LIBRARIES[name].isDart2jsLibrary; | |
| 29 } | |
| 30 | |
| 31 var handler; | |
| 32 RandomAccessFile output; | |
| 33 Uri outputUri; | |
| 34 Uri sdkRoot; | |
| 35 const bool outputJson = | |
| 36 const bool.fromEnvironment('outputJson', defaultValue: false); | |
| 37 | |
| 38 main(List<String> arguments) { | |
| 39 handler = new FormattingDiagnosticHandler() | |
| 40 ..throwOnError = true; | |
| 41 | |
| 42 outputUri = | |
| 43 handler.provider.cwd.resolve(nativeToUriPath(arguments.first)); | |
| 44 output = new File(arguments.first).openSync(mode: FileMode.WRITE); | |
| 45 | |
| 46 Uri myLocation = | |
| 47 handler.provider.cwd.resolveUri(Platform.script); | |
| 48 | |
| 49 sdkRoot = myLocation.resolve(SDK_ROOT).resolve('../'); | |
| 50 | |
| 51 // Get the names of public dart2js libraries. | |
| 52 Iterable<String> names = LIBRARIES.keys.where(isPublicDart2jsLibrary); | |
| 53 | |
| 54 // Turn the names into uris by prepending dart: to them. | |
| 55 List<Uri> uris = names.map((String name) => Uri.parse('dart:$name')).toList(); | |
| 56 | |
| 57 analyze(uris, myLocation.resolve(SDK_ROOT), null, handler.provider, handler) | |
| 58 .then(jsonify); | |
| 59 } | |
| 60 | |
| 61 jsonify(MirrorSystem mirrors) { | |
| 62 var map = <String, String>{}; | |
| 63 | |
| 64 mirrors.libraries.forEach((_, LibraryMirror library) { | |
| 65 BackDoor.compilationUnitsOf(library).forEach((compilationUnit) { | |
| 66 Uri uri = compilationUnit.uri; | |
| 67 String filename = relativize(sdkRoot, uri, false); | |
| 68 SourceFile file = handler.provider.sourceFiles['$uri']; | |
| 69 map['sdk:/$filename'] = file.slowText(); | |
| 70 }); | |
| 71 }); | |
| 72 | |
| 73 LIBRARIES.forEach((name, info) { | |
| 74 var patch = info.dart2jsPatchPath; | |
| 75 if (patch != null) { | |
| 76 Uri uri = sdkRoot.resolve('sdk/lib/$patch'); | |
| 77 String filename = relativize(sdkRoot, uri, false); | |
| 78 SourceFile file = handler.provider.sourceFiles['$uri']; | |
| 79 map['sdk:/$filename'] = file.slowText(); | |
| 80 } | |
| 81 }); | |
| 82 | |
| 83 if (outputJson) { | |
| 84 output.writeStringSync(JSON.encode(map)); | |
| 85 } else { | |
| 86 output.writeStringSync(''' | |
| 87 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 88 // for details. All rights reserved. Use of this source code is governed by a | |
| 89 // BSD-style license that can be found in the LICENSE file. | |
| 90 | |
| 91 // DO NOT EDIT. | |
| 92 // This file is generated by jsonify.dart. | |
| 93 | |
| 94 library dart.sdk_sources; | |
| 95 | |
| 96 const Map<String, String> SDK_SOURCES = const <String, String>'''); | |
| 97 output.writeStringSync(JSON.encode(map).replaceAll(r'$', r'\$')); | |
| 98 output.writeStringSync(';\n'); | |
| 99 } | |
| 100 output.closeSync(); | |
| 101 } | |
| OLD | NEW |