aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-01-06 17:05:45 +0000
committerMike Buland <eichlan@xagasoft.com>2010-01-06 17:05:45 +0000
commit3c7e81d3baba06cb1bf37de84aeaa6cad277652a (patch)
tree166e9309a0be01e6b4e8591434372e4817a65d76 /src
parente809677b1d5a02b93a0be7a9fce8a6b67d0d91be (diff)
downloadbuild-3c7e81d3baba06cb1bf37de84aeaa6cad277652a.tar.gz
build-3c7e81d3baba06cb1bf37de84aeaa6cad277652a.tar.bz2
build-3c7e81d3baba06cb1bf37de84aeaa6cad277652a.tar.xz
build-3c7e81d3baba06cb1bf37de84aeaa6cad277652a.zip
Wow, ok, well, I added some more error handling, that's positive, also switched
conditions and functions to a plugger system like views, and all of them now load builtin and external plugins flawlessly. It's actually a lot of fun. I also added the example/test plugin condition "random" it randomly builds targets...it's not really useful...
Diffstat (limited to 'src')
-rw-r--r--src/conditionalways.cpp4
-rw-r--r--src/conditionfileexists.cpp41
-rw-r--r--src/conditionfileexists.h16
-rw-r--r--src/conditionfiletime.cpp4
-rw-r--r--src/conditionnever.cpp4
-rw-r--r--src/conditionplugger.cpp43
-rw-r--r--src/conditionplugger.h17
-rw-r--r--src/context.cpp48
-rw-r--r--src/functiondirname.cpp4
-rw-r--r--src/functiondirs.cpp4
-rw-r--r--src/functionexecute.cpp4
-rw-r--r--src/functionexists.cpp4
-rw-r--r--src/functionfilename.cpp4
-rw-r--r--src/functionfiles.cpp4
-rw-r--r--src/functiongetmakedeps.cpp4
-rw-r--r--src/functionmatches.cpp4
-rw-r--r--src/functionplugger.cpp59
-rw-r--r--src/functionplugger.h17
-rw-r--r--src/functionreplace.cpp4
-rw-r--r--src/functiontargets.cpp4
-rw-r--r--src/functiontostring.cpp4
-rw-r--r--src/functionunlink.cpp4
-rw-r--r--src/main.cpp40
-rw-r--r--src/plugins/pluginConditionRandom.cpp31
-rw-r--r--src/profile.cpp25
-rw-r--r--src/viewplugger.cpp24
26 files changed, 374 insertions, 47 deletions
diff --git a/src/conditionalways.cpp b/src/conditionalways.cpp
index 077b5b5..8c245f4 100644
--- a/src/conditionalways.cpp
+++ b/src/conditionalways.cpp
@@ -1,6 +1,10 @@
1#include "conditionalways.h" 1#include "conditionalways.h"
2#include "target.h" 2#include "target.h"
3 3
4#include <bu/plugger.h>
5PluginInterface3( pluginConditionAlways, always, ConditionAlways, Condition,
6 "Mike Buland", 0, 1 );
7
4ConditionAlways::ConditionAlways() 8ConditionAlways::ConditionAlways()
5{ 9{
6} 10}
diff --git a/src/conditionfileexists.cpp b/src/conditionfileexists.cpp
new file mode 100644
index 0000000..0585351
--- /dev/null
+++ b/src/conditionfileexists.cpp
@@ -0,0 +1,41 @@
1#include "conditionfileexists.h"
2#include "target.h"
3
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <unistd.h>
7
8#include <bu/sio.h>
9using namespace Bu;
10
11#include <bu/plugger.h>
12PluginInterface3( pluginConditionFileExists, fileExists, ConditionFileExists,
13 Condition, "Mike Buland", 0, 1 );
14
15ConditionFileExists::ConditionFileExists()
16{
17}
18
19ConditionFileExists::~ConditionFileExists()
20{
21}
22
23bool ConditionFileExists::shouldExec( class Runner &r, Target &rTarget )
24{
25 for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ )
26 {
27 // If any input exists, then return true, we should exec.
28 if( !access( (*j).getStr(), F_OK ) )
29 {
30 return true;
31 }
32 }
33
34 return false;
35}
36
37Condition *ConditionFileExists::clone()
38{
39 return new ConditionFileExists();
40}
41
diff --git a/src/conditionfileexists.h b/src/conditionfileexists.h
new file mode 100644
index 0000000..6f30297
--- /dev/null
+++ b/src/conditionfileexists.h
@@ -0,0 +1,16 @@
1#ifndef CONDITION_FILE_EXISTS_H
2#define CONDITION_FILE_EXISTS_H
3
4#include "condition.h"
5
6class ConditionFileExists : public Condition
7{
8public:
9 ConditionFileExists();
10 virtual ~ConditionFileExists();
11
12 virtual bool shouldExec( class Runner &r, class Target &rTarget );
13 virtual Condition *clone();
14};
15
16#endif
diff --git a/src/conditionfiletime.cpp b/src/conditionfiletime.cpp
index 148ffac..43df53b 100644
--- a/src/conditionfiletime.cpp
+++ b/src/conditionfiletime.cpp
@@ -8,6 +8,10 @@
8#include <bu/sio.h> 8#include <bu/sio.h>
9using namespace Bu; 9using namespace Bu;
10 10
11#include <bu/plugger.h>
12PluginInterface3( pluginConditionFileTime, fileTime, ConditionFileTime,
13 Condition, "Mike Buland", 0, 1 );
14
11ConditionFileTime::ConditionFileTime() 15ConditionFileTime::ConditionFileTime()
12{ 16{
13} 17}
diff --git a/src/conditionnever.cpp b/src/conditionnever.cpp
index 1ab4375..f99feb6 100644
--- a/src/conditionnever.cpp
+++ b/src/conditionnever.cpp
@@ -1,6 +1,10 @@
1#include "conditionnever.h" 1#include "conditionnever.h"
2#include "target.h" 2#include "target.h"
3 3
4#include <bu/plugger.h>
5PluginInterface3( pluginConditionNever, never, ConditionNever, Condition,
6 "Mike Buland", 0, 1 );
7
4ConditionNever::ConditionNever() 8ConditionNever::ConditionNever()
5{ 9{
6} 10}
diff --git a/src/conditionplugger.cpp b/src/conditionplugger.cpp
new file mode 100644
index 0000000..3edfa00
--- /dev/null
+++ b/src/conditionplugger.cpp
@@ -0,0 +1,43 @@
1#include "conditionplugger.h"
2
3#include <sys/types.h>
4#include <dirent.h>
5
6extern Bu::PluginInfo pluginConditionAlways;
7extern Bu::PluginInfo pluginConditionNever;
8extern Bu::PluginInfo pluginConditionFileTime;
9extern Bu::PluginInfo pluginConditionFileExists;
10
11ConditionPlugger::ConditionPlugger()
12{
13 registerBuiltinPlugin( &pluginConditionAlways );
14 registerBuiltinPlugin( &pluginConditionNever );
15 registerBuiltinPlugin( &pluginConditionFileTime );
16 registerBuiltinPlugin( &pluginConditionFileExists );
17
18 DIR *dir = opendir("/usr/lib/build");
19 if( !dir )
20 return;
21 struct dirent *de;
22 while( (de = readdir( dir )) )
23 {
24 if( strncmp("pluginCondition", de->d_name, 15 ) )
25 continue;
26
27 Bu::FString sFile("/usr/lib/build/");
28 sFile += de->d_name;
29 char *s = de->d_name;
30 for(; *s && *s != '.'; s++ ) { }
31 registerExternalPlugin(
32 sFile,
33 Bu::FString( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name )
34 );
35 }
36
37 closedir( dir );
38}
39
40ConditionPlugger::~ConditionPlugger()
41{
42}
43
diff --git a/src/conditionplugger.h b/src/conditionplugger.h
new file mode 100644
index 0000000..71fa7e3
--- /dev/null
+++ b/src/conditionplugger.h
@@ -0,0 +1,17 @@
1#ifndef CONDITION_PLUGGER_H
2#define CONDITION_PLUGGER_H
3
4#include "condition.h"
5#include <bu/plugger.h>
6#include <bu/singleton.h>
7
8class ConditionPlugger : public Bu::Plugger<Condition>,
9 public Bu::Singleton<ConditionPlugger>
10{
11friend class Bu::Singleton<ConditionPlugger>;
12private:
13 ConditionPlugger();
14 virtual ~ConditionPlugger();
15};
16
17#endif
diff --git a/src/context.cpp b/src/context.cpp
index efe8098..64b3bd0 100644
--- a/src/context.cpp
+++ b/src/context.cpp
@@ -7,18 +7,7 @@
7#include "profile.h" 7#include "profile.h"
8#include "view.h" 8#include "view.h"
9 9
10#include "functionreplace.h" 10#include "functionplugger.h"
11#include "functionexists.h"
12#include "functionfiles.h"
13#include "functionexecute.h"
14#include "functionmatches.h"
15#include "functiontostring.h"
16#include "functionunlink.h"
17#include "functiontargets.h"
18#include "functiondirs.h"
19#include "functiongetmakedeps.h"
20#include "functionfilename.h"
21#include "functiondirname.h"
22 11
23#include <bu/process.h> 12#include <bu/process.h>
24#include <bu/sio.h> 13#include <bu/sio.h>
@@ -27,18 +16,6 @@ using namespace Bu;
27Context::Context() : 16Context::Context() :
28 pView( NULL ) 17 pView( NULL )
29{ 18{
30 addFunction( new FunctionReplace() );
31 addFunction( new FunctionExists() );
32 addFunction( new FunctionFiles() );
33 addFunction( new FunctionExecute() );
34 addFunction( new FunctionMatches() );
35 addFunction( new FunctionToString() );
36 addFunction( new FunctionUnlink() );
37 addFunction( new FunctionTargets() );
38 addFunction( new FunctionDirs() );
39 addFunction( new FunctionGetMakeDeps() );
40 addFunction( new FunctionFileName() );
41 addFunction( new FunctionDirName() );
42 pushScope(); 19 pushScope();
43} 20}
44 21
@@ -178,7 +155,16 @@ Variable Context::call( const Bu::FString &sName, Variable &input,
178{ 155{
179 if( !hFunction.has( sName ) ) 156 if( !hFunction.has( sName ) )
180 { 157 {
181 throw Bu::ExceptionBase("Unknown function called: %s", sName.getStr() ); 158 // Try to load the function...
159 try
160 {
161 addFunction( FunctionPlugger::getInstance().instantiate( sName ) );
162 }
163 catch(...)
164 {
165 throw Bu::ExceptionBase("Unknown function called: %s",
166 sName.getStr() );
167 }
182 } 168 }
183 return hFunction.get( sName )->call( input, lParams ); 169 return hFunction.get( sName )->call( input, lParams );
184} 170}
@@ -290,8 +276,16 @@ void Context::buildTargetTree( Runner &r )
290 continue; 276 continue;
291 277
292 StrList lNewIns; // The new "changed" inputs for this target 278 StrList lNewIns; // The new "changed" inputs for this target
293 279
294 Rule *pMaster = hRule.get( (*i)->getRule() ); 280 Rule *pMaster;
281 try
282 {
283 pMaster = hRule.get( (*i)->getRule() );
284 }
285 catch( Bu::HashException &e )
286 {
287 throw Bu::ExceptionBase("Unknown rule: %s", (*i)->getRule().getStr() );
288 }
295 289
296 for( StrList::const_iterator j = (*i)->getInputList().begin(); j; j++ ) 290 for( StrList::const_iterator j = (*i)->getInputList().begin(); j; j++ )
297 { 291 {
diff --git a/src/functiondirname.cpp b/src/functiondirname.cpp
index e8b728b..f72d181 100644
--- a/src/functiondirname.cpp
+++ b/src/functiondirname.cpp
@@ -1,5 +1,9 @@
1#include "functiondirname.h" 1#include "functiondirname.h"
2 2
3#include <bu/plugger.h>
4PluginInterface3( pluginFunctionDirName, dirName, FunctionDirName, Function,
5 "Mike Buland", 0, 1 );
6
3FunctionDirName::FunctionDirName() 7FunctionDirName::FunctionDirName()
4{ 8{
5} 9}
diff --git a/src/functiondirs.cpp b/src/functiondirs.cpp
index fb64ef3..dee3c4c 100644
--- a/src/functiondirs.cpp
+++ b/src/functiondirs.cpp
@@ -5,6 +5,10 @@
5#include <glob.h> 5#include <glob.h>
6#include <unistd.h> 6#include <unistd.h>
7 7
8#include <bu/plugger.h>
9PluginInterface3( pluginFunctionDirs, dirs, FunctionDirs, Function,
10 "Mike Buland", 0, 1 );
11
8FunctionDirs::FunctionDirs() 12FunctionDirs::FunctionDirs()
9{ 13{
10} 14}
diff --git a/src/functionexecute.cpp b/src/functionexecute.cpp
index 619d2c2..f692036 100644
--- a/src/functionexecute.cpp
+++ b/src/functionexecute.cpp
@@ -6,6 +6,10 @@
6#include <bu/process.h> 6#include <bu/process.h>
7using namespace Bu; 7using namespace Bu;
8 8
9#include <bu/plugger.h>
10PluginInterface3( pluginFunctionExecute, execute, FunctionExecute, Function,
11 "Mike Buland", 0, 1 );
12
9FunctionExecute::FunctionExecute() 13FunctionExecute::FunctionExecute()
10{ 14{
11} 15}
diff --git a/src/functionexists.cpp b/src/functionexists.cpp
index d2aa9e9..2207f84 100644
--- a/src/functionexists.cpp
+++ b/src/functionexists.cpp
@@ -2,6 +2,10 @@
2 2
3#include <unistd.h> 3#include <unistd.h>
4 4
5#include <bu/plugger.h>
6PluginInterface3( pluginFunctionExists, exists, FunctionExists, Function,
7 "Mike Buland", 0, 1 );
8
5FunctionExists::FunctionExists() 9FunctionExists::FunctionExists()
6{ 10{
7} 11}
diff --git a/src/functionfilename.cpp b/src/functionfilename.cpp
index 21a4655..57aada9 100644
--- a/src/functionfilename.cpp
+++ b/src/functionfilename.cpp
@@ -1,5 +1,9 @@
1#include "functionfilename.h" 1#include "functionfilename.h"
2 2
3#include <bu/plugger.h>
4PluginInterface3( pluginFunctionFileName, fileName, FunctionFileName, Function,
5 "Mike Buland", 0, 1 );
6
3FunctionFileName::FunctionFileName() 7FunctionFileName::FunctionFileName()
4{ 8{
5} 9}
diff --git a/src/functionfiles.cpp b/src/functionfiles.cpp
index e708d45..e0f8268 100644
--- a/src/functionfiles.cpp
+++ b/src/functionfiles.cpp
@@ -5,6 +5,10 @@
5#include <glob.h> 5#include <glob.h>
6#include <unistd.h> 6#include <unistd.h>
7 7
8#include <bu/plugger.h>
9PluginInterface3( pluginFunctionFiles, files, FunctionFiles, Function,
10 "Mike Buland", 0, 1 );
11
8FunctionFiles::FunctionFiles() 12FunctionFiles::FunctionFiles()
9{ 13{
10} 14}
diff --git a/src/functiongetmakedeps.cpp b/src/functiongetmakedeps.cpp
index 008a509..cc6cbbb 100644
--- a/src/functiongetmakedeps.cpp
+++ b/src/functiongetmakedeps.cpp
@@ -6,6 +6,10 @@
6#include <bu/sio.h> 6#include <bu/sio.h>
7using namespace Bu; 7using namespace Bu;
8 8
9#include <bu/plugger.h>
10PluginInterface3( pluginFunctionGetMakeDeps, getMakeDeps, FunctionGetMakeDeps,
11 Function, "Mike Buland", 0, 1 );
12
9FunctionGetMakeDeps::FunctionGetMakeDeps() 13FunctionGetMakeDeps::FunctionGetMakeDeps()
10{ 14{
11} 15}
diff --git a/src/functionmatches.cpp b/src/functionmatches.cpp
index 4e4b7ff..5b96fa8 100644
--- a/src/functionmatches.cpp
+++ b/src/functionmatches.cpp
@@ -2,6 +2,10 @@
2 2
3#include <unistd.h> 3#include <unistd.h>
4 4
5#include <bu/plugger.h>
6PluginInterface3( pluginFunctionMatches, matches, FunctionMatches, Function,
7 "Mike Buland", 0, 1 );
8
5FunctionMatches::FunctionMatches() 9FunctionMatches::FunctionMatches()
6{ 10{
7} 11}
diff --git a/src/functionplugger.cpp b/src/functionplugger.cpp
new file mode 100644
index 0000000..83435ae
--- /dev/null
+++ b/src/functionplugger.cpp
@@ -0,0 +1,59 @@
1#include "functionplugger.h"
2
3#include <sys/types.h>
4#include <dirent.h>
5
6extern Bu::PluginInfo pluginFunctionDirName;
7extern Bu::PluginInfo pluginFunctionDirs;
8extern Bu::PluginInfo pluginFunctionExecute;
9extern Bu::PluginInfo pluginFunctionExists;
10extern Bu::PluginInfo pluginFunctionFileName;
11extern Bu::PluginInfo pluginFunctionFiles;
12extern Bu::PluginInfo pluginFunctionGetMakeDeps;
13extern Bu::PluginInfo pluginFunctionMatches;
14extern Bu::PluginInfo pluginFunctionReplace;
15extern Bu::PluginInfo pluginFunctionTargets;
16extern Bu::PluginInfo pluginFunctionToString;
17extern Bu::PluginInfo pluginFunctionUnlink;
18
19FunctionPlugger::FunctionPlugger()
20{
21 registerBuiltinPlugin( &pluginFunctionDirName );
22 registerBuiltinPlugin( &pluginFunctionDirs );
23 registerBuiltinPlugin( &pluginFunctionExecute );
24 registerBuiltinPlugin( &pluginFunctionExists );
25 registerBuiltinPlugin( &pluginFunctionFileName );
26 registerBuiltinPlugin( &pluginFunctionFiles );
27 registerBuiltinPlugin( &pluginFunctionGetMakeDeps );
28 registerBuiltinPlugin( &pluginFunctionMatches );
29 registerBuiltinPlugin( &pluginFunctionReplace );
30 registerBuiltinPlugin( &pluginFunctionTargets );
31 registerBuiltinPlugin( &pluginFunctionToString );
32 registerBuiltinPlugin( &pluginFunctionUnlink );
33
34 DIR *dir = opendir("/usr/lib/build");
35 if( !dir )
36 return;
37 struct dirent *de;
38 while( (de = readdir( dir )) )
39 {
40 if( strncmp("pluginFunction", de->d_name, 15 ) )
41 continue;
42
43 Bu::FString sFile("/usr/lib/build/");
44 sFile += de->d_name;
45 char *s = de->d_name;
46 for(; *s && *s != '.'; s++ ) { }
47 registerExternalPlugin(
48 sFile,
49 Bu::FString( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name )
50 );
51 }
52
53 closedir( dir );
54}
55
56FunctionPlugger::~FunctionPlugger()
57{
58}
59
diff --git a/src/functionplugger.h b/src/functionplugger.h
new file mode 100644
index 0000000..30022f6
--- /dev/null
+++ b/src/functionplugger.h
@@ -0,0 +1,17 @@
1#ifndef FUNCTION_PLUGGER_H
2#define FUNCTION_PLUGGER_H
3
4#include "function.h"
5#include <bu/plugger.h>
6#include <bu/singleton.h>
7
8class FunctionPlugger : public Bu::Plugger<Function>,
9 public Bu::Singleton<FunctionPlugger>
10{
11friend class Bu::Singleton<FunctionPlugger>;
12private:
13 FunctionPlugger();
14 virtual ~FunctionPlugger();
15};
16
17#endif
diff --git a/src/functionreplace.cpp b/src/functionreplace.cpp
index d269083..b341e44 100644
--- a/src/functionreplace.cpp
+++ b/src/functionreplace.cpp
@@ -1,5 +1,9 @@
1#include "functionreplace.h" 1#include "functionreplace.h"
2 2
3#include <bu/plugger.h>
4PluginInterface3( pluginFunctionReplace, replace, FunctionReplace, Function,
5 "Mike Buland", 0, 1 );
6
3FunctionReplace::FunctionReplace() 7FunctionReplace::FunctionReplace()
4{ 8{
5} 9}
diff --git a/src/functiontargets.cpp b/src/functiontargets.cpp
index 93fbb96..adafdfb 100644
--- a/src/functiontargets.cpp
+++ b/src/functiontargets.cpp
@@ -2,6 +2,10 @@
2#include "context.h" 2#include "context.h"
3#include "target.h" 3#include "target.h"
4 4
5#include <bu/plugger.h>
6PluginInterface3( pluginFunctionTargets, targets, FunctionTargets, Function,
7 "Mike Buland", 0, 1 );
8
5FunctionTargets::FunctionTargets() 9FunctionTargets::FunctionTargets()
6{ 10{
7} 11}
diff --git a/src/functiontostring.cpp b/src/functiontostring.cpp
index 0c04091..1d614ce 100644
--- a/src/functiontostring.cpp
+++ b/src/functiontostring.cpp
@@ -4,6 +4,10 @@
4#include <bu/sio.h> 4#include <bu/sio.h>
5using namespace Bu; 5using namespace Bu;
6 6
7#include <bu/plugger.h>
8PluginInterface3( pluginFunctionToString, toString, FunctionToString, Function,
9 "Mike Buland", 0, 1 );
10
7FunctionToString::FunctionToString() 11FunctionToString::FunctionToString()
8{ 12{
9} 13}
diff --git a/src/functionunlink.cpp b/src/functionunlink.cpp
index addcfd9..d8ad899 100644
--- a/src/functionunlink.cpp
+++ b/src/functionunlink.cpp
@@ -5,6 +5,10 @@
5#include <bu/sio.h> 5#include <bu/sio.h>
6using namespace Bu; 6using namespace Bu;
7 7
8#include <bu/plugger.h>
9PluginInterface3( pluginFunctionUnlink, unlink, FunctionUnlink, Function,
10 "Mike Buland", 0, 1 );
11
8FunctionUnlink::FunctionUnlink() 12FunctionUnlink::FunctionUnlink()
9{ 13{
10} 14}
diff --git a/src/main.cpp b/src/main.cpp
index 1bed895..c0b8dd3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,8 @@
5#include "target.h" 5#include "target.h"
6 6
7#include "viewplugger.h" 7#include "viewplugger.h"
8#include "functionplugger.h"
9#include "conditionplugger.h"
8 10
9#include "cache.h" 11#include "cache.h"
10 12
@@ -50,6 +52,8 @@ public:
50 addHelpBanner("The following options do things other than build:"); 52 addHelpBanner("The following options do things other than build:");
51 addOption( iInfoLevel, 'i', "info", "Display some basic info about the " 53 addOption( iInfoLevel, 'i', "info", "Display some basic info about the "
52 "loaded build config, including available targets."); 54 "loaded build config, including available targets.");
55 addOption( slot( this, &Options::onListPlugins), "list-plugins",
56 "List all available plugins.");
53 57
54 addHelpBanner("The following options control general execution:"); 58 addHelpBanner("The following options control general execution:");
55 addOption( sView, 'v', "view", sViews ); 59 addOption( sView, 'v', "view", sViews );
@@ -115,6 +119,42 @@ public:
115 return 0; 119 return 0;
116 } 120 }
117 121
122 int onListPlugins( StrArray /*sParams*/ )
123 {
124 StrList lViews = ViewPlugger::getInstance().getPluginList();
125 sio << "Available view plugins:" << sio.nl << "\t";
126 for( StrList::iterator i = lViews.begin(); i; i++ )
127 {
128 if( i != lViews.begin() )
129 sio << ", ";
130 sio << *i;
131 }
132
133 StrList lFuncs = FunctionPlugger::getInstance().getPluginList();
134 sio << sio.nl << sio.nl << "Available function plugins:"
135 << sio.nl << "\t";
136 for( StrList::iterator i = lFuncs.begin(); i; i++ )
137 {
138 if( i != lFuncs.begin() )
139 sio << ", ";
140 sio << *i;
141 }
142
143 StrList lConds = ConditionPlugger::getInstance().getPluginList();
144 sio << sio.nl << sio.nl << "Available condition plugins:"
145 << sio.nl << "\t";
146 for( StrList::iterator i = lConds.begin(); i; i++ )
147 {
148 if( i != lConds.begin() )
149 sio << ", ";
150 sio << *i;
151 }
152
153 sio << sio.nl << sio.nl;
154
155 return 0;
156 }
157
118 Bu::FString sView; 158 Bu::FString sView;
119 Bu::FString sAction; 159 Bu::FString sAction;
120 Bu::FString sConfig; 160 Bu::FString sConfig;
diff --git a/src/plugins/pluginConditionRandom.cpp b/src/plugins/pluginConditionRandom.cpp
new file mode 100644
index 0000000..42a4e00
--- /dev/null
+++ b/src/plugins/pluginConditionRandom.cpp
@@ -0,0 +1,31 @@
1#include "condition.h"
2#include <stdlib.h>
3
4class ConditionRandom : public Condition
5{
6public:
7 ConditionRandom()
8 {
9 }
10
11 virtual ~ConditionRandom()
12 {
13 }
14
15 virtual bool shouldExec( class Runner &, class Target & )
16 {
17 if( (random()/(double)RAND_MAX) >= .5 )
18 return true;
19 return false;
20 }
21
22 virtual Condition *clone()
23 {
24 return new ConditionRandom();
25 }
26};
27
28#include <bu/plugger.h>
29PluginInterface3( pluginConditionRandom, random, ConditionRandom, Condition,
30 "Mike Buland", 0, 1 );
31
diff --git a/src/profile.cpp b/src/profile.cpp
index 878a6e9..fd21097 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -4,9 +4,7 @@
4#include "astleaf.h" 4#include "astleaf.h"
5#include "condition.h" 5#include "condition.h"
6 6
7#include "conditionfiletime.h" 7#include "conditionplugger.h"
8#include "conditionalways.h"
9#include "conditionnever.h"
10 8
11#include <bu/sio.h> 9#include <bu/sio.h>
12using namespace Bu; 10using namespace Bu;
@@ -64,7 +62,7 @@ Profile *Profile::genDefaultClean()
64 pAst->openBranch(); 62 pAst->openBranch();
65 pAst->addNode( AstNode::typeString, "clean" ); 63 pAst->addNode( AstNode::typeString, "clean" );
66 pAst->openBranch(); 64 pAst->openBranch();
67 pAst->addNode( AstNode::typeCondition, "always" ); 65 pAst->addNode( AstNode::typeCondition, "fileExists" );
68 pAst->addNode( AstNode::typeFunction ); 66 pAst->addNode( AstNode::typeFunction );
69 pAst->openBranch(); 67 pAst->openBranch();
70 pAst->addNode( AstNode::typeString, "unlink" ); 68 pAst->addNode( AstNode::typeString, "unlink" );
@@ -89,28 +87,15 @@ void Profile::setCondition()
89 if( (*i)->getType() == AstNode::typeCondition ) 87 if( (*i)->getType() == AstNode::typeCondition )
90 { 88 {
91 Bu::FString sCond = dynamic_cast<const AstLeaf *>(*i)->getStrValue(); 89 Bu::FString sCond = dynamic_cast<const AstLeaf *>(*i)->getStrValue();
92 if( sCond == "filetime" ) 90 delete pCond;
93 { 91 pCond = ConditionPlugger::getInstance().instantiate( sCond );
94 delete pCond;
95 pCond = new ConditionFileTime();
96 }
97 else if( sCond == "always" )
98 {
99 delete pCond;
100 pCond = new ConditionAlways();
101 }
102 else if( sCond == "never" )
103 {
104 delete pCond;
105 pCond = new ConditionNever();
106 }
107 } 92 }
108 } 93 }
109 94
110 if( pCond == NULL ) 95 if( pCond == NULL )
111 { 96 {
112 // The default condition 97 // The default condition
113 pCond = new ConditionFileTime(); 98 pCond = ConditionPlugger::getInstance().instantiate("fileTime");
114 } 99 }
115} 100}
116 101
diff --git a/src/viewplugger.cpp b/src/viewplugger.cpp
index 6046f82..58f3605 100644
--- a/src/viewplugger.cpp
+++ b/src/viewplugger.cpp
@@ -1,11 +1,35 @@
1#include "viewplugger.h" 1#include "viewplugger.h"
2 2
3#include <sys/types.h>
4#include <dirent.h>
5
3extern Bu::PluginInfo pluginViewDefault; 6extern Bu::PluginInfo pluginViewDefault;
4extern Bu::PluginInfo pluginViewMake; 7extern Bu::PluginInfo pluginViewMake;
5ViewPlugger::ViewPlugger() 8ViewPlugger::ViewPlugger()
6{ 9{
7 registerBuiltinPlugin( &pluginViewDefault ); 10 registerBuiltinPlugin( &pluginViewDefault );
8 registerBuiltinPlugin( &pluginViewMake ); 11 registerBuiltinPlugin( &pluginViewMake );
12
13 DIR *dir = opendir("/usr/lib/build");
14 if( !dir )
15 return;
16 struct dirent *de;
17 while( (de = readdir( dir )) )
18 {
19 if( strncmp("pluginView", de->d_name, 15 ) )
20 continue;
21
22 Bu::FString sFile("/usr/lib/build/");
23 sFile += de->d_name;
24 char *s = de->d_name;
25 for(; *s && *s != '.'; s++ ) { }
26 registerExternalPlugin(
27 sFile,
28 Bu::FString( de->d_name, (ptrdiff_t)s-(ptrdiff_t)de->d_name )
29 );
30 }
31
32 closedir( dir );
9} 33}
10 34
11ViewPlugger::~ViewPlugger() 35ViewPlugger::~ViewPlugger()