Ninja
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Cleaner Struct Reference

#include <clean.h>

Public Member Functions

int CleanAll (bool generator=false)
 Clean all built files, except for files created by generator rules. More...
 
int cleaned_files_count () const
 
 Cleaner (State *state, const BuildConfig &config)
 Build a cleaner object with a real disk interface. More...
 
 Cleaner (State *state, const BuildConfig &config, DiskInterface *disk_interface)
 Build a cleaner object with the given disk_interface (Useful for testing). More...
 
int CleanRule (const Rule *rule)
 Clean all the file built with the given rule rule. More...
 
int CleanRule (const char *rule)
 Clean the file produced by the given rule. More...
 
int CleanRules (int rule_count, char *rules[])
 Clean the file produced by the given rules. More...
 
int CleanTarget (Node *target)
 Clean the given target and all the file built for it. More...
 
int CleanTarget (const char *target)
 Clean the given target target. More...
 
int CleanTargets (int target_count, char *targets[])
 Clean the given target targets. More...
 
bool IsVerbose () const
 

Private Member Functions

void DoCleanRule (const Rule *rule)
 
void DoCleanTarget (Node *target)
 Helper recursive method for CleanTarget(). More...
 
bool FileExists (const string &path)
 
bool IsAlreadyRemoved (const string &path)
 
void PrintFooter ()
 
void PrintHeader ()
 
void Remove (const string &path)
 Remove the given path file only if it has not been already removed. More...
 
void RemoveEdgeFiles (Edge *edge)
 Remove the depfile and rspfile for an Edge. More...
 
int RemoveFile (const string &path)
 Remove the file path. More...
 
void Report (const string &path)
 
void Reset ()
 

Private Attributes

set< Node * > cleaned_
 
int cleaned_files_count_
 
const BuildConfigconfig_
 
DiskInterfacedisk_interface_
 
set< string > removed_
 
Statestate_
 
int status_
 

Detailed Description

Definition at line 30 of file clean.h.

Constructor & Destructor Documentation

◆ Cleaner() [1/2]

Cleaner::Cleaner ( State state,
const BuildConfig config 
)

Build a cleaner object with a real disk interface.

Definition at line 25 of file clean.cc.

◆ Cleaner() [2/2]

Cleaner::Cleaner ( State state,
const BuildConfig config,
DiskInterface disk_interface 
)

Build a cleaner object with the given disk_interface (Useful for testing).

Definition at line 35 of file clean.cc.

Member Function Documentation

◆ CleanAll()

int Cleaner::CleanAll ( bool  generator = false)

Clean all built files, except for files created by generator rules.

Parameters
generatorIf set, also clean files created by generator rules.
Returns
non-zero if an error occurs.

Definition at line 113 of file clean.cc.

References State::edges_, PrintFooter(), PrintHeader(), Remove(), RemoveEdgeFiles(), Reset(), state_, and status_.

Referenced by TEST_F().

◆ cleaned_files_count()

int Cleaner::cleaned_files_count ( ) const
inline
Returns
the number of file cleaned.

Definition at line 66 of file clean.h.

Referenced by TEST_F().

◆ CleanRule() [1/2]

int Cleaner::CleanRule ( const Rule rule)

Clean all the file built with the given rule rule.

Returns
non-zero if an error occurs.

Definition at line 221 of file clean.cc.

References DoCleanRule(), PrintFooter(), PrintHeader(), Reset(), and status_.

Referenced by CleanRule(), and TEST_F().

◆ CleanRule() [2/2]

int Cleaner::CleanRule ( const char *  rule)

Clean the file produced by the given rule.

Returns
non-zero if an error occurs.

Definition at line 231 of file clean.cc.

References State::bindings_, CleanRule(), Error(), BindingEnv::LookupRule(), Reset(), state_, and status_.

◆ CleanRules()

int Cleaner::CleanRules ( int  rule_count,
char *  rules[] 
)

Clean the file produced by the given rules.

Returns
non-zero if an error occurs.

Definition at line 245 of file clean.cc.

References State::bindings_, DoCleanRule(), Error(), IsVerbose(), BindingEnv::LookupRule(), PrintFooter(), PrintHeader(), Reset(), state_, and status_.

◆ CleanTarget() [1/2]

int Cleaner::CleanTarget ( Node target)

Clean the given target and all the file built for it.

Returns
non-zero if an error occurs.

Definition at line 156 of file clean.cc.

References DoCleanTarget(), PrintFooter(), PrintHeader(), Reset(), and status_.

Referenced by CleanTarget(), and TEST_F().

◆ CleanTarget() [2/2]

int Cleaner::CleanTarget ( const char *  target)

Clean the given target target.

Returns
non-zero if an error occurs.

Definition at line 166 of file clean.cc.

References CleanTarget(), Error(), State::LookupNode(), Reset(), state_, and status_.

◆ CleanTargets()

