Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 769 lines (703 sloc) 24.626 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
$loadlib "io_ops";
class OS;

function setup_main(var argv)
{
    setup_distutils();
    var rosella = {
        "name" : 'Rosella',
        "abstract" : 'Utilities Library for Parrot',
        "authority" : 'http://github.com/Whiteknight',
        "copyright_holder" : 'Andrew Whitworth',
        "keywords" : ["test", "tap", "xunit", "event", "container", "dependency injection"],
        "license_type" : 'Artistic License 2.0',
        "license_uri" : 'http://www.perlfoundation.org/artistic_license_2_0',
        "checkout_uri" : 'git://github.com/Whiteknight/rosella.git',
        "browser_uri" : 'git://github.com/Whiteknight/rosella',
        "project_uri" : 'git://github.com/Whiteknight/rosella',
        "pir_nqp-rx" : {},
        "pir_winxed" : {},
        "pbc_pbc" : {},
        "pbc_pir" : {},
        "pir_pir" : {},
        "winxed_debug" : false,
        "winxed_winxed" : {},
        "inst_lib" : [],
        "installable_pbc" : {},
        "include_winxed" : {},
        "manifest_includes" : ["CREDITS", "README.md", "setup.winxed"]
    };

    setup_release(rosella);
    setup_stable_libraries(rosella);
    setup_experimental_libraries(rosella);
    setup_utilities(rosella);
    setup_data_files(rosella);
    setup_include_headers(rosella);

    get_all_tests(rosella, "t");
    argv.shift();
    setup(argv, rosella);
}

function setup_release(var rosella)
{
    //rosella["pir_winxed"]["setup.pir"] = "setup.winxed";
    //rosella["manifest_includes"].push("setup.pir");
}

