| 203 | | // Bud Builder -- uses Derek Parnell's Bud |
|---|
| 204 | | //============================================================================== |
|---|
| 205 | | class BudBuilder : Builder |
|---|
| 206 | | { |
|---|
| 207 | | //========================================================================== |
|---|
| 208 | | // Methods |
|---|
| 209 | | //========================================================================== |
|---|
| 210 | | override void buildPackage(char[] packageName) |
|---|
| 211 | | { |
|---|
| 212 | | // construct a path to the package's forbud file |
|---|
| 213 | | char[] path = packageName ~ pathSep ~ _forBudName; |
|---|
| 214 | | |
|---|
| 215 | | // verify that the file exists |
|---|
| 216 | | bool doesExist = false; |
|---|
| 217 | | version(Tango) |
|---|
| 218 | | { |
|---|
| 219 | | } |
|---|
| 220 | | else |
|---|
| 221 | | { |
|---|
| 222 | | doesExist = exists(path) ? true : false; |
|---|
| 223 | | } |
|---|
| 224 | | |
|---|
| 225 | | if(!doesExist) |
|---|
| 226 | | { |
|---|
| 227 | | printf("Could not find %s\n", toCString(path)); |
|---|
| 228 | | return; |
|---|
| 229 | | } |
|---|
| 230 | | |
|---|
| 231 | | // create the temporary brf |
|---|
| 232 | | printf("Preparing to build package %s in %s mode...\n", toCString(packageName), toCString(modeToString())); |
|---|
| 233 | | createBRF(packageName, path); |
|---|
| 234 | | |
|---|
| 235 | | // call out to build with the name of the temp brf as an arg |
|---|
| 236 | | if(execute(_name ~ " @" ~ _tempBRFName) != 0) |
|---|
| 237 | | { |
|---|
| 238 | | throw new Exception("Failed to build package " ~ packageName); |
|---|
| 239 | | } |
|---|
| 240 | | |
|---|
| 241 | | if(!doNotDeleteBRF) |
|---|
| 242 | | { |
|---|
| 243 | | // delete the temporary brf |
|---|
| 244 | | printf("Deleting temporary Build Response File...\n\n"); |
|---|
| 245 | | execute(delCmd ~ _tempBRFName); |
|---|
| 246 | | } |
|---|
| 247 | | } |
|---|
| 248 | | |
|---|
| 249 | | private: |
|---|
| 250 | | this(char[] name) |
|---|
| 251 | | { |
|---|
| 252 | | _name = name; |
|---|
| 253 | | _commonOptsName = "bud_common.txt"; |
|---|
| 254 | | _configOptsName = (mode == Mode.Debug) ? "bud_debug.txt" : "bud_release.txt"; |
|---|
| 255 | | _tempBRFName = "temp.brf"; |
|---|
| 256 | | _forBudName = "forbud.txt"; |
|---|
| 257 | | _brfBuf = ""; |
|---|
| 258 | | |
|---|
| 259 | | buildBRFBuffer(); |
|---|
| 260 | | } |
|---|
| 261 | | |
|---|
| 262 | | void buildBRFBuffer() |
|---|
| 263 | | { |
|---|
| 264 | | version(Tango) |
|---|
| 265 | | { |
|---|
| 266 | | } |
|---|
| 267 | | else |
|---|
| 268 | | { |
|---|
| 269 | | // read in the common options file if it exists |
|---|
| 270 | | if(exists(_commonOptsName)) |
|---|
| | 206 | // Utility functions |
|---|
| | 207 | //============================================================================== |
|---|
| | 208 | char[] modeToString() |
|---|
| | 209 | { |
|---|
| | 210 | return (mode == Mode.Debug) ? "Debug" : "Release"; |
|---|
| | 211 | } |
|---|
| | 212 | |
|---|
| | 213 | char[] loadOpts(char[] prefix, OptsType type) |
|---|
| | 214 | { |
|---|
| | 215 | char[] fileName = "buildopts" ~ pathSep ~ prefix ~ optsSuffix(type) ~ ".txt"; |
|---|
| | 216 | char[] ret = readFile(fileName); |
|---|
| | 217 | if(ret is null) |
|---|
| | 218 | return ""; |
|---|
| | 219 | return ret; |
|---|
| | 220 | } |
|---|
| | 221 | |
|---|
| | 222 | char[] optsSuffix(OptsType type) |
|---|
| | 223 | { |
|---|
| | 224 | switch(type) |
|---|
| | 225 | { |
|---|
| | 226 | case OptsType.Common: |
|---|
| | 227 | return "_common"; |
|---|
| | 228 | case OptsType.Release: |
|---|
| | 229 | return "_release"; |
|---|
| | 230 | case OptsType.Debug: |
|---|
| | 231 | return "_debug"; |
|---|
| | 232 | default: |
|---|
| | 233 | throw new Exception("Unknown OptsType"); |
|---|
| | 234 | } |
|---|
| | 235 | } |
|---|
| | 236 | |
|---|
| | 237 | char[] generateFileList(char[] directory) |
|---|
| | 238 | { |
|---|
| | 239 | /* |
|---|
| | 240 | char[] files; |
|---|
| | 241 | |
|---|
| | 242 | version(Tango) |
|---|
| | 243 | { |
|---|
| | 244 | } |
|---|
| | 245 | else |
|---|
| | 246 | { |
|---|
| | 247 | // get a list of all files in the directory |
|---|
| | 248 | auto list = listdir(directory); |
|---|
| | 249 | foreach(c; list) |
|---|
| 274 | | |
|---|
| 275 | | // read in the options for the build configuration, if the file exists |
|---|
| 276 | | if(exists(_configOptsName)) |
|---|
| 277 | | { |
|---|
| 278 | | _brfBuf ~= cast(char[])read(_configOptsName); |
|---|
| 279 | | } |
|---|
| 280 | | } |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | void createBRF(char[] packageName, char[] path) |
|---|
| 284 | | { |
|---|
| 285 | | printf("Reading build tool arguments...\n"); |
|---|
| 286 | | |
|---|
| 287 | | char[] txt; // holds the contents of the forbud file |
|---|
| 288 | | |
|---|
| 289 | | // read the forbud.txt in this package |
|---|
| 290 | | version(Tango) |
|---|
| 291 | | { |
|---|
| 292 | | } |
|---|
| 293 | | else |
|---|
| 294 | | { |
|---|
| 295 | | txt = cast(char[])read(path); |
|---|
| 296 | | } |
|---|
| 297 | | |
|---|
| 298 | | // this will store all of the text to be output to the temp brf |
|---|
| 299 | | char[] brf = ""; |
|---|
| 300 | | |
|---|
| 301 | | // append the common brf buffer |
|---|
| 302 | | brf ~= _brfBuf; |
|---|
| 303 | | |
|---|
| 304 | | // the package directory myst be on the import path |
|---|
| 305 | | brf ~= "\n-I" ~ packageName; |
|---|
| 306 | | |
|---|
| 307 | | // if the current package is not DerelictUtil, then DerelictUtil must |
|---|
| 308 | | // be on the import path and excluded from compilation |
|---|
| 309 | | if(cmpStr(packageName, "DerelictUtil") != 0) |
|---|
| 310 | | { |
|---|
| 311 | | brf ~= "\n-IDerelictUtil\n-XDerelictUtil" ~ pathSep ~ "derelict" ~ pathSep ~ "util"; |
|---|
| 312 | | } |
|---|
| 313 | | |
|---|
| 314 | | // append a switch to set the output path of the library and append the config file |
|---|
| 315 | | brf ~= "\n-Tlib" ~ pathSep ~ libPre ~ packageName ~ libExt ~ "\n" ~ txt; |
|---|
| 316 | | |
|---|
| 317 | | // write the temporary brf to disk |
|---|
| 318 | | printf("Creating temporary Build Response File...\n"); |
|---|
| 319 | | version(Tango) |
|---|
| 320 | | { |
|---|
| 321 | | } |
|---|
| 322 | | else |
|---|
| 323 | | { |
|---|
| 324 | | write(_tempBRFName, cast(void[])brf); |
|---|
| 325 | | } |
|---|
| 326 | | } |
|---|
| 327 | | |
|---|
| 328 | | //========================================================================== |
|---|
| 329 | | // Members |
|---|
| 330 | | //========================================================================== |
|---|
| 331 | | char[] _name; |
|---|
| 332 | | char[] _commonOptsName; |
|---|
| 333 | | char[] _configOptsName; |
|---|
| 334 | | char[] _tempBRFName; |
|---|
| 335 | | char[] _forBudName; |
|---|
| 336 | | char[] _brfBuf; |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| 339 | | //============================================================================== |
|---|
| 340 | | // Utility functions |
|---|
| 341 | | //============================================================================== |
|---|
| 342 | | char[] modeToString() |
|---|
| 343 | | { |
|---|
| 344 | | return (mode == Mode.Debug) ? "Debug" : "Release"; |
|---|
| 345 | | } |
|---|
| 346 | | |
|---|
| 347 | | //============================================================================== |
|---|
| 348 | | // Wrappers for compatibility between Phobos and Tango. |
|---|
| 349 | | //============================================================================== |
|---|
| 350 | | char[] toLowerStr(char[] str) |
|---|
| 351 | | { |
|---|
| 352 | | version(Tango) |
|---|
| 353 | | { |
|---|
| 354 | | return toLower(str); |
|---|
| 355 | | } |
|---|
| 356 | | else |
|---|
| 357 | | { |
|---|
| 358 | | return tolower(str); |
|---|
| 359 | | } |
|---|
| 360 | | } |
|---|
| 361 | | |
|---|
| 362 | | //============================================================================== |
|---|
| 363 | | int cmpStr(char[] a, char[] b) |
|---|
| 364 | | { |
|---|
| 365 | | version(Tango) |
|---|
| 366 | | { |
|---|
| 367 | | String s = new String!(char)(a); |
|---|
| 368 | | return s.compare(b); |
|---|
| 369 | | } |
|---|
| 370 | | else |
|---|
| 371 | | { |
|---|
| 372 | | return cmp(a, b); |
|---|
| 373 | | } |
|---|
| 374 | | } |
|---|
| 375 | | |
|---|
| 376 | | //============================================================================== |
|---|
| 377 | | int findStr(char[] str, char[] match) |
|---|
| 378 | | { |
|---|
| 379 | | version(Tango) |
|---|
| 380 | | { |
|---|
| 381 | | int i = locatePattern(str, match); |
|---|
| 382 | | return (i == str.length) ? -1 : i; |
|---|
| 383 | | } |
|---|
| 384 | | else |
|---|
| 385 | | { |
|---|
| 386 | | return find(str, match); |
|---|
| 387 | | } |
|---|
| 388 | | } |
|---|
| 389 | | |
|---|
| 390 | | //============================================================================== |
|---|
| 391 | | char[][] splitString(char[] str, char[] delim) |
|---|
| 392 | | { |
|---|
| 393 | | version(Tango) |
|---|
| 394 | | { |
|---|
| 395 | | return demarcate(str, delim); |
|---|
| 396 | | } |
|---|
| 397 | | else |
|---|
| 398 | | { |
|---|
| 399 | | return split(str, delim); |
|---|
| 400 | | } |
|---|
| 401 | | } |
|---|
| 402 | | |
|---|
| 403 | | //============================================================================== |
|---|
| 404 | | char* toCString(char[] str) |
|---|
| 405 | | { |
|---|
| 406 | | version(Tango) |
|---|
| 407 | | { |
|---|
| 408 | | return toUtf8z(str); |
|---|
| 409 | | } |
|---|
| 410 | | else |
|---|
| 411 | | { |
|---|
| 412 | | return toStringz(str); |
|---|
| 413 | | } |
|---|
| 414 | | } |
|---|
| 415 | | |
|---|
| 416 | | //============================================================================== |
|---|
| 417 | | int execute(char[] cmd) |
|---|
| 418 | | { |
|---|
| 419 | | version(Tango) |
|---|
| 420 | | { |
|---|
| 421 | | auto p = new Process(cmd, null); |
|---|
| 422 | | p.execute(); |
|---|
| 423 | | Result r = p.wait(); |
|---|
| 424 | | return r.status; |
|---|
| 425 | | } |
|---|
| 426 | | else |
|---|
| 427 | | { |
|---|
| 428 | | return system(toStringz(cmd)); |
|---|
| 429 | | } |
|---|
| 430 | | } |
|---|
| | 257 | } |
|---|
| | 258 | */ |
|---|
| | 259 | return ""; |
|---|
| | 260 | } |
|---|