aboutsummaryrefslogtreecommitdiff
path: root/src/filetarget.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-18 17:21:02 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-18 17:21:02 +0000
commitdf5286fe3bca619beb4771da1ffa8ace9613e9e5 (patch)
tree0ad268267325c586527b8d36461ab0040e9ae8ec /src/filetarget.cpp
parent4f94dfde7cbe043dfeb11a8712636bac348d3177 (diff)
downloadbuild-df5286fe3bca619beb4771da1ffa8ace9613e9e5.tar.gz
build-df5286fe3bca619beb4771da1ffa8ace9613e9e5.tar.bz2
build-df5286fe3bca619beb4771da1ffa8ace9613e9e5.tar.xz
build-df5286fe3bca619beb4771da1ffa8ace9613e9e5.zip
Gutted, deleted almost all the source, too many changes to keep it around, we'll
see what happens next.
Diffstat (limited to 'src/filetarget.cpp')
-rw-r--r--src/filetarget.cpp178
1 files changed, 0 insertions, 178 deletions
diff --git a/src/filetarget.cpp b/src/filetarget.cpp
deleted file mode 100644
index 0d47e6f..0000000
--- a/src/filetarget.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
1#include <errno.h>
2#include <dirent.h>
3
4#include "perform.h"
5#include "rule.h"
6#include "filetarget.h"
7#include "builder.h" // for BuildException
8#include "viewer.h"
9
10FileTarget::FileTarget( const char *sName ) :
11 Target( sName )
12{
13}
14
15FileTarget::~FileTarget()
16{
17}
18
19void FileTarget::debug()
20{
21 Target::debug();
22 printf(" type: FileTarget\n");
23}
24
25char *gnu_getcwd()
26{
27 size_t size = 1024;
28
29 while (1)
30 {
31 char *buffer = new char[size];
32 if (getcwd (buffer, size) == buffer)
33 return buffer;
34 delete[] buffer;
35 if (errno != ERANGE)
36 return 0;
37 size *= 2;
38 }
39}
40
41void FileTarget::addInputDir( const char *sDir )
42{
43 DIR *dir = opendir( sDir );
44 if( dir == NULL )
45 {
46 throw BuildException( strerror( errno ) );
47 }
48
49 char *cwd = gnu_getcwd();
50 std::string base;//( cwd );
51 //base += "/";
52 base += sDir;
53 base += "/";
54 delete[] cwd;
55
56 struct dirent *de;
57
58 while( (de = readdir( dir )) )
59 {
60 if( de->d_name[0] == '.' || de->d_name[0] == '\0' )
61 continue;
62
63 std::string s( base );
64 s += de->d_name;
65 addInput( s.c_str() );
66 }
67
68 closedir( dir );
69}
70
71//int nNew, nCache;
72
73void FileTarget::check( Builder &bld )
74{
75 //nNew = nCache = 0;
76 Rule *pRule = bld.getRule( sRule );
77
78 std::list<Perform *> perf;
79 std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() );
80 lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() );
81
82 bld.view().beginTarget( getName(), "file", "check", lOutput.size() );
83
84 bld.processRequires( lOutput );
85
86 for( std::list<Perform *>::iterator i = perf.begin();
87 i != perf.end(); i++ )
88 {
89 bld.view().beginPerform( *i );
90 bool bExtraReqs = false;
91 time_t target = getTime( bld, std::string((*i)->getTarget()) );
92 std::list<std::string> *lReqs = bld.getRequires( (*i)->getTarget() );
93 if( lReqs == NULL )
94 {
95 printf("No dependancies: %s\n", (*i)->getTarget() );
96 continue;
97 }
98 time_t rebuild = target;
99 for( std::list<std::string>::iterator j = lReqs->begin();
100 j != lReqs->end(); j++ )
101 {
102 time_t srcfile = getTime( bld, *j );
103 if( srcfile < rebuild )
104 rebuild = srcfile;
105 if( srcfile > target )
106 {
107 bld.view().beginExecute();
108 (*i)->execute( bld );
109 updateTime( (*i)->getTarget() );
110 bld.view().endExecute();
111 break;
112 }
113 if( bExtraReqs == false )
114 {
115 std::list<std::string>::iterator k = j;
116 k++;
117 if( k == lReqs->end() )
118 {
119 bExtraReqs = true;
120 bld.genRequiresFor( (*i)->getTarget(), rebuild );
121 }
122 }
123 }
124 bld.view().endPerform();
125 }
126
127 //printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 );
128
129 bld.view().endTarget();
130}
131
132void FileTarget::clean( Builder &bld )
133{
134 Rule *pRule = bld.getRule( sRule );
135
136 std::list<Perform *> perf;
137 std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() );
138 lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() );
139
140 for( std::list<std::string>::iterator i = lOutput.begin();
141 i != lOutput.end(); i++ )
142 {
143 unlink( (*i).c_str() );
144 }
145}
146
147time_t FileTarget::getTime( Builder &bld, std::string str )
148{
149 std::map<std::string, time_t>::iterator i = mTimes.find( str );
150 if( i != mTimes.end() )
151 {
152 //nCache++;
153 bld.view().beginRequiresCheck( true, str.c_str() );
154 bld.view().endRequiresCheck();
155 return (*i).second;
156 }
157
158 bld.view().beginRequiresCheck( false, str.c_str() );
159 struct stat st;
160 stat( str.c_str(), &st );
161
162 mTimes[str] = st.st_mtime;
163
164 //nNew++;
165
166 bld.view().endRequiresCheck();
167
168 return st.st_mtime;
169}
170
171void FileTarget::updateTime( std::string str )
172{
173 struct stat st;
174 stat( str.c_str(), &st );
175
176 mTimes[str] = st.st_mtime;
177}
178