summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Maennich <maennich@google.com>2021-11-18 16:04:02 +0000
committerMatthias Maennich <maennich@google.com>2021-11-20 14:20:28 +0000
commit7c19921a0f0a125a53d31632d60fab96f8b1007a (patch)
treecde3b85c7ed3cdb35c0cac3d4993eac14844e98a
parentaaa2b3367d653916967586e438d979117db577c3 (diff)
downloadbuild-tools-7c19921a0f0a125a53d31632d60fab96f8b1007a.tar.gz
interceptor: factor out the command line string creation
Bug: 205577427 Signed-off-by: Matthias Maennich <maennich@google.com> Change-Id: Idbecb16660ab055056269184091569264160bcc8
-rw-r--r--interceptor/interceptor.cc19
-rw-r--r--interceptor/interceptor.h2
2 files changed, 12 insertions, 9 deletions
diff --git a/interceptor/interceptor.cc b/interceptor/interceptor.cc
index caadfa0..0a52870 100644
--- a/interceptor/interceptor.cc
+++ b/interceptor/interceptor.cc
@@ -120,17 +120,18 @@ static void dump_vector(std::ostream& os, const char* key, const std::vector<T>&
os << "]";
}
+std::string Command::command() const {
+ std::ostringstream cmd;
+ cmd << program();
+ if (args().size() > 1) cmd << ' ';
+ std::transform(args().cbegin() + 1, args().cend(), std::ostream_iterator<std::string>(cmd, " "),
+ escape);
+ return cmd.str();
+}
+
std::string Command::repr() const {
std::ostringstream os;
- os << R"({"cmd": )";
- {
- std::ostringstream cmd;
- cmd << program();
- if (args().size() > 1) cmd << ' ';
- std::transform(args().cbegin() + 1, args().cend(), std::ostream_iterator<std::string>(cmd, " "),
- escape);
- os << std::quoted(cmd.str());
- }
+ os << R"({"cmd": )" << std::quoted(command());
os << ", ";
dump_vector(os, "in", inputs());
diff --git a/interceptor/interceptor.h b/interceptor/interceptor.h
index d7a38a9..f7ecae7 100644
--- a/interceptor/interceptor.h
+++ b/interceptor/interceptor.h
@@ -59,6 +59,8 @@ class Command {
void analyze();
private:
+ std::string command() const;
+
std::string program_;
std::string cwd_;