796d628ab6
* Ensure that we have a .dill file and it has the correct version before we start decoding it in dump.dart. * Throw errors, not strings. Ensure that they have a useful toString(). * Do not print usage except when the command is invoked incorrectly (wrong number of arguments). Once we get into the command it's less likely that it's been invoked incorrectly and more likely that something else has gone wrong. Because these utilities are invoked from other scripts (like the fasta command), printing their usage for problems other than invoking them correctly doesn't match the way that they were invoked and it's confusing. Change-Id: I7832383594d2b3719a0a7a7392ba4685717a79d2 Reviewed-on: https://dart-review.googlesource.com/c/78206 Commit-Queue: Kevin Millikin <kmillikin@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
56 lines
1.8 KiB
Dart
Executable File
56 lines
1.8 KiB
Dart
Executable File
#!/usr/bin/env dart
|
|
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/binary/ast_to_binary.dart';
|
|
import 'package:kernel/binary/limited_ast_to_binary.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:kernel/src/tool/command_line_util.dart';
|
|
|
|
void usage() {
|
|
print("Split a dill file into separate dill files (one library per file).");
|
|
print("Dart internal libraries are not included in the output.");
|
|
print("");
|
|
print("Usage: dart <script> dillFile.dill");
|
|
print("The given argument should be an existing file");
|
|
print("that is valid to load as a dill file.");
|
|
exit(1);
|
|
}
|
|
|
|
main(args) async {
|
|
CommandLineHelper.requireExactlyOneArgument(args, usage,
|
|
requireFileExists: true);
|
|
Component binary = CommandLineHelper.tryLoadDill(args[0]);
|
|
|
|
int part = 1;
|
|
binary.libraries.forEach((lib) => lib.isExternal = true);
|
|
for (int i = 0; i < binary.libraries.length; ++i) {
|
|
Library lib = binary.libraries[i];
|
|
if (lib.name?.startsWith("dart.") == true ||
|
|
lib.name == "builtin" ||
|
|
lib.name == "nativewrappers") continue;
|
|
lib.isExternal = false;
|
|
String path = args[0] + ".part${part++}.dill";
|
|
await writeComponentToFile(binary, path);
|
|
print("Wrote $path");
|
|
lib.isExternal = true;
|
|
}
|
|
}
|
|
|
|
Future<Null> writeComponentToFile(Component component, String path) async {
|
|
File output = new File(path);
|
|
IOSink sink = output.openWrite();
|
|
try {
|
|
BinaryPrinter printer =
|
|
new LimitedBinaryPrinter(sink, (lib) => !lib.isExternal, false);
|
|
printer.writeComponentFile(component);
|
|
} finally {
|
|
await sink.close();
|
|
}
|
|
}
|