aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-02 08:04:19 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-02 08:04:19 +0000
commit4ab0bf24ac9634a12a4a518edecae1d42fa331d9 (patch)
tree75b386895c987bd6f8575140d8c6aa48318ece96 /src
parent062fcfb96c56ecfb69b8c3162ced65b63e863752 (diff)
downloadbuild-4ab0bf24ac9634a12a4a518edecae1d42fa331d9.tar.gz
build-4ab0bf24ac9634a12a4a518edecae1d42fa331d9.tar.bz2
build-4ab0bf24ac9634a12a4a518edecae1d42fa331d9.tar.xz
build-4ab0bf24ac9634a12a4a518edecae1d42fa331d9.zip
Fixed a few minor bugs and added the new viewer system, it allows you to add new
front ends that will display what build is doing in any way you want. cool! So far we have plain and percent, verbose and make are coming, make should be really easy, just print out the commands and nothing else.
Diffstat (limited to 'src')
-rw-r--r--src/action.h5
-rw-r--r--src/builder.cpp13
-rw-r--r--src/builder.h9
-rw-r--r--src/filetarget.cpp31
-rw-r--r--src/filetarget.h2
-rw-r--r--src/main.cpp5
-rw-r--r--src/performcmd.cpp3
-rw-r--r--src/viewer.cpp62
-rw-r--r--src/viewer.h33
-rw-r--r--src/viewerpercent.cpp58
-rw-r--r--src/viewerpercent.h30
-rw-r--r--src/viewerplain.cpp33
-rw-r--r--src/viewerplain.h26
13 files changed, 295 insertions, 15 deletions
diff --git a/src/action.h b/src/action.h
index 7518ed2..ea92efa 100644
--- a/src/action.h
+++ b/src/action.h
@@ -25,6 +25,11 @@ public:
25 return bDefault; 25 return bDefault;
26 } 26 }
27 27
28 int getNumCommands()
29 {
30 return lCommand.size();
31 }
32
28 void debug(); 33 void debug();
29 34
30 void execute( class Builder &bld ); 35 void execute( class Builder &bld );
diff --git a/src/builder.cpp b/src/builder.cpp
index c4f2d12..65ae0c2 100644
--- a/src/builder.cpp
+++ b/src/builder.cpp
@@ -6,14 +6,16 @@
6#include "target.h" 6#include "target.h"
7#include "build.tab.h" 7#include "build.tab.h"
8#include "rule.h" 8#include "rule.h"
9#include "viewer.h"
9 10
10subExceptionDef( BuildException ) 11subExceptionDef( BuildException )
11 12
12Builder::Builder() : 13Builder::Builder( Viewer &rView ) :
13 pDefaultAction( NULL ), 14 pDefaultAction( NULL ),
14 pLastAddedAction( NULL ), 15 pLastAddedAction( NULL ),
15 sTmp(""), 16 sTmp(""),
16 sContext("") 17 sContext(""),
18 rView( rView )
17{ 19{
18} 20}
19 21
@@ -44,7 +46,11 @@ void Builder::build( const char *sAct )
44 pAct = mAction[sAct]; 46 pAct = mAction[sAct];
45 } 47 }
46 48
49 rView.beginAction( sAct, pAct->getNumCommands() );
50
47 pAct->execute( *this ); 51 pAct->execute( *this );
52
53 rView.endAction();
48} 54}
49 55
50void Builder::execute( Action *pAct ) 56void Builder::execute( Action *pAct )
@@ -318,6 +324,8 @@ void Builder::genRequiresFor( const char *sName )
318 { 324 {
319 varmap *revars = regexVars( re ); 325 varmap *revars = regexVars( re );
320 std::string s = varRepl( (*i).second.c_str(), "", revars ); 326 std::string s = varRepl( (*i).second.c_str(), "", revars );
327 rView.beginExtraRequiresCheck( s.c_str() );
328 rView.executeCmd( s.c_str() );
321 FILE *fcmd = popen( s.c_str(), "r" ); 329 FILE *fcmd = popen( s.c_str(), "r" );
322 std::string rhs; 330 std::string rhs;
323 bool bHeader = true; 331 bool bHeader = true;
@@ -366,6 +374,7 @@ void Builder::genRequiresFor( const char *sName )
366 } 374 }
367 pclose( fcmd ); 375 pclose( fcmd );
368 delete revars; 376 delete revars;
377 rView.endExtraRequiresCheck();
369 } 378 }
370 } 379 }
371} 380}
diff --git a/src/builder.h b/src/builder.h
index 296b9d7..82a82c4 100644
--- a/src/builder.h
+++ b/src/builder.h
@@ -16,6 +16,7 @@ class Action;
16class Command; 16class Command;
17class Rule; 17class Rule;
18class Target; 18class Target;
19class Viewer;
19 20
20#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) 21#define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld )
21YY_DECL; 22YY_DECL;
@@ -31,7 +32,7 @@ class Builder
31 }; 32 };
32 33
33public: 34public:
34 Builder(); 35 Builder( Viewer &rView );
35 virtual ~Builder(); 36 virtual ~Builder();
36 37
37 void load( const char *sFN ); 38 void load( const char *sFN );
@@ -43,6 +44,10 @@ public:
43 44
44 std::string file; 45 std::string file;
45 46
47 Viewer &view()
48 {
49 return rView;
50 }
46 void add( Action *pAct ); 51 void add( Action *pAct );
47 void add( Command *pCmd ); 52 void add( Command *pCmd );
48 void add( Rule *pRule ); 53 void add( Rule *pRule );
@@ -145,6 +150,8 @@ private:
145 StaticString sTmp; 150 StaticString sTmp;
146 151
147 bool bReqRegexp; 152 bool bReqRegexp;
153
154 Viewer &rView;
148}; 155};
149 156
150void cleanList( std::list<std::string> &lst ); 157void cleanList( std::list<std::string> &lst );
diff --git a/src/filetarget.cpp b/src/filetarget.cpp
index ca9a39f..e89cd5f 100644
--- a/src/filetarget.cpp
+++ b/src/filetarget.cpp
@@ -5,6 +5,7 @@
5#include "rule.h" 5#include "rule.h"
6#include "filetarget.h" 6#include "filetarget.h"
7#include "builder.h" // for BuildException 7#include "builder.h" // for BuildException
8#include "viewer.h"
8 9
9FileTarget::FileTarget( const char *sName ) : 10FileTarget::FileTarget( const char *sName ) :
10 Target( sName ) 11 Target( sName )
@@ -67,25 +68,27 @@ void FileTarget::addInputDir( const char *sDir )
67 closedir( dir ); 68 closedir( dir );
68} 69}
69 70
70int nNew, nCache; 71//int nNew, nCache;
71 72
72void FileTarget::check( Builder &bld ) 73void FileTarget::check( Builder &bld )
73{ 74{
74 printf("--- %s ---\n", getName() ); 75 //nNew = nCache = 0;
75 nNew = nCache = 0;
76 Rule *pRule = bld.getRule( sRule ); 76 Rule *pRule = bld.getRule( sRule );
77 77
78 std::list<Perform *> perf; 78 std::list<Perform *> perf;
79 std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() ); 79 std::list<std::string> tmp = pRule->execute( bld, lInput, perf, getName() );
80 lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() ); 80 lOutput.insert( lOutput.end(), tmp.begin(), tmp.end() );
81
82 bld.view().beginTarget( getName(), "file", "check", lOutput.size() );
81 83
82 bld.processRequires( lOutput ); 84 bld.processRequires( lOutput );
83 85
84 for( std::list<Perform *>::iterator i = perf.begin(); 86 for( std::list<Perform *>::iterator i = perf.begin();
85 i != perf.end(); i++ ) 87 i != perf.end(); i++ )
86 { 88 {
89 bld.view().beginPerform( *i );
87 bool bExtraReqs = false; 90 bool bExtraReqs = false;
88 time_t target = getTime( std::string((*i)->getTarget()) ); 91 time_t target = getTime( bld, std::string((*i)->getTarget()) );
89 std::list<std::string> *lReqs = bld.getRequires( (*i)->getTarget() ); 92 std::list<std::string> *lReqs = bld.getRequires( (*i)->getTarget() );
90 if( lReqs == NULL ) 93 if( lReqs == NULL )
91 { 94 {
@@ -95,10 +98,12 @@ void FileTarget::check( Builder &bld )
95 for( std::list<std::string>::iterator j = lReqs->begin(); 98 for( std::list<std::string>::iterator j = lReqs->begin();
96 j != lReqs->end(); j++ ) 99 j != lReqs->end(); j++ )
97 { 100 {
98 if( getTime( *j ) > target ) 101 if( getTime( bld, *j ) > target )
99 { 102 {
103 bld.view().beginExecute();
100 (*i)->execute( bld ); 104 (*i)->execute( bld );
101 updateTime( (*i)->getTarget() ); 105 updateTime( (*i)->getTarget() );
106 bld.view().endExecute();
102 break; 107 break;
103 } 108 }
104 if( bExtraReqs == false ) 109 if( bExtraReqs == false )
@@ -112,9 +117,12 @@ void FileTarget::check( Builder &bld )
112 } 117 }
113 } 118 }
114 } 119 }
120 bld.view().endPerform();
115 } 121 }
116 122
117 printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 ); 123 //printf("Cache hits %d, %d new (%f%%)\n", nCache, nNew, nCache/ (double)(nNew+nCache)*100.0 );
124
125 bld.view().endTarget();
118} 126}
119 127
120void FileTarget::clean( Builder &bld ) 128void FileTarget::clean( Builder &bld )
@@ -132,21 +140,26 @@ void FileTarget::clean( Builder &bld )
132 } 140 }
133} 141}
134 142
135time_t FileTarget::getTime( std::string str ) 143time_t FileTarget::getTime( Builder &bld, std::string str )
136{ 144{
137 std::map<std::string, time_t>::iterator i = mTimes.find( str ); 145 std::map<std::string, time_t>::iterator i = mTimes.find( str );
138 if( i != mTimes.end() ) 146 if( i != mTimes.end() )
139 { 147 {
140 nCache++; 148 //nCache++;
149 bld.view().beginRequiresCheck( true, str.c_str() );
150 bld.view().endRequiresCheck();
141 return (*i).second; 151 return (*i).second;
142 } 152 }
143 153
154 bld.view().beginRequiresCheck( false, str.c_str() );
144 struct stat st; 155 struct stat st;
145 stat( str.c_str(), &st ); 156 stat( str.c_str(), &st );
146 157
147 mTimes[str] = st.st_mtime; 158 mTimes[str] = st.st_mtime;
148 159
149 nNew++; 160 //nNew++;
161
162 bld.view().endRequiresCheck();
150 163
151 return st.st_mtime; 164 return st.st_mtime;
152} 165}
diff --git a/src/filetarget.h b/src/filetarget.h
index 856e854..c78c2fd 100644
--- a/src/filetarget.h
+++ b/src/filetarget.h
@@ -21,7 +21,7 @@ public:
21 virtual void check( class Builder &bld ); 21 virtual void check( class Builder &bld );
22 virtual void clean( class Builder &bld ); 22 virtual void clean( class Builder &bld );
23 23
24 time_t getTime( std::string str ); 24 time_t getTime( class Builder &bld, std::string str );
25 void updateTime( std::string str ); 25 void updateTime( std::string str );
26 26
27private: 27private:
diff --git a/src/main.cpp b/src/main.cpp
index ebfb745..132fb18 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,8 +1,11 @@
1#include "builder.h" 1#include "builder.h"
2#include "viewerplain.h"
3#include "viewerpercent.h"
2 4
3int main( int argc, char *argv[] ) 5int main( int argc, char *argv[] )
4{ 6{
5 Builder bld; 7 ViewerPercent p;
8 Builder bld( p );
6 9
7 bld.load("build.conf"); 10 bld.load("build.conf");
8 11
diff --git a/src/performcmd.cpp b/src/performcmd.cpp
index d9b7977..8eafc66 100644
--- a/src/performcmd.cpp
+++ b/src/performcmd.cpp
@@ -1,5 +1,6 @@
1#include "performcmd.h" 1#include "performcmd.h"
2#include "builder.h" 2#include "builder.h"
3#include "viewer.h"
3 4
4PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) : 5PerformCmd::PerformCmd( const char *sCmd, const char *sTarget ) :
5 Perform( sTarget ), 6 Perform( sTarget ),
@@ -13,7 +14,7 @@ PerformCmd::~PerformCmd()
13 14
14void PerformCmd::execute( class Builder &bld ) 15void PerformCmd::execute( class Builder &bld )
15{ 16{
16 printf("%s\n", sCommand.getString() ); 17 bld.view().executeCmd( sCommand );
17 int ret; 18 int ret;
18 if( (ret = system( sCommand.getString() )) != 0 ) 19 if( (ret = system( sCommand.getString() )) != 0 )
19 { 20 {
diff --git a/src/viewer.cpp b/src/viewer.cpp
new file mode 100644
index 0000000..ed6abfb
--- /dev/null
+++ b/src/viewer.cpp
@@ -0,0 +1,62 @@
1#include "viewer.h"
2
3Viewer::Viewer()
4{
5}
6
7Viewer::~Viewer()
8{
9}
10
11void Viewer::beginAction( const char *sName, int nCommands )
12{
13}
14
15void Viewer::endAction()
16{
17}
18
19void Viewer::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms )
20{
21}
22
23void Viewer::endTarget()
24{
25}
26
27void Viewer::beginPerform( Perform *pPerf )
28{
29}
30
31void Viewer::beginRequiresCheck( bool bCached, const char *sName )
32{
33}
34
35void Viewer::endRequiresCheck()
36{
37}
38
39void Viewer::beginExtraRequiresCheck( const char *sCommand )
40{
41}
42
43void Viewer::endExtraRequiresCheck()
44{
45}
46
47void Viewer::beginExecute()
48{
49}
50
51void Viewer::executeCmd( const char *sCmd )
52{
53}
54
55void Viewer::endExecute()
56{
57}
58
59void Viewer::endPerform()
60{
61}
62
diff --git a/src/viewer.h b/src/viewer.h
new file mode 100644
index 0000000..8f2a595
--- /dev/null
+++ b/src/viewer.h
@@ -0,0 +1,33 @@
1#ifndef VIEWER_H
2#define VIEWER_H
3
4#include <stdint.h>
5
6class Perform;
7
8class Viewer
9{
10public:
11 Viewer();
12 virtual ~Viewer();
13
14 virtual void beginAction( const char *sName, int nCommands );
15 virtual void endAction();
16 virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms );
17 virtual void endTarget();
18
19 virtual void beginPerform( Perform *pPerf );
20 virtual void beginRequiresCheck( bool bCached, const char *sName );
21 virtual void endRequiresCheck();
22 virtual void beginExtraRequiresCheck( const char *sCommand );
23 virtual void endExtraRequiresCheck();
24 virtual void beginExecute();
25 virtual void executeCmd( const char *sCmd );
26 virtual void endExecute();
27 virtual void endPerform();
28
29private:
30
31};
32
33#endif
diff --git a/src/viewerpercent.cpp b/src/viewerpercent.cpp
new file mode 100644
index 0000000..0b0344b
--- /dev/null
+++ b/src/viewerpercent.cpp
@@ -0,0 +1,58 @@
1#include "viewerpercent.h"
2#include "perform.h"
3
4ViewerPercent::ViewerPercent() :
5 nWidth( 25 )
6{
7}
8
9ViewerPercent::~ViewerPercent()
10{
11}
12
13void ViewerPercent::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms )
14{
15 printf("--- %s ---\n", sName );
16 nMax = nPerforms;
17 nCount = 0;
18 nLastLen = 0;
19}
20
21void ViewerPercent::endTarget()
22{
23 printf("\n\n");
24}
25
26void ViewerPercent::beginPerform( Perform *pPerf )
27{
28 sTarget = pPerf->getTarget();
29}
30
31void ViewerPercent::beginExecute()
32{
33}
34
35void ViewerPercent::endPerform()
36{
37 nCount++;
38
39 int nPer = (nCount*nWidth)/nMax;
40 fputc( '[', stdout );
41 for( int j = 0; j < nPer; j++ )
42 fputc('=', stdout );
43 for( int j = nPer; j < nWidth; j++ )
44 fputc(' ', stdout );
45 //fputc(']', stdout );
46
47 printf("] %s", sTarget.getString() );
48
49 int diff = nLastLen-sTarget;
50 for( int j = 0; j < diff; j++ )
51 fputc(' ', stdout );
52
53 nLastLen = sTarget;
54
55 fputc('\r', stdout );
56 fflush( stdout );
57}
58
diff --git a/src/viewerpercent.h b/src/viewerpercent.h
new file mode 100644
index 0000000..d575940
--- /dev/null
+++ b/src/viewerpercent.h
@@ -0,0 +1,30 @@
1#ifndef VIEWER_PERCENT_H
2#define VIEWER_PERCENT_H
3
4#include <stdint.h>
5
6#include "viewer.h"
7#include "staticstring.h"
8
9class ViewerPercent : public Viewer
10{
11public:
12 ViewerPercent();
13 virtual ~ViewerPercent();
14
15 virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms );
16 virtual void endTarget();
17
18 virtual void beginPerform( Perform *pPerf );
19 virtual void beginExecute();
20 virtual void endPerform();
21
22private:
23 class StaticString sTarget;
24 int nLastLen;
25 int nWidth;
26 int nMax;
27 int nCount;
28};
29
30#endif
diff --git a/src/viewerplain.cpp b/src/viewerplain.cpp
new file mode 100644
index 0000000..edc5ba8
--- /dev/null
+++ b/src/viewerplain.cpp
@@ -0,0 +1,33 @@
1#include <stdio.h>
2#include "viewerplain.h"
3#include "perform.h"
4
5ViewerPlain::ViewerPlain()
6{
7}
8
9ViewerPlain::~ViewerPlain()
10{
11}
12
13void ViewerPlain::beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms )
14{
15 printf("--- %s ---\n", sName );
16}
17
18void ViewerPlain::endTarget()
19{
20 printf("\n");
21}
22
23void ViewerPlain::beginPerform( Perform *pPerf )
24{
25 sTarget = pPerf->getTarget();
26 printf(" check: %s\n", sTarget.getString() );
27}
28
29void ViewerPlain::beginExecute()
30{
31 printf(" build: %s\n", sTarget.getString() );
32}
33
diff --git a/src/viewerplain.h b/src/viewerplain.h
new file mode 100644
index 0000000..7b4b189
--- /dev/null
+++ b/src/viewerplain.h
@@ -0,0 +1,26 @@
1#ifndef VIEWER_PLAIN_H
2#define VIEWER_PLAIN_H
3
4#include <stdint.h>
5
6#include "viewer.h"
7#include "staticstring.h"
8
9class ViewerPlain : public Viewer
10{
11public:
12 ViewerPlain();
13 virtual ~ViewerPlain();
14
15 virtual void beginTarget( const char *sName, const char *sType, const char *sOperation, int nPerforms );
16 virtual void endTarget();
17
18 virtual void beginPerform( Perform *pPerf );
19 virtual void beginExecute();
20
21private:
22 class StaticString sTarget;
23
24};
25
26#endif