function setup_stable_libraries(var rosella)
{
    // A distutils wrapper library which adds winxed functionality.
    // A bootstrapped version is included in the repo because we need it
    // to run setup.winxed (this script). This is the only rosella library
    // which doesn't rely on Core.
    setup_winxed_lib(rosella, "winxed", [],
        "winxed/Distutils"
    );

    // The Rosella "core" library. Does very little on its own but is
    // required by other libraries in the sequence
    setup_winxed_lib(rosella, "core", [],
        "core/Includes",
        "core/Rosella",
        "core/Error",
        "core/Hash",
        "core/Function",
        "core/IO",
        "core/IteratorBase",
        "core/Globals",
        "core/ObjectFactory",
        "core/Version",
        "core/StringFormatter",
        "core/Parrot",
        "_build/_versions"
    );

    // The action library. Allows creating Action/Command objects for
    // delayed evaluation.
    setup_winxed_lib(rosella, "action", ["Core"],
        "action/Action",
        "action/action/Sub",
        "action/action/Method",
        "action/Argument",
        "action/argument/Instance"
    );

    // Dependency Injection / Inversion of Control container library
    setup_winxed_lib(rosella, "container", ["Core"],
        "container/Container",
        "container/Argument",
        "container/LifetimeManager",
        "container/Option",
        "container/Resolver",
        "container/ServiceLocator"
    );

    // A proxying library for building and managing proxies
    setup_winxed_lib(rosella, "proxy", ["Core"],
        "proxy/Builder",
        "proxy/Controller",
        "proxy/Factory",
        "proxy/Proxy",
        "proxy/builder/Array",
        "proxy/builder/AttributeIntercept",
        "proxy/builder/Imitate",
        "proxy/builder/Immutable",
        "proxy/builder/InvokeIntercept",
        "proxy/builder/MethodIntercept",
        "proxy/builder/Passthrough",
        "proxy/builder/PMCKeyedHash",
        "proxy/builder/ProxyData",
        "proxy/builder/StringKeyedHash"
    );

    // A testing library for writing and running unit tests.
    setup_winxed_lib(rosella, "test", ["Core"],
        "test/Builder",
        "test/Asserter",
        "test/Failure",
        "test/Listener",
        "test/Listener/TAP",
        "test/Matcher",
        "test/matcher/Factory",
        "test/Result",
        "test/Suite",
        "test/SuiteFactory",
        "test/suitefactory/List",
        "test/suitefactory/Vector",
        "test/Test",
        "test/TestCase",
        "test/TestContext",
        "test/TestFactory",
        "test/TestStatus"
    );

    // A mock object library for advanced unit testing
    setup_winxed_lib(rosella, "mockobject", ["Core", "Test", "Proxy"],
        "mockobject/MockObject",
        "mockobject/Controller",
        "mockobject/controller/Ordered",
        "mockobject/Expectation",
        "mockobject/expectation/Get",
        "mockobject/expectation/Set",
        "mockobject/expectation/Method",
        "mockobject/expectation/Invoke",
        "mockobject/expectation/Will",
        "mockobject/expectation/With",
        "mockobject/Factory"
    );

    // A tap harness library for building easy, extensible test harnesses
    setup_winxed_lib(rosella, "harness", ["Core", "FileSystem", "Query", "String", "Container"],
        "harness/Harness",
        "harness/FileResult",
        "harness/TapParser",
        "harness/TestExecutor",
        "harness/TestFile",
        "harness/testfile/Automatic",
        "harness/testfile/Factory",
        "harness/testfile/NQP",
        "harness/testfile/PIR",
        "harness/testfile/Winxed",
        "harness/TestRun",
        "harness/testrun/Factory",
        "harness/View"
    );

    // Event library. Subscribe to, receive, and publish event notifications.
    setup_winxed_lib(rosella, "event", ["Core"],
        "event/Event",
        "event/Dispatcher",
        "event/dispatcher/Factory",
        "event/Manager",
        "event/Payload",
        "event/Subscriber",
        "event/subscriber/Factory"
    );

    // Memoization library. Allows multiple types of transparent Sub
    // memoization.
    setup_winxed_lib(rosella, "memoize", ["Core", "Proxy"],
        "memoize/Memoize",
        "memoize/Cache",
        "memoize/cache/Item",
        "memoize/cache/SimpleString",
        "memoize/Controller",
        "memoize/Factory"
    );

    // A library for working with aggregates
    setup_winxed_lib(rosella, "query", ["Core", "Random"],
        "query/Includes",
        "query/Query",
        "query/Provider",
        "query/provider/Array",
        "query/provider/Hash",
        "query/provider/Scalar",
        "query/provider/Factory",
        "query/Queryable",
        "query/Iterable",
        "query/iterable/Factory",
        "query/iterable/KeyValuePair",
        "query/iterable/Sources",
        "query/iterable/Iterators",
        "query/Sort",
        "query/sort/Timsort"
    );

    // A library for working with files and directories
    setup_winxed_lib(rosella, "filesystem", ["Core", "Math_Builtins", "Date"],
        "filesystem/Includes",
        "filesystem/FileSystem",
        "filesystem/Entry",
        "filesystem/Directory",
        "filesystem/DirectoryIterator",
        "filesystem/File",
        "filesystem/FileIterator",
        "filesystem/IterableHandle",
        "filesystem/Path",
        "filesystem/Visitor",
        "filesystem/visitor/Delete",
        "filesystem/visitor/Function",
        "filesystem/visitor/List",
        ["filesystem/Constants"]:[named("constants")]
    );

    // Search for values in nested aggregates
    setup_winxed_lib(rosella, "path", ["Core"],
        "path/Path",
        "path/Searcher",
        "path/searcher/Hash",
        "path/searcher/Attribute"
    );

    // String handling and tokenizing library
    setup_winxed_lib(rosella, "string", ["Core"],
        "string/Includes",
        "string/String",
        "string/FormatPrinter",
        "string/Tokenizer",
        "string/tokenizer/CClass",
        "string/tokenizer/Delimiter",
        "string/tokenizer/DelimiterRegion",
        "string/tokenizer/Iterator",
        "string/tokenizer/SimpleCode",
        "string/tokenizer/Token",
        "string/Trie"
    );

    // Templating and formatting text
    setup_winxed_lib(rosella, "template", ["Core", "Path", "String", "FileSystem"],
        "template/Includes",
        "template/Template",
        "template/Engine",
        "template/Context",
        "template/Handler",
        "template/handler/Factory",
        "template/handler/For",
        "template/handler/Repeat",
        "template/handler/If",
        "template/handler/Include",
        "template/handler/Set",
        "template/Node",
        "template/node/Factory",
        "template/node/Master",
        "template/node/Logic",
        "template/node/Data",
        "template/node/Eval",
        "template/node/Literal"
    );

    // Random number generation and tools
    setup_winxed_lib(rosella, "random", ["String", "Math_Builtins"],
        "random/Includes",
        "random/Random",
        "random/RandomNumber",
        "random/randomnumber/BoxMullerNormal",
        "random/randomnumber/MersenneTwister",
        "random/UUID",
        "random/uuid/Version4"
    );

    // Working with commandline arguments
    setup_winxed_lib(rosella, "commandline", ["Core", "String"],
        "commandline/Arguments",
        "commandline/ArgumentDef",
        "commandline/ModeCondition",
        "commandline/Program",
        "commandline/ProgramMode"
    );

    // Library for debug-style data dumping
    setup_winxed_lib(rosella, "dumper", ["Core"],
        "dumper/Dumper",
        "dumper/DumpHandler",
        "dumper/Emitter",
        "dumper/dumphandler/Array",
        "dumper/dumphandler/Hash",
        "dumper/dumphandler/InspectAttrs",
        "dumper/dumphandler/Object",
        "dumper/dumphandler/Null",
        "dumper/Handle"
    );

    // Library for working with date and time
    setup_winxed_lib(rosella, "date", ["Core", "Ascii", "Parse_builtins", "Parse"],
        "date/Includes",
        "date/Date",
        "date/DateFormatter",
        "date/Doomsday",
        "date/ISO8601_101",
        "date/SpecialDate",
        "date/TimeSpan",
        "date/TimeSpanFormatter"
    );

    // Library for reflection and introspection
    setup_winxed_lib(rosella, "reflect", ["Core"],
        "reflect/Includes",
        "reflect/Reflect",
        "reflect/Class",
        "reflect/class/Member",
        "reflect/class/Attribute",
        "reflect/class/Method",
        "reflect/Deserializer",
        "reflect/Function",
        "reflect/Instruction",
        "reflect/Module",
        "reflect/OpArg"
    );

    setup_winxed_lib(rosella, "parse", ["Core", "Ascii", "Parse_builtins"],
        "parse/Parse"
    );

    setup_winxed_lib(rosella, "json", ["Core", "Ascii", "Parse_builtins", "Parse", "Dumper"],
        "json/Includes",
        "json/Json",
        "json/Builder",
        "json/builder/Factory",
        "json/builder/DataObject",
        "json/Dumper",
        "json/DumpHandler",
        "json/Parser",
        "json/ParseResult"
    );

    setup_winxed_lib(rosella, "net", ["Core", "Math_Builtins", "Ascii", "Parse_builtins", "Parse", "String", "FileSystem", "Date", "Random"],
        "net/Includes",
        "net/Net",
        "net/Http",
        "net/RequestResponse",
        "net/http/Header",
        "net/http/Request",
        "net/http/Response",
        "net/MimeBase64",
        "net/Protocol",
        "net/protocol/Factory",
        "net/protocol/File",
        "net/protocol/Http",
        "net/Uri",
        "net/uri/Factory",
        "net/uri/File",
        "net/uri/Http",
        "net/UserAgent",
        "net/useragent/SimpleHttp",
        "net/SocketFactory"
    );

    setup_winxed_lib(rosella, "xml", ["Core", "Ascii", "Parse_builtins", "Parse", "String", "FileSystem", "Query"],
        "xml/Includes",
        "xml/Xml",
        "xml/Document",
        "xml/Parser",
        "xml/Tag",
        "xml/tag/Collection",
        "xml/Text",
        "xml/Visitor"
    );
}

