Ninja
msvc_helper.h
Go to the documentation of this file.
1 // Copyright 2011 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 #include <string>
16 #include <set>
17 #include <vector>
18 using namespace std;
19 
20 string EscapeForDepfile(const string& path);
21 
22 /// Visual Studio's cl.exe requires some massaging to work with Ninja;
23 /// for example, it emits include information on stderr in a funny
24 /// format when building with /showIncludes. This class parses this
25 /// output.
26 struct CLParser {
27  /// Parse a line of cl.exe output and extract /showIncludes info.
28  /// If a dependency is extracted, returns a nonempty string.
29  /// Exposed for testing.
30  static string FilterShowIncludes(const string& line);
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(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(string line);
41 
42  /// Parse the full output of cl, returning the output (if any) that
43  /// should printed.
44  string Parse(const string& output);
45 
46  set<string> includes_;
47 };
48 
49 /// Wraps a synchronous execution of a CL subprocess.
50 struct CLWrapper {
51  CLWrapper() : env_block_(NULL) {}
52 
53  /// Set the environment block (as suitable for CreateProcess) to be used
54  /// by Run().
55  void SetEnvBlock(void* env_block) { env_block_ = env_block; }
56 
57  /// Start a process and gather its raw output. Returns its exit code.
58  /// Crashes (calls Fatal()) on error.
59  int Run(const string& command, string* output);
60 
61  void* env_block_;
62 };
string EscapeForDepfile(const string &path)
void * env_block_
Definition: msvc_helper.h:61
Visual Studio's cl.exe requires some massaging to work with Ninja; for example, it emits include info...
Definition: msvc_helper.h:26
set< string > includes_
Definition: msvc_helper.h:46
Wraps a synchronous execution of a CL subprocess.
Definition: msvc_helper.h:50
void SetEnvBlock(void *env_block)
Set the environment block (as suitable for CreateProcess) to be used by Run().
Definition: msvc_helper.h:55