int Cleaner::CleanTargets ( int  target_count,
char *  targets[] 
)

Clean the given target targets.

Returns
non-zero if an error occurs.

Definition at line 180 of file clean.cc.

References CanonicalizePath(), DoCleanTarget(), Error(), IsVerbose(), State::LookupNode(), PrintFooter(), PrintHeader(), Reset(), state_, and status_.

◆ DoCleanRule()

void Cleaner::DoCleanRule ( const Rule rule)
private

Definition at line 206 of file clean.cc.

References State::edges_, Rule::name(), Remove(), RemoveEdgeFiles(), and state_.

Referenced by CleanRule(), and CleanRules().

◆ DoCleanTarget()

void Cleaner::DoCleanTarget ( Node target)
private

Helper recursive method for CleanTarget().

Definition at line 135 of file clean.cc.

References cleaned_, Node::in_edge(), Node::path(), Remove(), and RemoveEdgeFiles().

Referenced by CleanTarget(), and CleanTargets().

◆ FileExists()

bool Cleaner::FileExists ( const string &  path)
private
Returns
whether the file path exists.

Definition at line 51 of file clean.cc.

References disk_interface_, Error(), and DiskInterface::Stat().

Referenced by Remove().

◆ IsAlreadyRemoved()

bool Cleaner::IsAlreadyRemoved ( const string &  path)
private
Returns
whether the given path has already been removed.

Definition at line 81 of file clean.cc.

References removed_.

Referenced by Remove().

◆ IsVerbose()

bool Cleaner::IsVerbose ( ) const
inline
Returns
whether the cleaner is in verbose mode.

Definition at line 71 of file clean.h.

References BuildConfig::QUIET, and BuildConfig::VERBOSE.

Referenced by CleanRules(), CleanTargets(), PrintHeader(), and Report().

◆ PrintFooter()

void Cleaner::PrintFooter ( )
private

◆ PrintHeader()

void Cleaner::PrintHeader ( )
private

◆ Remove()

void Cleaner::Remove ( const string &  path)
private

Remove the given path file only if it has not been already removed.

Definition at line 65 of file clean.cc.

References config_, BuildConfig::dry_run, FileExists(), IsAlreadyRemoved(), removed_, RemoveFile(), Report(), and status_.

Referenced by CleanAll(), DoCleanRule(), DoCleanTarget(), and RemoveEdgeFiles().

◆ RemoveEdgeFiles()

void Cleaner::RemoveEdgeFiles ( Edge edge)
private

Remove the depfile and rspfile for an Edge.

Definition at line 86 of file clean.cc.

References Edge::GetUnescapedDepfile(), Edge::GetUnescapedRspfile(), and Remove().

Referenced by CleanAll(), DoCleanRule(), and DoCleanTarget().

◆ RemoveFile()

int Cleaner::RemoveFile ( const string &  path)
private

Remove the file path.

Returns
whether the file has been removed.

Definition at line 47 of file clean.cc.

References disk_interface_, and DiskInterface::RemoveFile().

Referenced by Remove().

◆ Report()

void Cleaner::Report ( const string &  path)
private

Definition at line 59 of file clean.cc.

References cleaned_files_count_, and IsVerbose().

Referenced by Remove().

◆ Reset()

void Cleaner::Reset ( )
private

Definition at line 266 of file clean.cc.

References cleaned_, cleaned_files_count_, removed_, and status_.

Referenced by CleanAll(), CleanRule(), CleanRules(), CleanTarget(), and CleanTargets().

Member Data Documentation

◆ cleaned_

set<Node*> Cleaner::cleaned_
private

Definition at line 101 of file clean.h.

Referenced by DoCleanTarget(), and Reset().

◆ cleaned_files_count_

int Cleaner::cleaned_files_count_
private

Definition at line 102 of file clean.h.

Referenced by PrintFooter(), Report(), and Reset().

◆ config_

const BuildConfig& Cleaner::config_
private

Definition at line 99 of file clean.h.

Referenced by PrintFooter(), PrintHeader(), and Remove().

◆ disk_interface_

DiskInterface* Cleaner::disk_interface_
private

Definition at line 103 of file clean.h.

Referenced by FileExists(), and RemoveFile().

◆ removed_

set<string> Cleaner::removed_
private

Definition at line 100 of file clean.h.

Referenced by IsAlreadyRemoved(), Remove(), and Reset().

◆ state_

State* Cleaner::state_
private

Definition at line 98 of file clean.h.

Referenced by CleanAll(), CleanRule(), CleanRules(), CleanTarget(), CleanTargets(), and DoCleanRule().

◆ status_

int Cleaner::status_
private

Definition at line 104 of file clean.h.

Referenced by CleanAll(), CleanRule(), CleanRules(), CleanTarget(), CleanTargets(), Remove(), and Reset().


The documentation for this struct was generated from the following files: