36 bool EndsWith(
const string& input,
const string& needle) {
37 return (input.size() >= needle.size() &&
38 input.substr(input.size() - needle.size()) == needle);
45 const string& deps_prefix) {
46 const string kDepsPrefixEnglish =
"Note: including file: ";
47 const char* in = line.c_str();
48 const char* end = in + line.size();
49 const string& prefix = deps_prefix.empty() ? kDepsPrefixEnglish : deps_prefix;
50 if (end - in > (
int)prefix.size() &&
51 memcmp(in, prefix.c_str(), (int)prefix.size()) == 0) {
55 return line.substr(in - line.c_str());
62 transform(path.begin(), path.end(), path.begin(),
ToLowerASCII);
64 return (path.find(
"program files") != string::npos ||
65 path.find(
"microsoft visual studio") != string::npos);
70 transform(line.begin(), line.end(), line.begin(),
ToLowerASCII);
72 return EndsWith(line,
".c") ||
73 EndsWith(line,
".cc") ||
74 EndsWith(line,
".cxx") ||
75 EndsWith(line,
".cpp");
80 string* filtered_output,
string* err) {
84 assert(&output != filtered_output);
90 while (start < output.size()) {
91 size_t end = output.find_first_of(
"\r\n", start);
92 if (end == string::npos)
94 string line = output.substr(start, end - start);
96 string include = FilterShowIncludes(line, deps_prefix);
97 if (!include.empty()) {
100 if (!normalizer.
Normalize(include, &normalized, err))
104 normalized = include;
109 if (!IsSystemInclude(normalized))
110 includes_.insert(normalized);
111 }
else if (FilterInputFilename(line)) {
116 filtered_output->append(line);
117 filtered_output->append(
"\n");
120 if (end < output.size() && output[end] ==
'\r')
122 if (end < output.size() && output[end] ==
'\n')
static bool IsSystemInclude(std::string path)
Return true if a mentioned include file is a system path.
bool CanonicalizePath(string *path, uint64_t *slash_bits, string *err)
bool Normalize(const std::string &input, std::string *result, std::string *err) const
Normalize by fixing slashes style, fixing redundant .
#define METRIC_RECORD(name)
The primary interface to metrics.
static bool FilterInputFilename(std::string line)
Parse a line of cl.exe output and return true if it looks like it's printing an input filename...
Utility functions for normalizing include paths on Windows.
char ToLowerASCII(char c)
bool Parse(const std::string &output, const std::string &deps_prefix, std::string *filtered_output, std::string *err)
Parse the full output of cl, filling filtered_output with the text that should be printed (if any)...
unsigned long long uint64_t
static std::string FilterShowIncludes(const std::string &line, const std::string &deps_prefix)
Parse a line of cl.exe output and extract /showIncludes info.