| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 library stub_core_library.bin; | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 | |
| 9 import 'package:args/args.dart'; | |
| 10 import 'package:path/path.dart' as p; | |
| 11 | |
| 12 import 'package:stub_core_library/src/utils.dart'; | |
| 13 import 'package:stub_core_library/stub_core_library.dart'; | |
| 14 | |
| 15 /// A map from Dart core library sources to the filenames into which they should | |
| 16 /// be generated. | |
| 17 /// | |
| 18 /// The source paths are URL-formatted and relative to the Dart SDK root. | |
| 19 const CORE_LIBRARIES = const { | |
| 20 'lib/io/io.dart': 'dart_io.dart', | |
| 21 'lib/html/html_common/html_common.dart': 'dart_html_common.dart', | |
| 22 'lib/html/html_common/metadata.dart': 'metadata.dart', | |
| 23 'lib/html/dartium/html_dartium.dart': 'dart_html.dart', | |
| 24 'lib/indexed_db/dartium/indexed_db_dartium.dart': 'dart_indexed_db.dart', | |
| 25 'lib/js/dartium/js_dartium.dart': 'dart_js.dart', | |
| 26 'lib/svg/dartium/svg_dartium.dart': 'dart_svg.dart', | |
| 27 'lib/web_audio/dartium/web_audio_dartium.dart': 'dart_web_audio.dart', | |
| 28 'lib/web_gl/dartium/web_gl_dartium.dart': 'dart_web_gl.dart', | |
| 29 'lib/web_sql/dartium/web_sql_dartium.dart': 'dart_web_sql.dart' | |
| 30 }; | |
| 31 | |
| 32 /// A map from stubbable "dart:" URLs to the names of the stub files they should | |
| 33 /// be replaced with. | |
| 34 const IMPORT_REPLACEMENTS = const { | |
| 35 'dart:io': 'dart_io.dart', | |
| 36 'dart:html_common': 'dart_html_common.dart', | |
| 37 'dart:html': 'dart_html.dart', | |
| 38 'dart:indexed_db': 'dart_indexed_db.dart', | |
| 39 'dart:js': 'dart_js.dart', | |
| 40 'dart:svg': 'dart_svg.dart', | |
| 41 'dart:web_audio': 'dart_web_audio.dart', | |
| 42 'dart:web_gl': 'dart_web_gl.dart', | |
| 43 'dart:web_sql': 'dart_web_sql.dart' | |
| 44 }; | |
| 45 | |
| 46 /// The exit code for a usage error. | |
| 47 const USAGE_ERROR = 64; | |
| 48 | |
| 49 /// The root directory of the SDK. | |
| 50 String get sdkRoot => p.join( | |
| 51 p.dirname(p.fromUri(Platform.script)), '..', '..', '..', 'sdk'); | |
| 52 | |
| 53 /// The argument parser. | |
| 54 final argParser = new ArgParser() | |
| 55 ..addFlag('help', abbr: 'h', help: 'Print this usage information.'); | |
| 56 | |
| 57 /// The usage string. | |
| 58 String get usage => """ | |
| 59 Generate Dart core library stubs. | |
| 60 | |
| 61 Usage: stub_core_libraries.dart <directory> | |
| 62 | |
| 63 ${argParser.getUsage()}"""; | |
| 64 | |
| 65 void main(List<String> arguments) { | |
| 66 var options; | |
| 67 try { | |
| 68 options = argParser.parse(arguments); | |
| 69 } on FormatException catch (e) { | |
| 70 stderr.writeln(e.message); | |
| 71 stderr.writeln(usage); | |
| 72 exitCode = USAGE_ERROR; | |
| 73 return; | |
| 74 } | |
| 75 | |
| 76 if (options['help']) { | |
| 77 print(usage); | |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 var destination = options.rest.isEmpty ? p.current : options.rest.first; | |
| 82 | |
| 83 // Don't allow extra arguments. | |
| 84 if (options.rest.length > 1) { | |
| 85 var unexpected = options.rest.skip(1).map((arg) => '"$arg"'); | |
| 86 var arguments = pluralize("argument", unexpected.length); | |
| 87 stderr.writeln("Unexpected $arguments ${toSentence(unexpected)}."); | |
| 88 stderr.writeln(usage); | |
| 89 exitCode = USAGE_ERROR; | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 new Directory(destination).createSync(recursive: true); | |
| 94 | |
| 95 // TODO(nweiz): Tree-shake these libraries when issue 19896 is fixed. | |
| 96 CORE_LIBRARIES.forEach((path, output) { | |
| 97 path = p.join(sdkRoot, p.fromUri(path)); | |
| 98 new File(p.join(destination, output)) | |
| 99 .writeAsStringSync(stubFile(path, IMPORT_REPLACEMENTS)); | |
| 100 }); | |
| 101 } | |
| OLD | NEW |