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") ||
76 EndsWith(line,
".c++");
81 string* filtered_output,
string* err) {
85 assert(&output != filtered_output);
87 bool seen_show_includes =
false;
92 while (start < output.size()) {
93 size_t end = output.find_first_of(
"\r\n", start);
94 if (end == string::npos)
96 string line = output.substr(start, end - start);
98 string include = FilterShowIncludes(line, deps_prefix);
99 if (!include.empty()) {
100 seen_show_includes =
true;
103 if (!normalizer.
Normalize(include, &normalized, err))
107 normalized = include;
111 if (!IsSystemInclude(normalized))
112 includes_.insert(normalized);
113 }
else if (!seen_show_includes && FilterInputFilename(line)) {
118 filtered_output->append(line);
119 filtered_output->append(
"\n");
122 if (end < output.size() && output[end] ==
'\r')
124 if (end < output.size() && output[end] ==
'\n')
#define METRIC_RECORD(name)
The primary interface to metrics.
char ToLowerASCII(char c)
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.
static std::string FilterShowIncludes(const std::string &line, const std::string &deps_prefix)
Parse a line of cl.exe output and extract /showIncludes info.
static bool IsSystemInclude(std::string path)
Return true if a mentioned include file is a system path.
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).
Utility functions for normalizing include paths on Windows.
bool Normalize(const std::string &input, std::string *result, std::string *err) const
Normalize by fixing slashes style, fixing redundant .
void CanonicalizePath(string *path, uint64_t *slash_bits)
unsigned long long uint64_t