Ninja
clparser.h
Go to the documentation of this file.
1 // Copyright 2015 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NINJA_CLPARSER_H_
16 #define NINJA_CLPARSER_H_
17 
18 #include <set>
19 #include <string>
20 
21 /// Visual Studio's cl.exe requires some massaging to work with Ninja;
22 /// for example, it emits include information on stderr in a funny
23 /// format when building with /showIncludes. This class parses this
24 /// output.
25 struct CLParser {
26  /// Parse a line of cl.exe output and extract /showIncludes info.
27  /// If a dependency is extracted, returns a nonempty string.
28  /// Exposed for testing.
29  static std::string FilterShowIncludes(const std::string& line,
30  const std::string& deps_prefix);
31 
32  /// Return true if a mentioned include file is a system path.
33  /// Filtering these out reduces dependency information considerably.
34  static bool IsSystemInclude(std::string path);
35 
36  /// Parse a line of cl.exe output and return true if it looks like
37  /// it's printing an input filename. This is a heuristic but it appears
38  /// to be the best we can do.
39  /// Exposed for testing.
40  static bool FilterInputFilename(std::string line);
41 
42  /// Parse the full output of cl, filling filtered_output with the text that
43  /// should be printed (if any). Returns true on success, or false with err
44  /// filled. output must not be the same object as filtered_object.
45  bool Parse(const std::string& output, const std::string& deps_prefix,
46  std::string* filtered_output, std::string* err);
47 
48  std::set<std::string> includes_;
49 };
50 
51 #endif // NINJA_CLPARSER_H_
Visual Studio's cl.exe requires some massaging to work with Ninja; for example, it emits include info...
Definition: clparser.h:25
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.
Definition: clparser.cc:69
static std::string FilterShowIncludes(const std::string &line, const std::string &deps_prefix)
Parse a line of cl.exe output and extract /showIncludes info.
Definition: clparser.cc:44
static bool IsSystemInclude(std::string path)
Return true if a mentioned include file is a system path.
Definition: clparser.cc:61
std::set< std::string > includes_
Definition: clparser.h:48
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).
Definition: clparser.cc:80