aboutsummaryrefslogtreecommitdiff
path: root/src/filetarget.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-01 06:27:43 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-01 06:27:43 +0000
commit46a3cfdd7b2a77a308a6ac3fbca3b675c4f44fe7 (patch)
tree795ace6809cbba6019f5517b345a5ab20fed5b9a /src/filetarget.cpp
parent935bc7d5223883d87f58a6798f4a0ade7df95afc (diff)
downloadbuild-46a3cfdd7b2a77a308a6ac3fbca3b675c4f44fe7.tar.gz
build-46a3cfdd7b2a77a308a6ac3fbca3b675c4f44fe7.tar.bz2
build-46a3cfdd7b2a77a308a6ac3fbca3b675c4f44fe7.tar.xz
build-46a3cfdd7b2a77a308a6ac3fbca3b675c4f44fe7.zip
It builds fine, and can build other things as well, like squirrelmud, and clean.
I need to fix the dependancy tracking so that it will only check if it needs to, sort of like pymake. And does each file as it gets to it.
Diffstat (limited to 'src/filetarget.cpp')
-rw-r--r--src/filetarget.cpp63
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
70int nNew, nCache;
71
69void FileTarget::check( Builder &bld ) 72void 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
87void FileTarget::clean( Builder &bld ) 108void 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
123time_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
142void 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