diff options
Diffstat (limited to 'src/filetarget.cpp')
| -rw-r--r-- | src/filetarget.cpp | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/filetarget.cpp b/src/filetarget.cpp index 1880c35..f9367a4 100644 --- a/src/filetarget.cpp +++ b/src/filetarget.cpp | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <errno.h> | 1 | #include <errno.h> |
| 2 | #include <dirent.h> | 2 | #include <dirent.h> |
| 3 | 3 | ||
| 4 | #include "perform.h" | ||
| 4 | #include "rule.h" | 5 | #include "rule.h" |
| 5 | #include "filetarget.h" | 6 | #include "filetarget.h" |
| 6 | #include "builder.h" // for BuildException | 7 | #include "builder.h" // for BuildException |
| @@ -66,8 +67,11 @@ void FileTarget::addInputDir( const char *sDir ) | |||
| 66 | closedir( dir ); | 67 | closedir( dir ); |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 70 | int nNew, nCache; | ||
| 71 | |||
| 69 | void FileTarget::check( Builder &bld ) | 72 | void FileTarget::check( Builder &bld ) |
| 70 | { | 73 | { |
| 74 | nNew = nCache = 0; | ||
| 71 | Rule *pRule = bld.getRule( sRule ); | 75 | Rule *pRule = bld.getRule( sRule ); |
| 72 | 76 | ||
| 73 | std::list<Perform *> perf; | 77 | std::list<Perform *> perf; |
| @@ -79,12 +83,67 @@ void FileTarget::check( Builder &bld ) | |||
| 79 | for( std::list<Perform *>::iterator i = perf.begin(); | 83 | for( std::list<Perform *>::iterator i = perf.begin(); |
| 80 | i != perf.end(); i++ ) | 84 | i != perf.end(); i++ ) |
| 81 | { | 85 | { |
| 82 | std::list<std::string> lReqs = bld.getRequires( (*i)->getTarget() ); | 86 | time_t target = getTime( std::string((*i)->getTarget()) ); |
| 83 | 87 | std::list<std::string> *lReqs = bld.getRequires( (*i)->getTarget() ); | |
| 88 | if( lReqs == NULL ) | ||
| 89 | { | ||
| 90 | printf("No dependancies: %s\n", (*i)->getTarget() ); | ||
| 91 | continue; | ||
| 92 | } | ||
| 93 | for( std::list<std::string>::iterator j = lReqs->begin(); | ||
| 94 | j != lReqs->end(); j++ ) | ||
| 95 | { | ||
| 96 | if( getTime( *j ) > target ) | ||
| 97 | { | ||
| 98 | (*i)->execute( bld ); | ||
| 99 | updateTime( (*i)->getTarget() ); | ||
| 100 | break; | ||
| 101 | } | ||
| 102 | } | ||
| 84 | } | 103 | } |
| 104 | |||
| 105 | printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 ); | ||
| 85 | } | 106 | } |
| 86 | 107 | ||
| 87 | void FileTarget::clean( Builder &bld ) | 108 | void FileTarget::clean( Builder &bld ) |
| 88 | { | 109 | { |
| 110 | Rule *pRule = bld.getRule( sRule ); | ||
| 111 | |||
| 112 | std::list<Perform *> perf; | ||
| 113 | std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() ); | ||
| 114 | lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); | ||
| 115 | |||
| 116 | for( std::list<std::string>::iterator i = lOutput.begin(); | ||
| 117 | i != lOutput.end(); i++ ) | ||
| 118 | { | ||
| 119 | unlink( (*i).c_str() ); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | time_t FileTarget::getTime( std::string str ) | ||
| 124 | { | ||
| 125 | std::map<std::string, time_t>::iterator i = mTimes.find( str ); | ||
| 126 | if( i != mTimes.end() ) | ||
| 127 | { | ||
| 128 | nCache++; | ||
| 129 | return (*i).second; | ||
| 130 | } | ||
| 131 | |||
| 132 | struct stat st; | ||
| 133 | stat( str.c_str(), &st ); | ||
| 134 | |||
| 135 | mTimes[str] = st.st_mtime; | ||
| 136 | |||
| 137 | nNew++; | ||
| 138 | |||
| 139 | return st.st_mtime; | ||
| 140 | } | ||
| 141 | |||
| 142 | void FileTarget::updateTime( std::string str ) | ||
| 143 | { | ||
| 144 | struct stat st; | ||
| 145 | stat( str.c_str(), &st ); | ||
| 146 | |||
| 147 | mTimes[str] = st.st_mtime; | ||
| 89 | } | 148 | } |
| 90 | 149 | ||