function setup_experimental_libraries(var rosella)
{
    // A prototype library for managing a prototype-based object system
    setup_unstable_lib(rosella, "prototype", ["Core"],
        "prototype/Object",
        "prototype/Manager",
        "prototype/manager/Entry",
        "prototype/manager/ObjectCloner"
    );

    // A library for creating and using cheap, transparent decorator
    setup_unstable_lib(rosella, "decorate", ["Core", "Proxy"],
        "decorate/Builder",
        "decorate/Decorator",
        "decorate/Factory"
    );

    setup_unstable_lib(rosella, "assert", ["Core"],
        "assert/Assert",
        "assert/Debug",
        "assert/Method",
        "assert/Interface"
    );

    setup_unstable_lib(rosella, "lazy", ["Core", "Proxy"],
        "lazy/Lazy",
        "lazy/Builder",
        "lazy/Controller",
        "lazy/Factory"
    );

    setup_unstable_lib(rosella, "benchmark", ["Core", "Math_Builtins"],
        "benchmark/Benchmark",
        "benchmark/Result"
    );

    setup_unstable_lib(rosella, "repl", ["Core"],
        "repl/Repl",
        "repl/Commands",
        "repl/CommandFuncs",
        "repl/Compiler",
        "repl/State",
        "repl/View"
    );

    setup_unstable_lib(rosella, "genetic", ["Core", "Query", "Random"],
        "genetic/Cell",
        "genetic/Context",
        "genetic/Engine",
        "genetic/Mutator",
        "genetic/mutator/Generic"
    );

    setup_unstable_lib(rosella, "feed", ["Core", "Xml", "Net", "FileSystem"],
        "feed/Feed",
        "feed/Entry",
        "feed/Writer"
    );

    setup_unstable_lib(rosella, "terminal", ["Core"],
        "terminal/Includes",
        "terminal/Terminal",
        "terminal/Decorations"
    );
}

