Ninja
|
00001 // Copyright 2011 Google Inc. All Rights Reserved. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // http://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 #include <string> 00016 #include <set> 00017 #include <vector> 00018 using namespace std; 00019 00020 string EscapeForDepfile(const string& path); 00021 00022 /// Visual Studio's cl.exe requires some massaging to work with Ninja; 00023 /// for example, it emits include information on stderr in a funny 00024 /// format when building with /showIncludes. This class parses this 00025 /// output. 00026 struct CLParser { 00027 /// Parse a line of cl.exe output and extract /showIncludes info. 00028 /// If a dependency is extracted, returns a nonempty string. 00029 /// Exposed for testing. 00030 static string FilterShowIncludes(const string& line); 00031 00032 /// Return true if a mentioned include file is a system path. 00033 /// Filtering these out reduces dependency information considerably. 00034 static bool IsSystemInclude(string path); 00035 00036 /// Parse a line of cl.exe output and return true if it looks like 00037 /// it's printing an input filename. This is a heuristic but it appears 00038 /// to be the best we can do. 00039 /// Exposed for testing. 00040 static bool FilterInputFilename(string line); 00041 00042 /// Parse the full output of cl, returning the output (if any) that 00043 /// should printed. 00044 string Parse(const string& output); 00045 00046 set<string> includes_; 00047 }; 00048 00049 /// Wraps a synchronous execution of a CL subprocess. 00050 struct CLWrapper { 00051 CLWrapper() : env_block_(NULL) {} 00052 00053 /// Set the environment block (as suitable for CreateProcess) to be used 00054 /// by Run(). 00055 void SetEnvBlock(void* env_block) { env_block_ = env_block; } 00056 00057 /// Start a process and gather its raw output. Returns its exit code. 00058 /// Crashes (calls Fatal()) on error. 00059 int Run(const string& command, string* output); 00060 00061 void* env_block_; 00062 };