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 #ifndef NINJA_CLEAN_H_ 00016 #define NINJA_CLEAN_H_ 00017 00018 #include <set> 00019 #include <string> 00020 00021 #include "build.h" 00022 00023 using namespace std; 00024 00025 struct State; 00026 struct Node; 00027 struct Rule; 00028 struct DiskInterface; 00029 00030 struct Cleaner { 00031 /// Build a cleaner object with a real disk interface. 00032 Cleaner(State* state, const BuildConfig& config); 00033 00034 /// Build a cleaner object with the given @a disk_interface 00035 /// (Useful for testing). 00036 Cleaner(State* state, 00037 const BuildConfig& config, 00038 DiskInterface* disk_interface); 00039 00040 /// Clean the given @a target and all the file built for it. 00041 /// @return non-zero if an error occurs. 00042 int CleanTarget(Node* target); 00043 /// Clean the given target @a target. 00044 /// @return non-zero if an error occurs. 00045 int CleanTarget(const char* target); 00046 /// Clean the given target @a targets. 00047 /// @return non-zero if an error occurs. 00048 int CleanTargets(int target_count, char* targets[]); 00049 00050 /// Clean all built files, except for files created by generator rules. 00051 /// @param generator If set, also clean files created by generator rules. 00052 /// @return non-zero if an error occurs. 00053 int CleanAll(bool generator = false); 00054 00055 /// Clean all the file built with the given rule @a rule. 00056 /// @return non-zero if an error occurs. 00057 int CleanRule(const Rule* rule); 00058 /// Clean the file produced by the given @a rule. 00059 /// @return non-zero if an error occurs. 00060 int CleanRule(const char* rule); 00061 /// Clean the file produced by the given @a rules. 00062 /// @return non-zero if an error occurs. 00063 int CleanRules(int rule_count, char* rules[]); 00064 00065 /// @return the number of file cleaned. 00066 int cleaned_files_count() const { 00067 return cleaned_files_count_; 00068 } 00069 00070 /// @return whether the cleaner is in verbose mode. 00071 bool IsVerbose() const { 00072 return (config_.verbosity != BuildConfig::QUIET 00073 && (config_.verbosity == BuildConfig::VERBOSE || config_.dry_run)); 00074 } 00075 00076 private: 00077 /// Remove the file @a path. 00078 /// @return whether the file has been removed. 00079 int RemoveFile(const string& path); 00080 /// @returns whether the file @a path exists. 00081 bool FileExists(const string& path); 00082 void Report(const string& path); 00083 00084 /// Remove the given @a path file only if it has not been already removed. 00085 void Remove(const string& path); 00086 /// @return whether the given @a path has already been removed. 00087 bool IsAlreadyRemoved(const string& path); 00088 /// Remove the depfile and rspfile for an Edge. 00089 void RemoveEdgeFiles(Edge* edge); 00090 00091 /// Helper recursive method for CleanTarget(). 00092 void DoCleanTarget(Node* target); 00093 void PrintHeader(); 00094 void PrintFooter(); 00095 void DoCleanRule(const Rule* rule); 00096 void Reset(); 00097 00098 State* state_; 00099 const BuildConfig& config_; 00100 set<string> removed_; 00101 set<Node*> cleaned_; 00102 int cleaned_files_count_; 00103 DiskInterface* disk_interface_; 00104 int status_; 00105 }; 00106 00107 #endif // NINJA_CLEAN_H_