function setup_utilities(var rosella)
{
    var utilities = {
        "winxed_repl" : {
            "install_name" : "winxed_repl",
            "includes" : ["Core", "Repl"]
        },
        "test_all_lib" : {
            "install_name" : "rosella_test_all_lib",
            "includes" : ["Core", "FileSystem", "String", "Template", "CommandLine", "Query", "Reflect"]
        },
        "test_template" : {
            "install_name" : "rosella_test_template",
            "includes" : ["Core", "FileSystem", "Template", "CommandLine", "Query", "Reflect"]
        },
        "mk_winxed_header" : {
            "install_name" : "winxed_mk_header",
            "includes" : ["Core", "FileSystem", "CommandLine", "Query", "Reflect"]
        },
        "harness" : {
            "install_name" : "rosella_harness",
            "includes" : ["Core", "Harness"]
        },
        "parrot_release" : {
            "install_name" : "parrot_release",
            "includes" : ["Core", "FileSystem", "Template", "String", "Query", "Date"]
        },
        "templatecc" : {
            "install_name" : "rosella_templatecc",
            "includes" : ["Core", "CommandLine", "Template"]
        },
        "rosella_doc" : {
            "install_name" : "rosella_doc",
            "includes" : ["Core", "CommandLine", "FileSystem", "Query", "Reflect"]
        },
        "dump_pbc" : {
            "install_name" : "rosella_dump_pbc",
            "includes" : ["Core", "FileSystem", "String", "CommandLine", "Query", "Reflect"]
        }
    };
    string src_prefix = "src/utilities/";
    string dest_prefix = "rosella/";
    for (string util_source in utilities) {
        string src_file = src_prefix + util_source + ".winxed";
        string dest_file_base = string(utilities[util_source]["install_name"]);
        string winxed_file = dest_prefix + dest_file_base + ".winxed";
        string pir_file = dest_prefix + dest_file_base + ".pir";
        string pbc_file = dest_prefix + dest_file_base + ".pbc";

        var files = ["src/include/Builtins.winxed"];
        var includes = utilities[util_source]["includes"];
        for (string include in includes)
            push(files, "src/include/" + include + ".winxed");
        push(files, src_file);

        rosella["winxed_winxed"][winxed_file] = files;
        rosella["pir_winxed"][pir_file] = winxed_file;
        rosella["pbc_pir"][pbc_file] = pir_file;
        rosella["installable_pbc"][dest_file_base] = pbc_file;
    }
}

function setup_data_files(var rosella)
{
    rosella["inst_data"] = [
        "rosella/data/templates/test_class.nqp.template",
        "rosella/data/templates/test_class.winxed.template",
        "rosella/data/templates/test_ns.winxed.template",
        "rosella/data/templates/test_harness.nqp.template",
        "rosella/data/templates/test_harness.winxed.template",
        "rosella/data/templates/release_directions.template",
        "rosella/data/templates/release.json.template",
        "rosella/data/templates/release_announce.txt.template",
        "rosella/data/templates/release_announce.html.template",
        "rosella/data/templates/release_announce.md.template"
    ];
}

