summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/notification
diff options
context:
space:
mode:
Diffstat (limited to 'base/common/src/com/netscape/certsrv/notification')
0 files changed, 0 insertions, 0 deletions
id='n269' href='#n269'>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 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
// file      : build2/install/rule.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <build2/install/rule>

#include <butl/filesystem> // dir_exists(), file_exists()

#include <build2/scope>
#include <build2/target>
#include <build2/algorithm>
#include <build2/filesystem>
#include <build2/diagnostics>

using namespace std;
using namespace butl;

namespace build2
{
  namespace install
  {
    // Lookup the install or install.* variable. Return NULL if not found or
    // if the value is the special 'false' name (which means do not install).
    // T is either scope or target.
    //
    template <typename P, typename T>
    static const P*
    lookup_install (T& t, const string& var)
    {
      auto l (t[var]);

      if (!l)
        return nullptr;

      const P& r (cast<P> (l));
      return r.simple () && r.string () == "false" ? nullptr : &r;
    }

    // alias_rule
    //
    match_result alias_rule::
    match (action, target&, const string&) const
    {
      return true;
    }

    recipe alias_rule::
    apply (action a, target& t) const
    {
      tracer trace ("install::alias_rule::apply");

      for (prerequisite p: group_prerequisites (t))
      {
        target& pt (search (p));

        // Check if this prerequisite is explicitly "not installable",
        // that is, there is the 'install' variable and its value is
        // false.
        //
        // At first, this might seem redundand since we could have let
        // the file_rule below take care of it. The nuance is this: this
        // prerequsite can be in a different subproject that hasn't loaded
        // the install module (and therefore has no file_rule registered).
        // The typical example would be the 'tests' subproject.
        //
        // Note: not the same as lookup() above.
        //
        auto l (pt["install"]);

        if (l && cast<path> (l).string () == "false")
        {
          l5 ([&]{trace << "ignoring " << pt;});
          continue;
        }

        build2::match (a, pt);
        t.prerequisite_targets.push_back (&pt);
      }

      return default_recipe;
    }

    // file_rule
    //
    struct match_data
    {
      bool install;
    };

    static_assert (sizeof (match_data) <= target::data_size,
                   "insufficient space");

    match_result file_rule::
    match (action a, target& t, const string&) const
    {
      // First determine if this target should be installed (called
      // "installable" for short).
      //
      match_data md {lookup_install<path> (t, "install") != nullptr};
      match_result mr (true);

      if (a.operation () == update_id)
      {
        // If this is the update pre-operation and the target is installable,
        // change the recipe action to (update, 0) (i.e., "unconditional
        // update") so that we don't get matched for its prerequisites.
        //
        if (md.install)
          mr.recipe_action = action (a.meta_operation (), update_id);
        else
          // Otherwise, signal that we don't match so that some other rule can
          // take care of it.
          //
          return false;
      }

      t.data (md); // Save the data in the target's auxilary storage.
      return mr;
    }

    target* file_rule::
    filter (action, target& t, prerequisite_member p) const
    {
      target& pt (p.search ());
      return pt.in (t.root_scope ()) ? &pt : nullptr;
    }

