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  const string& deps_prefix);
32 
33  /// Return true if a mentioned include file is a system path.
34  /// Filtering these out reduces dependency information considerably.
35  static bool IsSystemInclude(string path);
36 
37  /// Parse a line of cl.exe output and return true if it looks like
38  /// it's printing an input filename. This is a heuristic but it appears
39  /// to be the best we can do.
40  /// Exposed for testing.
41  static bool FilterInputFilename(string line);
42 
43  /// Parse the full output of cl, returning the output (if any) that
44  /// should printed.
45  string Parse(const string& output, const string& deps_prefix);
46 
47  set<string> includes_;
48 };
49 
50 /// Wraps a synchronous execution of a CL subprocess.
51 struct CLWrapper {
52  CLWrapper() : env_block_(NULL) {}
53 
54  /// Set the environment block (as suitable for CreateProcess) to be used
55  /// by Run().
56  void SetEnvBlock(void* env_block) { env_block_ = env_block; }
57 
58  /// Start a process and gather its raw output. Returns its exit code.
59  /// Crashes (calls Fatal()) on error.
60  int Run(const string& command, string* output);
61 
62  void* env_block_;
63 };
string EscapeForDepfile(const string &path)
void * env_block_
Definition: msvc_helper.h:62
Visual Studio&#39;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:47
Wraps a synchronous execution of a CL subprocess.
Definition: msvc_helper.h:51
void SetEnvBlock(void *env_block)
Set the environment block (as suitable for CreateProcess) to be used by Run().
Definition: msvc_helper.h:56