1 // Copyright 2011 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef NINJA_CLEAN_H_
16 #define NINJA_CLEAN_H_
31 /// Build a cleaner object with a real disk interface.
32 Cleaner(State* state, const BuildConfig& config);
34 /// Build a cleaner object with the given @a disk_interface
35 /// (Useful for testing).
37 const BuildConfig& config,
38 DiskInterface* disk_interface);
40 /// Clean the given @a target and all the file built for it.
41 /// @return non-zero if an error occurs.
42 int CleanTarget(Node* target);
43 /// Clean the given target @a target.
44 /// @return non-zero if an error occurs.
45 int CleanTarget(const char* target);
46 /// Clean the given target @a targets.
47 /// @return non-zero if an error occurs.
48 int CleanTargets(int target_count, char* targets[]);
50 /// Clean all built files, except for files created by generator rules.
51 /// @param generator If set, also clean files created by generator rules.
52 /// @return non-zero if an error occurs.
53 int CleanAll(bool generator = false);
55 /// Clean all the file built with the given rule @a rule.
56 /// @return non-zero if an error occurs.
57 int CleanRule(const Rule* rule);
58 /// Clean the file produced by the given @a rule.
59 /// @return non-zero if an error occurs.
60 int CleanRule(const char* rule);
61 /// Clean the file produced by the given @a rules.
62 /// @return non-zero if an error occurs.
63 int CleanRules(int rule_count, char* rules[]);
65 /// @return the number of file cleaned.
66 int cleaned_files_count() const {
67 return cleaned_files_count_;
70 /// @return whether the cleaner is in verbose mode.
71 bool IsVerbose() const {
72 return (config_.verbosity != BuildConfig::QUIET
73 && (config_.verbosity == BuildConfig::VERBOSE || config_.dry_run));
77 /// Remove the file @a path.
78 /// @return whether the file has been removed.
79 int RemoveFile(const string& path);
80 /// @returns whether the file @a path exists.
81 bool FileExists(const string& path);
82 void Report(const string& path);
84 /// Remove the given @a path file only if it has not been already removed.
85 void Remove(const string& path);
86 /// @return whether the given @a path has already been removed.
87 bool IsAlreadyRemoved(const string& path);
88 /// Remove the depfile and rspfile for an Edge.
89 void RemoveEdgeFiles(Edge* edge);
91 /// Helper recursive method for CleanTarget().
92 void DoCleanTarget(Node* target);
95 void DoCleanRule(const Rule* rule);
99 const BuildConfig& config_;
100 set<string> removed_;
102 int cleaned_files_count_;
103 DiskInterface* disk_interface_;
107 #endif // NINJA_CLEAN_H_