    recipe file_rule::
    apply (action a, target& t) const
    {
      match_data md (move (t.data<match_data> ()));
      t.clear_data (); // In case delegated-to rule also uses aux storage.

      if (!md.install) // Not installable.
        return noop_recipe;

      // Ok, if we are here, then this means:
      //
      // 1. This target is installable.
      // 2. The action is either
      //    a. (perform, [un]install, 0) or
      //    b. (*, update, [un]install)
      //
      // In both cases, the next step is to search, match, and collect all the
      // installable prerequisites.
      //
      // @@ Perhaps if [noinstall] will be handled by the
      // group_prerequisite_members machinery, then we can just
      // run standard search_and_match()? Will need an indicator
      // that it was forced (e.g., [install]) for filter() below.
      //
      auto r (group_prerequisite_members (a, t));
      for (auto i (r.begin ()); i != r.end (); ++i)
      {
        prerequisite_member p (*i);

        // Ignore unresolved targets that are imported from other projects.
        // We are definitely not installing those.
        //
        if (p.proj () != nullptr)
          continue;

        // Let a customized rule have its say.
        //
        target* pt (filter (a, t, p));
        if (pt == nullptr)
          continue;

        // See if we were explicitly instructed not to touch this target.
        //
        auto l ((*pt)["install"]);
        if (l && cast<path> (l).string () == "false")
          continue;

        build2::match (a, *pt);

        // If the matched rule returned noop_recipe, then the target
        // state will be set to unchanged as an optimization. Use this
        // knowledge to optimize things on our side as well since this
        // will help a lot in case of any static installable content
        // (headers, documentation, etc).
        //
        if (pt->state () != target_state::unchanged)
          t.prerequisite_targets.push_back (pt);
        else
          unmatch (a, *pt); // No intent to execute.

        // Skip members of ad hoc groups. We handle them explicitly below.
        //
        if (pt->adhoc_group ())
          i.leave_group ();
      }

      // This is where we diverge depending on the operation. In the
      // update pre-operation, we need to make sure that this target
      // as well as all its installable prerequisites are up to date.
      //
      if (a.operation () == update_id)
      {
        // Save the prerequisite targets that we found since the
        // call to match_delegate() below will wipe them out.
        //
        target::prerequisite_targets_type p;

        if (!t.prerequisite_targets.empty ())
          p.swap (t.prerequisite_targets);

        // Find the "real" update rule, that is, the rule that would
        // have been found if we signalled that we do not match from
        // match() above.
        //
        recipe d (match_delegate (a, t, *this).first);

        // If we have no installable prerequisites, then simply redirect
        // to it.
        //
        if (p.empty ())
          return d;

        // Ok, the worst case scenario: we need to cause update of
        // prerequisite targets and also delegate to the real update.
        //
        return [pt = move (p), dr = move (d)]
          (action a, target& t) mutable -> target_state
        {
          // Do the target update first.
          //
          target_state r (execute_delegate (dr, a, t));

          // Swap our prerequisite targets back in and execute.
          //
          t.prerequisite_targets.swap (pt);
          r |= execute_prerequisites (a, t);
          pt.swap (t.prerequisite_targets); // In case we get re-executed.

          return r;
        };
      }
      else if (a.operation () == install_id)
        return [this] (action a, target& t) {return perform_install (a, t);};
      else
        return [this] (action a, target& t) {return perform_uninstall (a, t);};
    }

    void file_rule::
    install_extra (file&, const install_dir&) const {}

    bool file_rule::
    uninstall_extra (file&, const install_dir&) const {return false;}

    struct install_dir
    {
      dir_path dir;

      // If not NULL, then point to the corresponding install.* value.
      //
      const string*  sudo     = nullptr;
      const path*    cmd      = nullptr;
      const strings* options  = nullptr;
      const string*  mode     = nullptr;
      const string*  dir_mode = nullptr;

      explicit
      install_dir (dir_path d = dir_path ()): dir (move (d)) {}

      install_dir (dir_path d, const install_dir& b)
          : dir (move (d)),
            sudo (b.sudo),
            cmd (b.cmd),
            options (b.options),
            mode (b.mode),
            dir_mode (b.dir_mode) {}
    };

    using install_dirs = vector<install_dir>;

    // Calculate a subdirectory based on l's location (*.subdirs) and if not
    // empty add it to install_dirs. Return the new last element.
    //
    static install_dir&
    resolve_subdir (install_dirs& rs, target& t, scope& s, const lookup& l)
    {
      // Find the scope from which this value came and use as a base
      // to calculate the subdirectory.
      //
      for (const scope* p (&s); p != nullptr; p = p->parent_scope ())
      {
        if (l.belongs (*p)) // Ok since no target/type in lookup.
        {
          // The target can be in out or src.
          //
          const dir_path& d (t.out_dir ().leaf (p->out_path ()));

          // Add it as another leading directory rather than modifying
          // the last one directly; somehow, it feels right.
          //
          if (!d.empty ())
            rs.emplace_back (rs.back ().dir / d, rs.back ());
          break;
        }
      }

      return rs.back ();
    }

    // Resolve installation directory name to absolute directory path. Return
    // all the super-directories leading up to the destination (last).
    //
    static install_dirs
    resolve (target& t, dir_path d, const string* var = nullptr)
    {
      install_dirs rs;

      if (d.absolute ())
        rs.emplace_back (move (d.normalize ()));
      else
      {
        // If it is relative, then the first component is treated as the