function setup_include_headers(var rosella)
{
    rosella["inst_wxheader"] = {
        "src/include/Action.winxed" : "Rosella/Action.winxed",
        "src/include/Ascii.winxed" : "Rosella/Ascii.winxed",
        "src/include/Builtins.winxed" : "Rosella/Builtins.winxed",
        "src/include/CommandLine.winxed" : "Rosella/CommandLine.winxed",
        "src/include/Container.winxed" : "Rosella/Container.winxed",
        "src/include/Core.winxed" : "Rosella/Core.winxed",
        "src/include/Dumper.winxed" : "Rosella/Dumper.winxed",
        "src/include/Event.winxed" : "Rosella/Event.winxed",
        "src/include/FileSystem.winxed" : "Rosella/FileSystem.winxed",
        "src/include/Genetic.winxed" : "Rosella/Genetic.winxed",
        "src/include/Harness.winxed" : "Rosella/Harness.winxed",
        "src/include/Json.winxed" : "Rosella/Json.winxed",
        "src/include/Math_Builtins.winxed" : "Rosella/Math_Builtins.winxed",
        "src/include/Memoize.winxed" : "Rosella/Memoize.winxed",
        "src/include/MockObject.winxed" : "Rosella/MockObject.winxed",
        "src/include/Net.winxed" : "Rosella/Net.winxed",
        "src/include/Parse.winxed" : "Rosella/Parse.winxed",
        "src/include/Parse_builtins.winxed" : "Rosella/Parse_builtins.winxed",
        "src/include/Proxy.winxed" : "Rosella/Proxy.winxed",
        "src/include/Path.winxed" : "Rosella/Path.winxed",
        "src/include/Query.winxed" : "Rosella/Query.winxed",
        "src/include/Random.winxed" : "Rosella/Random.winxed",
        "src/include/Repl.winxed" : "Rosella/Repl.winxed",
        "src/include/String.winxed" : "Rosella/String.winxed",
        "src/include/Template.winxed" : "Rosella/Template.winxed",
        "src/include/Test.winxed" : "Rosella/Test.winxed",
        "src/include/Winxed.winxed" : "Rosella/Winxed.winxed"
    };
}

function setup_winxed_lib(var rosella, string name, var includes, var files [slurpy],
        var named [slurpy,named])
{
    setup_lib_internal(rosella, name, "src/", includes, files, named);
}

function setup_unstable_lib(var rosella, string name, var includes, var files [slurpy],
        var named [slurpy,named])
{
    setup_lib_internal(rosella, name, "src/unstable/", includes, files, named);
}

function setup_lib_internal(var rosella, string name, string prefix,
        var includes, var files_raw, var named)
{
    var pir_files = [];
    setup_lib_constants(rosella, name, prefix, named);

    // Get a list of all files
    var files = ["src/include/Builtins.winxed"];
    for (string include in includes)
        push(files, "src/include/" + include + ".winxed");
    for (string file in files_raw)
        push(files, prefix + file + ".winxed");

    string winxed_master = "rosella/" + name + ".winxed";
    string pbc_lib_name = "rosella/" + name + ".pbc";
    string pir_lib_name = "rosella/" + name + ".pir";
    rosella["winxed_winxed"][winxed_master] = files;
    rosella["pir_winxed"][pir_lib_name] = winxed_master;
    rosella["pbc_pir"][pbc_lib_name] = pir_lib_name;
    rosella["inst_lib"].push(pbc_lib_name);
    rosella["manifest_includes"].push(pir_lib_name);
}

function setup_lib_constants(var rosella, string name, string prefix, var args)
{
    var constants_files = args["constants"];
    if (constants_files == null || elements(constants_files) == 0)
        return;
    for (string constant_file in constants_files) {
        string pasm_file = sprintf("%s%s.pasm", [prefix, constant_file]);
        string winxed_file = sprintf("%s%s.winxed", [prefix, constant_file]);
        rosella["include_winxed"][pasm_file] = winxed_file;
    }
}



