From f1a7e04851ecbb707e7e18eace31b5eaf95bcc48 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 24 Aug 2017 15:17:05 -0700 Subject: AAPT2: Change the daemon mode to be line based Accept a set of arguments separated by newlines. This avoids path separator conflicts with the argument format for passing splits. Test: manual Bug: 65645766 Change-Id: Ia68122cb77b7dde2292a0fd953e79f02996ac01c Merged-In: Ia68122cb77b7dde2292a0fd953e79f02996ac01c --- tools/aapt2/Main.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp index 82977cb66421..86f4c42c72a7 100644 --- a/tools/aapt2/Main.cpp +++ b/tools/aapt2/Main.cpp @@ -82,26 +82,32 @@ static int ExecuteCommand(const StringPiece& command, const std::vectorError(DiagMessage() << "no command"); - continue; + // Run in daemon mode. The first line of input is the command. This can be 'quit' which ends + // the daemon mode. Each subsequent line is a single parameter to the command. The end of a + // invocation is signaled by providing an empty line. At any point, an EOF signal or the + // command 'quit' will end the daemon mode. + while (true) { + std::vector raw_args; + for (std::string line; std::getline(std::cin, line) && !line.empty();) { + raw_args.push_back(line); } - const StringPiece command(*token_iter); - if (command == "quit") { + if (!std::cin) { break; } - ++token_iter; + // An empty command does nothing. + if (raw_args.empty()) { + continue; + } + + if (raw_args[0] == "quit") { + break; + } std::vector args; - args.insert(args.end(), token_iter, tokenizer.end()); - int ret = ExecuteCommand(command, args, diagnostics); + args.insert(args.end(), ++raw_args.begin(), raw_args.end()); + int ret = ExecuteCommand(raw_args[0], args, diagnostics); if (ret != 0) { std::cerr << "Error" << std::endl; } -- cgit v1.2.3-59-g8ed1b