summaryrefslogtreecommitdiff
path: root/tools/aapt/Command.cpp
diff options
context:
space:
mode:
authorJerome Dochez <jedo@google.com>2014-09-26 10:21:21 -0700
committerJerome Dochez <jedo@google.com>2014-10-02 15:43:55 -0700
commit6f1280cf170b358a57ff70341a9f2ad224e5a662 (patch)
tree86e6e7c829b8a112973b4be9b38deeca2ec179d3 /tools/aapt/Command.cpp
parent519006395204ba3eab77ae420d20eb70ebb78af5 (diff)
Added a daemon mode to aapt to receive streams of commands from gradle.
When crunching png, we used to spawn a separate aapt process from java which is slow and resource intensive. Introduced a daemon mode to appt which when invoked with -m parameter will listen from commands on stdin and give report of command execution on stdout. One one command is supported so far : s f1 f2 This command perform a single png crunch, f1 pointing to the input png file to crunch, and f2 pointing to the path for the resulting crunced file. Expected output from the command is "Done" or "Error". Change-Id: Iaf1d865e8d5ee5d36abe39dea6443715865a98d3
Diffstat (limited to 'tools/aapt/Command.cpp')
-rw-r--r--tools/aapt/Command.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 41d8502c5331..1e9e3e20ddf8 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -23,6 +23,10 @@
#include <errno.h>
#include <fcntl.h>
+#include <iostream>
+#include <string>
+#include <sstream>
+
using namespace android;
#ifndef AAPT_VERSION
@@ -2506,6 +2510,37 @@ int doSingleCrunch(Bundle* bundle)
return NO_ERROR;
}
+int runInDaemonMode(Bundle* bundle) {
+ std::cout << "Ready" << std::endl;
+ for (std::string line; std::getline(std::cin, line);) {
+ if (line == "quit") {
+ return NO_ERROR;
+ }
+ std::stringstream ss;
+ ss << line;
+ std::string s;
+
+ std::string command, parameterOne, parameterTwo;
+ std::getline(ss, command, ' ');
+ std::getline(ss, parameterOne, ' ');
+ std::getline(ss, parameterTwo, ' ');
+ if (command[0] == 's') {
+ bundle->setSingleCrunchInputFile(parameterOne.c_str());
+ bundle->setSingleCrunchOutputFile(parameterTwo.c_str());
+ std::cout << "Crunching " << parameterOne << std::endl;
+ if (doSingleCrunch(bundle) != NO_ERROR) {
+ std::cout << "Error" << std::endl;
+ }
+ std::cout << "Done" << std::endl;
+ } else {
+ // in case of invalid command, just bail out.
+ std::cerr << "Unknown command" << std::endl;
+ return -1;
+ }
+ }
+ return -1;
+}
+
char CONSOLE_DATA[2925] = {
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 95, 46, 32, 32, 32, 32, 32, 32, 32, 32, 32,