| 3623 | emsg, changed); |
| 3624 | } |
| 3625 | static cm::optional<bool> ChangeRPathXCOFF(std::string const& file, |
| 3626 | std::string const& oldRPath, |
| 3627 | std::string const& newRPath, |
| 3628 | bool removeEnvironmentRPath, |
| 3629 | std::string* emsg, bool* changed) |
| 3630 | { |
| 3631 | if (changed) { |
| 3632 | *changed = false; |
| 3633 | } |
| 3634 | #if !defined(CMake_USE_XCOFF_PARSER) |
| 3635 | (void)file; |
| 3636 | (void)oldRPath; |
| 3637 | (void)newRPath; |
| 3638 | (void)removeEnvironmentRPath; |
| 3639 | (void)emsg; |
| 3640 | return cm::nullopt; |
| 3641 | #else |
| 3642 | bool chg = false; |
| 3643 | cmXCOFF xcoff(file.c_str(), cmXCOFF::Mode::ReadWrite); |
| 3644 | if (!xcoff) { |
| 3645 | return cm::nullopt; // Not a valid XCOFF file |
| 3646 | } |
| 3647 | if (cm::optional<cm::string_view> maybeLibPath = xcoff.GetLibPath()) { |
| 3648 | cm::string_view libPath = *maybeLibPath; |
| 3649 | // Make sure the current rpath contains the old rpath. |
| 3650 | std::string::size_type pos = cmSystemToolsFindRPath(libPath, oldRPath); |
| 3651 | if (pos == std::string::npos) { |
| 3652 | // If it contains the new rpath instead then it is okay. |
| 3653 | if (cmSystemToolsFindRPath(libPath, newRPath) != std::string::npos) { |
| 3654 | return true; |
| 3655 | } |
| 3656 | if (emsg) { |
| 3657 | std::ostringstream e; |
| 3658 | /* clang-format off */ |
| 3659 | e << "The current RPATH is:\n" |
| 3660 | " " << libPath << "\n" |
| 3661 | "which does not contain:\n" |
| 3662 | " " << oldRPath << "\n" |
| 3663 | "as was expected."; |
| 3664 | /* clang-format on */ |
| 3665 | *emsg = e.str(); |
| 3666 | } |
| 3667 | return false; |
| 3668 | } |
| 3669 | |
| 3670 | // The prefix is either empty or ends in a ':'. |
| 3671 | cm::string_view prefix = libPath.substr(0, pos); |
| 3672 | if (newRPath.empty() && !prefix.empty()) { |
| 3673 | prefix.remove_suffix(1); |
| 3674 | } |
| 3675 | |
| 3676 | // The suffix is either empty or starts in a ':'. |
| 3677 | cm::string_view suffix = libPath.substr(pos + oldRPath.length()); |
| 3678 | |
| 3679 | // Construct the new value which preserves the part of the path |
| 3680 | // not being changed. |
| 3681 | std::string newLibPath; |
| 3682 | if (!removeEnvironmentRPath) { |
no test coverage detected
searching dependent graphs…