// Load in the distutils library, which we are also responsible for
// building. If we don't have a version handy, load in the bootstrapping
// version. If we do have one built, use that instead
function setup_distutils()
{
    #int e = 0;
    #string distutils = "rosella/winxed.pbc";
    #${ stat e, distutils, 0 };
    #if (e)
    # load_bytecode(distutils);
    #else {
    # say("Bootstrapping build with existing distutils library");
        load_bytecode("src/winxed/Distutils.bootstrap.pir");
    #}

    using Rosella.Winxed.Distutils.winxed_setup;
    winxed_setup();
    using register_step_before;
    using build_version_file;
    using clean_version_file;
    register_step_before("build", build_version_file);
    register_step_before("clean", clean_version_file);
}

// TODO: "build" first, before we test.
function do_test()
{
    using get_nqp;
    string nqp = "parrot-nqp"; //get_nqp();
    string cmd = nqp + " t/harness";
    int result;
    ${ spawnw result, cmd };
    return result;
}

function get_all_tests(var rosella, string path)
{
    loadlib("os");
    var os = new OS;
    int STAT_ISREG = 0x8000;
    int STAT_ISDIR = 0x4000;
    var contents_raw = os.readdir(path);

    for (string file in contents_raw) {
        string entry = path + "/" + file;
        var stat = os.stat(entry);
        int mode = stat[2];
        int isdir = 0;
        ${ band isdir, mode, STAT_ISDIR };
        int isfile = 0;
        ${ band isfile, mode, STAT_ISREG };
        if (file[0] == ".")
            continue;
        if (isfile == STAT_ISREG && is_test(entry))
            rosella["manifest_includes"].push(entry);

        if (isdir == STAT_ISDIR)
            get_all_tests(rosella, entry);
    }
}

function is_test(string path)
{
    int len = length(path);
    string ext = substr(path, len - 2);
    if (ext == ".t")
        return 1;
    else
        return 0;
}

function build_version_file(var rosella)
{
    using newer;
    using Rosella.Winxed.Distutils.make_path_for;

    string file = "src/_build/_versions.winxed";
    make_path_for(file);
    int e = 0;
    ${ stat e, file, 0 };
    if (!e || newer("VERSION", file))
        build_and_compile_version_file(rosella);
}

function clean_version_file(var rosella)
{
    string file = "src/_build/_versions.winxed";
    using unlink;
    int e = 0;
    ${ stat e, file, 0 };
    if (e) {
        say("unlink " + file);
        unlink(file);
    }
}

function build_and_compile_version_file(var rosella)
{
    print("Reading version information...");
    var verfile = new 'FileHandle';
    verfile.open('VERSION', 'r');
    string text = verfile.readall();
    verfile.close();
    var lines = split("\n", text);

    var code = new 'StringBuilder';
    string preamble = <<:
namespace Rosella { namespace __PRIVATE_Version
{
    // This file is automatically generated by setup.winxed.
    // DO NOT MODIFY THIS FILE YOURSELF
    // Seriously, it's a bad idea.
    function __GET_VERSION_HASH[anon]()
    {
        return {
:>>
;
    push(code, preamble);

    for (string line in lines) {
        var parts = split(': ', line);
        if (elements(parts) != 2)
            continue;
        string libname = parts[0];
        parts = split(' ', parts[1]);
        push(code, sprintf(" '%s' : new Rosella.Version('%s', %s, '%s'),\n", [libname, libname, parts[0], parts[1]]));
    }
    string postamble = <<:
            "UNKNOWN" : new Rosella.Version('UNKNOWN', -1, 'UNKNOWN')
        };
    }
}}
:>>
;
    push(code, postamble);

    var file = new 'FileHandle';
    file.open("src/_build/_versions.winxed", "w");
    file.print(string(code));
    file.close();
    say("done.");
}

function main[main](var argv)
{
    int exit_code = 0;
    if (argv[1] == "test")
        do_test();
    else {
        try {
            setup_main(argv);
        } catch (e) {
            say(e["message"]);
            for (string bt in e.backtrace_strings())
                say(bt);
            exit_code = 1;
        }
    }
    if (exit_code != 0)
        exit(exit_code);
}
Something went wrong with that request. Please try again.