| 2104 | } |
| 2105 | |
| 2106 | bool cmFindPackageCommand::ReadPackage() |
| 2107 | { |
| 2108 | // Resolve any transitive dependencies for the root file. |
| 2109 | if (!FindPackageDependencies(this->FileFound, *this->CpsReader, |
| 2110 | this->Required)) { |
| 2111 | return false; |
| 2112 | } |
| 2113 | |
| 2114 | bool const hasComponentsRequested = |
| 2115 | !this->RequiredComponents.empty() || !this->OptionalComponents.empty(); |
| 2116 | |
| 2117 | cmMakefile::CallRAII cs{ this->Makefile, this->FileFound, this->Status }; |
| 2118 | cmMakefile::PolicyPushPop ps{ this->Makefile }; |
| 2119 | |
| 2120 | this->Makefile->SetPolicy(cmPolicies::CMP0200, cmPolicies::NEW); |
| 2121 | |
| 2122 | // Loop over appendices. |
| 2123 | auto iter = this->CpsAppendices.begin(); |
| 2124 | while (iter != this->CpsAppendices.end()) { |
| 2125 | RequiredStatus required = RequiredStatus::Optional; |
| 2126 | bool important = false; |
| 2127 | |
| 2128 | // Check if this appendix provides any requested components. |
| 2129 | if (hasComponentsRequested) { |
| 2130 | auto providesAny = [&iter]( |
| 2131 | std::set<std::string> const& desiredComponents) { |
| 2132 | return std::any_of(iter->second.Components.begin(), |
| 2133 | iter->second.Components.end(), |
| 2134 | [&desiredComponents](std::string const& component) { |
| 2135 | return cm::contains(desiredComponents, component); |
| 2136 | }); |
| 2137 | }; |
| 2138 | |
| 2139 | if (providesAny(this->RequiredComponents)) { |
| 2140 | important = true; |
| 2141 | required = this->Required; |
| 2142 | } else if (!providesAny(this->OptionalComponents)) { |
| 2143 | // This appendix doesn't provide any requested components; remove it |
| 2144 | // from the set to be imported. |
| 2145 | iter = this->CpsAppendices.erase(iter); |
| 2146 | continue; |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | // Resolve any transitive dependencies for the appendix. |
| 2151 | if (!this->FindPackageDependencies(iter->first, iter->second, required)) { |
| 2152 | if (important) { |
| 2153 | // Some dependencies are missing, and we need(ed) this appendix; fail. |
| 2154 | return false; |
| 2155 | } |
| 2156 | |
| 2157 | // Some dependencies are missing, but we don't need this appendix; remove |
| 2158 | // it from the set to be imported. |
| 2159 | iter = this->CpsAppendices.erase(iter); |
| 2160 | } else { |
| 2161 | ++iter; |
| 2162 | } |
| 2163 | } |
no test coverage detected