| 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 // Usage: Add the following to your .gclient file (found in the parent | 5 // Usage: Add the following to your .gclient file (found in the parent |
| 6 // of the "dart" in a gclient checkout of the Dart repositor). | 6 // of the "dart" in a gclient checkout of the Dart repositor). |
| 7 // | 7 // |
| 8 // hooks = [ | 8 // hooks = [ |
| 9 // { | 9 // { |
| 10 // "pattern": ".", | 10 // "pattern": ".", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // | 28 // |
| 29 // Where DART_LOCATION is the gclient directory where you found .gclient. | 29 // Where DART_LOCATION is the gclient directory where you found .gclient. |
| 30 | 30 |
| 31 import 'dart:io'; | 31 import 'dart:io'; |
| 32 | 32 |
| 33 import 'dart:mirrors'; | 33 import 'dart:mirrors'; |
| 34 | 34 |
| 35 import 'package:sdk_library_metadata/libraries.dart' | 35 import 'package:sdk_library_metadata/libraries.dart' |
| 36 show libraries, LibraryInfo; | 36 show libraries, LibraryInfo; |
| 37 | 37 |
| 38 import 'package:compiler/src/mirrors/analyze.dart' | 38 import 'package:compiler/src/mirrors/analyze.dart' show analyze; |
| 39 show analyze; | 39 import 'package:compiler/src/mirrors/dart2js_mirrors.dart' show BackDoor; |
| 40 import 'package:compiler/src/mirrors/dart2js_mirrors.dart' | |
| 41 show BackDoor; | |
| 42 import 'package:compiler/src/mirrors/mirrors_util.dart' show nameOf; | 40 import 'package:compiler/src/mirrors/mirrors_util.dart' show nameOf; |
| 43 | 41 |
| 44 import 'package:compiler/src/filenames.dart'; | 42 import 'package:compiler/src/filenames.dart'; |
| 45 import 'package:compiler/src/io/source_file.dart'; | 43 import 'package:compiler/src/io/source_file.dart'; |
| 46 import 'package:compiler/src/source_file_provider.dart'; | 44 import 'package:compiler/src/source_file_provider.dart'; |
| 47 import 'package:compiler/src/util/uri_extras.dart'; | 45 import 'package:compiler/src/util/uri_extras.dart'; |
| 48 | 46 |
| 49 const DART2JS = 'package:compiler/src/dart2js.dart'; | 47 const DART2JS = 'package:compiler/src/dart2js.dart'; |
| 50 const DART2JS_MIRROR = 'package:compiler/src/mirrors/dart2js_mirrors.dart'; | 48 const DART2JS_MIRROR = 'package:compiler/src/mirrors/dart2js_mirrors.dart'; |
| 51 const SDK_ROOT = '../../../../sdk/'; | 49 const SDK_ROOT = '../../../../sdk/'; |
| 52 | 50 |
| 53 bool isPublicDart2jsLibrary(String name) { | 51 bool isPublicDart2jsLibrary(String name) { |
| 54 return !name.startsWith('_') && libraries[name].isDart2jsLibrary; | 52 return !name.startsWith('_') && libraries[name].isDart2jsLibrary; |
| 55 } | 53 } |
| 56 | 54 |
| 57 var handler; | 55 var handler; |
| 58 RandomAccessFile output; | 56 RandomAccessFile output; |
| 59 Uri outputUri; | 57 Uri outputUri; |
| 60 | 58 |
| 61 main(List<String> arguments) { | 59 main(List<String> arguments) { |
| 62 handler = new FormattingDiagnosticHandler() | 60 handler = new FormattingDiagnosticHandler()..throwOnError = true; |
| 63 ..throwOnError = true; | |
| 64 | 61 |
| 65 outputUri = | 62 outputUri = handler.provider.cwd.resolve(nativeToUriPath(arguments.first)); |
| 66 handler.provider.cwd.resolve(nativeToUriPath(arguments.first)); | |
| 67 output = new File(arguments.first).openSync(mode: FileMode.WRITE); | 63 output = new File(arguments.first).openSync(mode: FileMode.WRITE); |
| 68 | 64 |
| 69 Uri myLocation = | 65 Uri myLocation = handler.provider.cwd.resolveUri(Platform.script); |
| 70 handler.provider.cwd.resolveUri(Platform.script); | |
| 71 | 66 |
| 72 List<Uri> uris = <Uri>[]; | 67 List<Uri> uris = <Uri>[]; |
| 73 | 68 |
| 74 if (arguments.length > 1) { | 69 if (arguments.length > 1) { |
| 75 // Compute tags for libraries requested by the user. | 70 // Compute tags for libraries requested by the user. |
| 76 uris.addAll( | 71 uris.addAll( |
| 77 arguments.skip(1).map((argument) => Uri.base.resolve(argument))); | 72 arguments.skip(1).map((argument) => Uri.base.resolve(argument))); |
| 78 } else { | 73 } else { |
| 79 // Compute tags for dart2js itself. | 74 // Compute tags for dart2js itself. |
| 80 uris.add(myLocation.resolve(DART2JS)); | 75 uris.add(myLocation.resolve(DART2JS)); |
| 81 uris.add(myLocation.resolve(DART2JS_MIRROR)); | 76 uris.add(myLocation.resolve(DART2JS_MIRROR)); |
| 82 } | 77 } |
| 83 | 78 |
| 84 // Get the names of public dart2js libraries. | 79 // Get the names of public dart2js libraries. |
| 85 Iterable<String> names = libraries.keys.where(isPublicDart2jsLibrary); | 80 Iterable<String> names = libraries.keys.where(isPublicDart2jsLibrary); |
| 86 | 81 |
| 87 // Prepend "dart:" to the names. | 82 // Prepend "dart:" to the names. |
| 88 uris.addAll(names.map((String name) => Uri.parse('dart:$name'))); | 83 uris.addAll(names.map((String name) => Uri.parse('dart:$name'))); |
| 89 | 84 |
| 90 Uri platformConfigUri = myLocation.resolve(SDK_ROOT) | 85 Uri platformConfigUri = |
| 91 .resolve("lib/dart2js_shared_sdk"); | 86 myLocation.resolve(SDK_ROOT).resolve("lib/dart2js_shared_sdk"); |
| 92 Uri packageRoot = Uri.base.resolve(Platform.packageRoot); | 87 Uri packageRoot = Uri.base.resolve(Platform.packageRoot); |
| 93 | 88 |
| 94 analyze(uris, platformConfigUri, packageRoot, handler.provider, handler) | 89 analyze(uris, platformConfigUri, packageRoot, handler.provider, handler) |
| 95 .then(processMirrors); | 90 .then(processMirrors); |
| 96 } | 91 } |
| 97 | 92 |
| 98 processMirrors(MirrorSystem mirrors) { | 93 processMirrors(MirrorSystem mirrors) { |
| 99 mirrors.libraries.forEach((_, LibraryMirror library) { | 94 mirrors.libraries.forEach((_, LibraryMirror library) { |
| 100 BackDoor.compilationUnitsOf(library).forEach(emitTagsForCompilationUnit); | 95 BackDoor.compilationUnitsOf(library).forEach(emitTagsForCompilationUnit); |
| 101 }); | 96 }); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 int lineEnd = file.lineStarts.length > line_number | 177 int lineEnd = file.lineStarts.length > line_number |
| 183 // Subract 1 to remove trailing newline. | 178 // Subract 1 to remove trailing newline. |
| 184 ? file.lineStarts[line_number] - 1 | 179 ? file.lineStarts[line_number] - 1 |
| 185 : null; | 180 : null; |
| 186 String tag_definition_text = file.slowText().substring(lineStart, lineEnd); | 181 String tag_definition_text = file.slowText().substring(lineStart, lineEnd); |
| 187 | 182 |
| 188 return new Definition(byte_offset, line_number, tag_definition_text); | 183 return new Definition(byte_offset, line_number, tag_definition_text); |
| 189 } | 184 } |
| 190 | 185 |
| 191 void writeOn(StringBuffer buffer, String tagname) { | 186 void writeOn(StringBuffer buffer, String tagname) { |
| 192 buffer.write( | 187 buffer.write('${tag_definition_text}\x7f${tagname}' |
| 193 '${tag_definition_text}\x7f${tagname}' | |
| 194 '\x01${line_number},${byte_offset}\n'); | 188 '\x01${line_number},${byte_offset}\n'); |
| 195 } | 189 } |
| 196 } | 190 } |
| OLD | NEW |