diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2018-09-19 16:57:01 -0700 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2018-10-09 10:51:25 -0700 |
commit | 214846df59118ebe6b75706ea3505a8bb3b2f93c (patch) | |
tree | 993d34675e462c8e535b8b8ee543c7b22328e4fe /tools/aapt2/Main.cpp | |
parent | 99ecc121bca092afb2ace650f879f437c9d3ff9b (diff) |
Created resuable DumpApkCommand and added "badger"
This change refactors the dump commands to inherit from a base
DumpApkCommand and adds a command that prints out an ASCII
image of a badger if the user wrote "badger" instead of
"badging". The command is hidden from the help menu.
Bug: 73535002
Test: manual
Change-Id: I9bdd8a7bbf6a4282c4933e5c478f6d1d8e32d99e
Diffstat (limited to 'tools/aapt2/Main.cpp')
-rw-r--r-- | tools/aapt2/Main.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp index 37013c07ffef..adf85b0ea8e8 100644 --- a/tools/aapt2/Main.cpp +++ b/tools/aapt2/Main.cpp @@ -36,6 +36,7 @@ #include "cmd/Dump.h" #include "cmd/Link.h" #include "cmd/Optimize.h" +#include "io/FileStream.h" #include "util/Files.h" #include "util/Util.h" @@ -68,10 +69,11 @@ class VersionCommand : public Command { /** The main entry point of AAPT. */ class MainCommand : public Command { public: - explicit MainCommand(IDiagnostics* diagnostics) : Command("aapt2"), diagnostics_(diagnostics) { + explicit MainCommand(text::Printer* printer, IDiagnostics* diagnostics) + : Command("aapt2"), diagnostics_(diagnostics) { AddOptionalSubcommand(util::make_unique<CompileCommand>(diagnostics)); AddOptionalSubcommand(util::make_unique<LinkCommand>(diagnostics)); - AddOptionalSubcommand(util::make_unique<DumpCommand>(diagnostics)); + AddOptionalSubcommand(util::make_unique<DumpCommand>(printer, diagnostics)); AddOptionalSubcommand(util::make_unique<DiffCommand>()); AddOptionalSubcommand(util::make_unique<OptimizeCommand>()); AddOptionalSubcommand(util::make_unique<ConvertCommand>()); @@ -101,13 +103,14 @@ class MainCommand : public Command { */ class DaemonCommand : public Command { public: - explicit DaemonCommand(IDiagnostics* diagnostics) : Command("daemon", "m"), - diagnostics_(diagnostics) { + explicit DaemonCommand(io::FileOutputStream* out, IDiagnostics* diagnostics) + : Command("daemon", "m"), out_(out), diagnostics_(diagnostics) { SetDescription("Runs aapt in daemon mode. Each subsequent line is a single parameter to the\n" "command. The end of an invocation is signaled by providing an empty line."); } int Action(const std::vector<std::string>& /* args */) override { + text::Printer printer(out_); std::cout << "Ready" << std::endl; while (true) { @@ -132,7 +135,9 @@ class DaemonCommand : public Command { std::vector<StringPiece> args; args.insert(args.end(), raw_args.begin(), raw_args.end()); - if (MainCommand(diagnostics_).Execute(args, &std::cerr) != 0) { + int result = MainCommand(&printer, diagnostics_).Execute(args, &std::cerr); + out_->Flush(); + if (result != 0) { std::cerr << "Error" << std::endl; } std::cerr << "Done" << std::endl; @@ -143,6 +148,7 @@ class DaemonCommand : public Command { } private: + io::FileOutputStream* out_; IDiagnostics* diagnostics_; }; @@ -159,11 +165,17 @@ int MainImpl(int argc, char** argv) { args.push_back(argv[i]); } - // Add the daemon subcommand here so it cannot be called while executing the daemon + // Use a smaller buffer so that there is less latency for printing to stdout. + constexpr size_t kStdOutBufferSize = 1024u; + aapt::io::FileOutputStream fout(STDOUT_FILENO, kStdOutBufferSize); + aapt::text::Printer printer(&fout); + aapt::StdErrDiagnostics diagnostics; - auto main_command = new aapt::MainCommand(&diagnostics); - main_command->AddOptionalSubcommand(aapt::util::make_unique<aapt::DaemonCommand>(&diagnostics)); + auto main_command = new aapt::MainCommand(&printer, &diagnostics); + // Add the daemon subcommand here so it cannot be called while executing the daemon + main_command->AddOptionalSubcommand( + aapt::util::make_unique<aapt::DaemonCommand>(&fout, &diagnostics)); return main_command->Execute(args, &std::cerr); } |