diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 562 |
1 files changed, 281 insertions, 281 deletions
diff --git a/src/main.cpp b/src/main.cpp index caa33e6..ded91ba 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -24,290 +24,290 @@ using namespace Bu; | |||
24 | class Options : public Bu::OptParser | 24 | class Options : public Bu::OptParser |
25 | { | 25 | { |
26 | public: | 26 | public: |
27 | Options( int argc, char *argv[] ) : | 27 | Options( int argc, char *argv[] ) : |
28 | sView("default"), | 28 | sView("default"), |
29 | sAction("default"), | 29 | sAction("default"), |
30 | sConfig("default.bld"), | 30 | sConfig("default.bld"), |
31 | sCacheFile(".build_cache"), | 31 | sCacheFile(".build_cache"), |
32 | bDot( false ), | 32 | bDot( false ), |
33 | bDebug( false ), | 33 | bDebug( false ), |
34 | bAutoInclude( true ), | 34 | bAutoInclude( true ), |
35 | bAstDump( false ), | 35 | bAstDump( false ), |
36 | bEnviron( true ), | 36 | bEnviron( true ), |
37 | bCache( true ), | 37 | bCache( true ), |
38 | iInfoLevel( 0 ) | 38 | iInfoLevel( 0 ) |
39 | { | 39 | { |
40 | bool bClean = false; | 40 | bool bClean = false; |
41 | addHelpBanner("build mark 3\n"); | 41 | addHelpBanner("build mark 3\n"); |
42 | 42 | ||
43 | Bu::String sViews("Select a view from: "); | 43 | Bu::String sViews("Select a view from: "); |
44 | StrList lViews = ViewPlugger::getInstance().getPluginList(); | 44 | StrList lViews = ViewPlugger::getInstance().getPluginList(); |
45 | for( StrList::iterator i = lViews.begin(); i; i++ ) | 45 | for( StrList::iterator i = lViews.begin(); i; i++ ) |
46 | { | 46 | { |
47 | if( i != lViews.begin() ) | 47 | if( i != lViews.begin() ) |
48 | sViews += ", "; | 48 | sViews += ", "; |
49 | sViews += *i; | 49 | sViews += *i; |
50 | } | 50 | } |
51 | 51 | ||
52 | addHelpBanner("The following options do things other than build:"); | 52 | addHelpBanner("The following options do things other than build:"); |
53 | addOption( iInfoLevel, 'i', "info", "Display some basic info about the " | 53 | addOption( iInfoLevel, 'i', "info", "Display some basic info about the " |
54 | "loaded build config, including available targets."); | 54 | "loaded build config, including available targets."); |
55 | addOption( slot( this, &Options::onListPlugins), "list-plugins", | 55 | addOption( slot( this, &Options::onListPlugins), "list-plugins", |
56 | "List all available plugins."); | 56 | "List all available plugins."); |
57 | addHelpOption(); | 57 | addHelpOption(); |
58 | 58 | ||
59 | addHelpBanner("\nThe following options control general execution:"); | 59 | addHelpBanner("\nThe following options control general execution:"); |
60 | addOption( sView, 'v', "view", sViews ); | 60 | addOption( sView, 'v', "view", sViews ); |
61 | addOption( sConfig, 'f', "file", "Select a different config file." ); | 61 | addOption( sConfig, 'f', "file", "Select a different config file." ); |
62 | addOption( bClean, 'c', "Shorthand for running action 'clean'. If an " | 62 | addOption( bClean, 'c', "Shorthand for running action 'clean'. If an " |
63 | "action is specified, this will modify it to run 'clean-action'."); | 63 | "action is specified, this will modify it to run 'clean-action'."); |
64 | addOption( slot(this, &Options::onChdir), 'C', "chdir", | 64 | addOption( slot(this, &Options::onChdir), 'C', "chdir", |
65 | "Change to directory before doing anything else."); | 65 | "Change to directory before doing anything else."); |
66 | addOption( sCacheFile, "cache", "Select a different cache file."); | 66 | addOption( sCacheFile, "cache", "Select a different cache file."); |
67 | addOption( bCache, "no-cache", "Disable using the cache."); | 67 | addOption( bCache, "no-cache", "Disable using the cache."); |
68 | 68 | ||
69 | addHelpBanner("\nThe following options control debugging:"); | 69 | addHelpBanner("\nThe following options control debugging:"); |
70 | addOption( bEnviron, "no-env", "Do not import environment variables."); | 70 | addOption( bEnviron, "no-env", "Do not import environment variables."); |
71 | addOption( bDot, "dot", "Generate a dot chart after execution." ); | 71 | addOption( bDot, "dot", "Generate a dot chart after execution." ); |
72 | addOption( bDebug, "debug", | 72 | addOption( bDebug, "debug", |
73 | "Dump massive amounts of hard to read debugging data." ); | 73 | "Dump massive amounts of hard to read debugging data." ); |
74 | addOption( bAstDump, "debug-ast", | 74 | addOption( bAstDump, "debug-ast", |
75 | "Display the raw AST that is computed from parsing the input. " | 75 | "Display the raw AST that is computed from parsing the input. " |
76 | "You should probably never ever use this, it'll scare you." | 76 | "You should probably never ever use this, it'll scare you." |
77 | ); | 77 | ); |
78 | 78 | ||
79 | setHelpDefault( "view", "=[view]" ); | 79 | setHelpDefault( "view", "=[view]" ); |
80 | setHelpDefault( "file", "=[file]" ); | 80 | setHelpDefault( "file", "=[file]" ); |
81 | setHelpDefault( "cache", "=[file]" ); | 81 | setHelpDefault( "cache", "=[file]" ); |
82 | setHelpDefault( "chdir", "=[dir]" ); | 82 | setHelpDefault( "chdir", "=[dir]" ); |
83 | 83 | ||
84 | setOverride( "no-env", "false" ); | 84 | setOverride( "no-env", "false" ); |
85 | setOverride( "dot", "true" ); | 85 | setOverride( "dot", "true" ); |
86 | setOverride( "debug", "true" ); | 86 | setOverride( "debug", "true" ); |
87 | setOverride( "debug-ast", "true" ); | 87 | setOverride( "debug-ast", "true" ); |
88 | setOverride( "info", "1" ); | 88 | setOverride( "info", "1" ); |
89 | setOverride( 'c', "true" ); | 89 | setOverride( 'c', "true" ); |
90 | setOverride( "no-cache", "false" ); | 90 | setOverride( "no-cache", "false" ); |
91 | 91 | ||
92 | setNonOption( slot( this, &Options::onNonOption ) ); | 92 | setNonOption( slot( this, &Options::onNonOption ) ); |
93 | 93 | ||
94 | parse( argc, argv ); | 94 | parse( argc, argv ); |
95 | 95 | ||
96 | if( bClean ) | 96 | if( bClean ) |
97 | { | 97 | { |
98 | if( sAction == "default" ) | 98 | if( sAction == "default" ) |
99 | sAction = "clean"; | 99 | sAction = "clean"; |
100 | else | 100 | else |
101 | sAction.prepend("clean-"); | 101 | sAction.prepend("clean-"); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | 104 | ||
105 | virtual ~Options() | 105 | virtual ~Options() |
106 | { | 106 | { |
107 | } | 107 | } |
108 | 108 | ||
109 | int onChdir( StrArray sParams ) | 109 | int onChdir( StrArray sParams ) |
110 | { | 110 | { |
111 | if( sParams.getSize() == 0 ) | 111 | if( sParams.getSize() == 0 ) |
112 | { | 112 | { |
113 | sio << "You must specify a directory name!" << sio.nl << sio.nl; | 113 | sio << "You must specify a directory name!" << sio.nl << sio.nl; |
114 | exit(2); | 114 | exit(2); |
115 | } | 115 | } |
116 | chdir( sParams[1].getStr() ); | 116 | chdir( sParams[1].getStr() ); |
117 | return 1; | 117 | return 1; |
118 | } | 118 | } |
119 | 119 | ||
120 | int onNonOption( StrArray sParams ) | 120 | int onNonOption( StrArray sParams ) |
121 | { | 121 | { |
122 | sAction = sParams[0]; | 122 | sAction = sParams[0]; |
123 | return 0; | 123 | return 0; |
124 | } | 124 | } |
125 | 125 | ||
126 | int onListPlugins( StrArray /*sParams*/ ) | 126 | int onListPlugins( StrArray /*sParams*/ ) |
127 | { | 127 | { |
128 | StrList lViews = ViewPlugger::getInstance().getPluginList(); | 128 | StrList lViews = ViewPlugger::getInstance().getPluginList(); |
129 | sio << "Available view plugins:" << sio.nl << "\t"; | 129 | sio << "Available view plugins:" << sio.nl << "\t"; |
130 | for( StrList::iterator i = lViews.begin(); i; i++ ) | 130 | for( StrList::iterator i = lViews.begin(); i; i++ ) |
131 | { | 131 | { |
132 | if( i != lViews.begin() ) | 132 | if( i != lViews.begin() ) |
133 | sio << ", "; | 133 | sio << ", "; |
134 | sio << *i; | 134 | sio << *i; |
135 | } | 135 | } |
136 | 136 | ||
137 | StrList lFuncs = FunctionPlugger::getInstance().getPluginList(); | 137 | StrList lFuncs = FunctionPlugger::getInstance().getPluginList(); |
138 | sio << sio.nl << sio.nl << "Available function plugins:" | 138 | sio << sio.nl << sio.nl << "Available function plugins:" |
139 | << sio.nl << "\t"; | 139 | << sio.nl << "\t"; |
140 | for( StrList::iterator i = lFuncs.begin(); i; i++ ) | 140 | for( StrList::iterator i = lFuncs.begin(); i; i++ ) |
141 | { | 141 | { |
142 | if( i != lFuncs.begin() ) | 142 | if( i != lFuncs.begin() ) |
143 | sio << ", "; | 143 | sio << ", "; |
144 | sio << *i; | 144 | sio << *i; |
145 | } | 145 | } |
146 | 146 | ||
147 | StrList lConds = ConditionPlugger::getInstance().getPluginList(); | 147 | StrList lConds = ConditionPlugger::getInstance().getPluginList(); |
148 | sio << sio.nl << sio.nl << "Available condition plugins:" | 148 | sio << sio.nl << sio.nl << "Available condition plugins:" |
149 | << sio.nl << "\t"; | 149 | << sio.nl << "\t"; |
150 | for( StrList::iterator i = lConds.begin(); i; i++ ) | 150 | for( StrList::iterator i = lConds.begin(); i; i++ ) |
151 | { | 151 | { |
152 | if( i != lConds.begin() ) | 152 | if( i != lConds.begin() ) |
153 | sio << ", "; | 153 | sio << ", "; |
154 | sio << *i; | 154 | sio << *i; |
155 | } | 155 | } |
156 | 156 | ||
157 | sio << sio.nl << sio.nl; | 157 | sio << sio.nl << sio.nl; |
158 | 158 | ||
159 | return 0; | 159 | return 0; |
160 | } | 160 | } |
161 | 161 | ||
162 | Bu::String sView; | 162 | Bu::String sView; |
163 | Bu::String sAction; | 163 | Bu::String sAction; |
164 | Bu::String sConfig; | 164 | Bu::String sConfig; |
165 | Bu::String sCacheFile; | 165 | Bu::String sCacheFile; |
166 | bool bDot; | 166 | bool bDot; |
167 | bool bDebug; | 167 | bool bDebug; |
168 | bool bAutoInclude; | 168 | bool bAutoInclude; |
169 | bool bAstDump; | 169 | bool bAstDump; |
170 | bool bEnviron; | 170 | bool bEnviron; |
171 | bool bCache; | 171 | bool bCache; |
172 | int iInfoLevel; | 172 | int iInfoLevel; |
173 | }; | 173 | }; |
174 | 174 | ||
175 | int main( int argc, char *argv[] ) | 175 | int main( int argc, char *argv[] ) |
176 | { | 176 | { |
177 | typedef Bu::List<Bu::String> StrList; | 177 | typedef Bu::List<Bu::String> StrList; |
178 | StrList lShareList; | 178 | StrList lShareList; |
179 | lShareList.append("/usr/share/build/").append("./share/"); | 179 | lShareList.append("/usr/share/build/").append("./share/"); |
180 | Ast ast; | 180 | Ast ast; |
181 | Context cnt; | 181 | Context cnt; |
182 | BuildParser bp( ast ); | 182 | BuildParser bp( ast ); |
183 | 183 | ||
184 | for( StrList::iterator i = lShareList.begin(); i; i++ ) | 184 | for( StrList::iterator i = lShareList.begin(); i; i++ ) |
185 | { | 185 | { |
186 | bp.addIncludePath( *i + "include"); | 186 | bp.addIncludePath( *i + "include"); |
187 | } | 187 | } |
188 | 188 | ||
189 | Options opts( argc, argv ); | 189 | Options opts( argc, argv ); |
190 | 190 | ||
191 | try | 191 | try |
192 | { | 192 | { |
193 | cnt.setView( ViewPlugger::getInstance().instantiate( opts.sView ) ); | 193 | cnt.setView( ViewPlugger::getInstance().instantiate( opts.sView ) ); |
194 | } | 194 | } |
195 | catch( Bu::HashException &e ) | 195 | catch( Bu::HashException &e ) |
196 | { | 196 | { |
197 | sio << "Error: Invalid view specified, please choose from the " | 197 | sio << "Error: Invalid view specified, please choose from the " |
198 | "following choices:" << sio.nl << sio.nl << "\t"; | 198 | "following choices:" << sio.nl << sio.nl << "\t"; |
199 | 199 | ||
200 | StrList lViews = ViewPlugger::getInstance().getPluginList(); | 200 | StrList lViews = ViewPlugger::getInstance().getPluginList(); |
201 | for( StrList::iterator i = lViews.begin(); i; i++ ) | 201 | for( StrList::iterator i = lViews.begin(); i; i++ ) |
202 | { | 202 | { |
203 | if( i != lViews.begin() ) | 203 | if( i != lViews.begin() ) |
204 | sio << ", "; | 204 | sio << ", "; |
205 | sio << *i; | 205 | sio << *i; |
206 | } | 206 | } |
207 | sio << sio.nl << sio.nl; | 207 | sio << sio.nl << sio.nl; |
208 | return 1; | 208 | return 1; |
209 | } | 209 | } |
210 | 210 | ||
211 | if( opts.bCache ) | 211 | if( opts.bCache ) |
212 | { | 212 | { |
213 | Cache::getInstance().bind( opts.sCacheFile ); | 213 | Cache::getInstance().bind( opts.sCacheFile ); |
214 | } | 214 | } |
215 | 215 | ||
216 | // Load up the environment as vars. | 216 | // Load up the environment as vars. |
217 | if( opts.bEnviron ) | 217 | if( opts.bEnviron ) |
218 | { | 218 | { |
219 | for( char **env = environ; *env; env++ ) | 219 | for( char **env = environ; *env; env++ ) |
220 | { | 220 | { |
221 | int iSplit; | 221 | int iSplit; |
222 | for( iSplit = 0; (*env)[iSplit] != '='; iSplit++ ) { } | 222 | for( iSplit = 0; (*env)[iSplit] != '='; iSplit++ ) { } |
223 | cnt.addVariable( | 223 | cnt.addVariable( |
224 | String( *env, iSplit ), | 224 | String( *env, iSplit ), |
225 | String( *env+iSplit+1 ) | 225 | String( *env+iSplit+1 ) |
226 | ); | 226 | ); |
227 | } | 227 | } |
228 | } | 228 | } |
229 | 229 | ||
230 | if( opts.bAutoInclude ) | 230 | if( opts.bAutoInclude ) |
231 | { | 231 | { |
232 | DIR *d; | 232 | DIR *d; |
233 | Bu::String sAutoDir; | 233 | Bu::String sAutoDir; |
234 | for( StrList::iterator i = lShareList.begin(); i; i++ ) | 234 | for( StrList::iterator i = lShareList.begin(); i; i++ ) |
235 | { | 235 | { |
236 | sAutoDir = *i + "autoinclude"; | 236 | sAutoDir = *i + "autoinclude"; |
237 | d = opendir( sAutoDir.getStr() ); | 237 | d = opendir( sAutoDir.getStr() ); |
238 | if( d ) | 238 | if( d ) |
239 | break; | 239 | break; |
240 | } | 240 | } |
241 | if( !d ) | 241 | if( !d ) |
242 | { | 242 | { |
243 | cnt.getView()->sysWarning( | 243 | cnt.getView()->sysWarning( |
244 | "Could not find an autoinclude directory." | 244 | "Could not find an autoinclude directory." |
245 | ); | 245 | ); |
246 | } | 246 | } |
247 | else | 247 | else |
248 | { | 248 | { |
249 | struct dirent *de; | 249 | struct dirent *de; |
250 | while( (de = readdir( d )) ) | 250 | while( (de = readdir( d )) ) |
251 | { | 251 | { |
252 | if( de->d_name[0] == '.' || (de->d_type != DT_REG) ) | 252 | if( de->d_name[0] == '.' || (de->d_type != DT_REG) ) |
253 | continue; | 253 | continue; |
254 | //sio << "Auto-including: " << de->d_name << sio.nl; | 254 | //sio << "Auto-including: " << de->d_name << sio.nl; |
255 | bp.load( sAutoDir + "/" + de->d_name ); | 255 | bp.load( sAutoDir + "/" + de->d_name ); |
256 | } | 256 | } |
257 | } | 257 | } |
258 | } | 258 | } |
259 | 259 | ||
260 | bp.load( opts.sConfig ); | 260 | bp.load( opts.sConfig ); |
261 | 261 | ||
262 | if( opts.bAstDump ) | 262 | if( opts.bAstDump ) |
263 | { | 263 | { |
264 | sio << ast << sio.nl << sio.nl; | 264 | sio << ast << sio.nl << sio.nl; |
265 | return 0; | 265 | return 0; |
266 | } | 266 | } |
267 | 267 | ||
268 | // sio << ast << sio.nl; | 268 | // sio << ast << sio.nl; |
269 | 269 | ||
270 | Runner r( ast, cnt ); | 270 | Runner r( ast, cnt ); |
271 | r.initialize(); | 271 | r.initialize(); |
272 | 272 | ||
273 | r.run(); | 273 | r.run(); |
274 | 274 | ||
275 | switch( opts.iInfoLevel ) | 275 | switch( opts.iInfoLevel ) |
276 | { | 276 | { |
277 | case 0: | 277 | case 0: |
278 | // Do nothing | 278 | // Do nothing |
279 | break; | 279 | break; |
280 | 280 | ||
281 | case 1: | 281 | case 1: |
282 | cnt.printBasicInfo(); | 282 | cnt.printBasicInfo(); |
283 | return 0; | 283 | return 0; |
284 | } | 284 | } |
285 | 285 | ||
286 | try | 286 | try |
287 | { | 287 | { |
288 | r.execAction( opts.sAction ); | 288 | r.execAction( opts.sAction ); |
289 | } | 289 | } |
290 | catch( std::exception &e ) | 290 | catch( std::exception &e ) |
291 | { | 291 | { |
292 | cnt.getView()->sysError(e.what()); | 292 | cnt.getView()->sysError(e.what()); |
293 | } | 293 | } |
294 | catch( ... ) | 294 | catch( ... ) |
295 | { | 295 | { |
296 | cnt.getView()->sysError( | 296 | cnt.getView()->sysError( |
297 | "Unknown error occured, this is probably bad..." | 297 | "Unknown error occured, this is probably bad..." |
298 | ); | 298 | ); |
299 | } | 299 | } |
300 | 300 | ||
301 | if( opts.bDot ) | 301 | if( opts.bDot ) |
302 | { | 302 | { |
303 | cnt.writeTargetDot(); | 303 | cnt.writeTargetDot(); |
304 | } | 304 | } |
305 | 305 | ||
306 | if( opts.bDebug ) | 306 | if( opts.bDebug ) |
307 | { | 307 | { |
308 | sio << "Final context:" << sio.nl << cnt << sio.nl << sio.nl; | 308 | sio << "Final context:" << sio.nl << cnt << sio.nl << sio.nl; |
309 | } | 309 | } |
310 | 310 | ||
311 | return 0; | 311 | return 0; |
312 | } | 312 | } |
313 | 313 | ||