diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-08-24 15:17:05 -0700 |
---|---|---|
committer | Izabela Orlowska <imorlowska@google.com> | 2017-08-25 14:20:24 +0100 |
commit | 43f6f77a7220b38743fc429c19aa83332afb52b4 (patch) | |
tree | 0a2b87bc59f3bf8d7d211c276d3af44a97cc38dc /tools/aapt2/Main.cpp | |
parent | 1d4be040e06a11d750c364bac856120cbcc03669 (diff) |
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
Change-Id: Ia68122cb77b7dde2292a0fd953e79f02996ac01c
Diffstat (limited to 'tools/aapt2/Main.cpp')
-rw-r--r-- | tools/aapt2/Main.cpp | 32 |
1 files 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::vector<StringPi static void RunDaemon(IDiagnostics* diagnostics) { std::cout << "Ready" << std::endl; - // Run in daemon mode. Each line of input from stdin is treated as a command line argument - // invocation. This means we need to split the line into a vector of args. - for (std::string line; std::getline(std::cin, line);) { - const util::Tokenizer tokenizer = util::Tokenize(line, file::sPathSep); - auto token_iter = tokenizer.begin(); - if (token_iter == tokenizer.end()) { - diagnostics->Error(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<std::string> 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<StringPiece> 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; } |