mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-18 20:03:02 +08:00
[vcpkg] Remove AnyParagraph and InstallPlanType::INSTALL
This commit is contained in:
parent
10d712ed01
commit
ff8a2d1726
@ -23,23 +23,10 @@ namespace vcpkg::Dependencies
|
||||
const Build::BuildPackageOptions& options);
|
||||
std::string to_output_string(RequestType request_type, const CStringView s);
|
||||
|
||||
struct AnyParagraph
|
||||
{
|
||||
std::vector<PackageSpec> dependencies(const Triplet& triplet) const;
|
||||
|
||||
Optional<StatusParagraph> status_paragraph;
|
||||
Optional<BinaryControlFile> binary_control_file;
|
||||
Optional<const SourceControlFile&> source_control_file;
|
||||
};
|
||||
}
|
||||
|
||||
namespace vcpkg::Dependencies
|
||||
{
|
||||
enum class InstallPlanType
|
||||
{
|
||||
UNKNOWN,
|
||||
BUILD_AND_INSTALL,
|
||||
INSTALL,
|
||||
ALREADY_INSTALLED,
|
||||
EXCLUDED
|
||||
};
|
||||
@ -51,18 +38,22 @@ namespace vcpkg::Dependencies
|
||||
InstallPlanAction();
|
||||
|
||||
InstallPlanAction(const PackageSpec& spec,
|
||||
std::vector<const StatusParagraph*>&& spghs,
|
||||
const std::unordered_set<std::string>& features,
|
||||
const RequestType& request_type);
|
||||
InstallPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type);
|
||||
|
||||
InstallPlanAction(const PackageSpec& spec,
|
||||
const SourceControlFile& any_paragraph,
|
||||
const SourceControlFile& scf,
|
||||
const std::unordered_set<std::string>& features,
|
||||
const RequestType& request_type);
|
||||
|
||||
std::string displayname() const;
|
||||
|
||||
PackageSpec spec;
|
||||
AnyParagraph any_paragraph;
|
||||
|
||||
Optional<const SourceControlFile&> source_control_file;
|
||||
Optional<std::vector<const StatusParagraph*>> status_paragraphs;
|
||||
|
||||
InstallPlanType plan_type;
|
||||
RequestType request_type;
|
||||
Build::BuildPackageOptions build_options;
|
||||
@ -111,12 +102,21 @@ namespace vcpkg::Dependencies
|
||||
static bool compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right);
|
||||
|
||||
ExportPlanAction();
|
||||
ExportPlanAction(const PackageSpec& spec, const AnyParagraph& any_paragraph, const RequestType& request_type);
|
||||
ExportPlanAction(const PackageSpec& spec,
|
||||
std::vector<const StatusParagraph*>&& status_paragraphs,
|
||||
const RequestType& request_type);
|
||||
|
||||
ExportPlanAction(const PackageSpec& spec, const RequestType& request_type);
|
||||
|
||||
PackageSpec spec;
|
||||
AnyParagraph any_paragraph;
|
||||
ExportPlanType plan_type;
|
||||
RequestType request_type;
|
||||
|
||||
Optional<const BinaryParagraph&> core_paragraph() const;
|
||||
std::vector<PackageSpec> dependencies(const Triplet& triplet) const;
|
||||
|
||||
private:
|
||||
std::vector<const StatusParagraph*> m_spghs;
|
||||
};
|
||||
|
||||
struct PortFileProvider
|
||||
|
@ -21,6 +21,8 @@ namespace vcpkg
|
||||
|
||||
std::vector<std::unique_ptr<StatusParagraph>*> find_all(const std::string& name, const Triplet& triplet);
|
||||
|
||||
std::vector<const std::unique_ptr<StatusParagraph>*> find_all_installed(const PackageSpec& spec) const;
|
||||
|
||||
const_iterator find_installed(const PackageSpec& spec) const
|
||||
{
|
||||
return find_installed(spec.name(), spec.triplet());
|
||||
|
@ -41,7 +41,7 @@ namespace UnitTest1
|
||||
|
||||
Assert::AreEqual(plan.spec.triplet().to_string().c_str(), triplet.to_string().c_str());
|
||||
|
||||
Assert::AreEqual(pkg_name.c_str(), plan.any_paragraph.source_control_file.get()->core_paragraph->name.c_str());
|
||||
Assert::AreEqual(pkg_name.c_str(), plan.source_control_file.get()->core_paragraph->name.c_str());
|
||||
Assert::AreEqual(size_t(vec.size()), feature_list.size());
|
||||
|
||||
for (auto&& feature_name : vec)
|
||||
|
@ -13,7 +13,6 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
|
||||
{
|
||||
case Dependencies::InstallPlanType::ALREADY_INSTALLED: return L"ALREADY_INSTALLED";
|
||||
case Dependencies::InstallPlanType::BUILD_AND_INSTALL: return L"BUILD_AND_INSTALL";
|
||||
case Dependencies::InstallPlanType::INSTALL: return L"INSTALL";
|
||||
case Dependencies::InstallPlanType::EXCLUDED: return L"EXCLUDED";
|
||||
case Dependencies::InstallPlanType::UNKNOWN: return L"UNKNOWN";
|
||||
default: return ToString(static_cast<int>(t));
|
||||
|
@ -69,8 +69,7 @@ namespace vcpkg::Export::IFW
|
||||
{
|
||||
std::error_code ec;
|
||||
|
||||
const BinaryParagraph& binary_paragraph =
|
||||
action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph;
|
||||
const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO);
|
||||
|
||||
// Prepare meta dir
|
||||
const fs::path package_xml_file_path =
|
||||
@ -142,8 +141,7 @@ namespace vcpkg::Export::IFW
|
||||
for (auto package = unique_packages.begin(); package != unique_packages.end(); ++package)
|
||||
{
|
||||
const ExportPlanAction& action = *(package->second);
|
||||
const BinaryParagraph& binary_paragraph =
|
||||
action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph;
|
||||
const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO);
|
||||
|
||||
package_xml_file_path =
|
||||
raw_exported_dir_path / Strings::format("packages.%s", package->first) / "meta" / "package.xml";
|
||||
@ -436,8 +434,7 @@ namespace vcpkg::Export::IFW
|
||||
const std::string display_name = action.spec.to_string();
|
||||
System::println("Exporting package %s... ", display_name);
|
||||
|
||||
const BinaryParagraph& binary_paragraph =
|
||||
action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph;
|
||||
const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO);
|
||||
|
||||
unique_packages[action.spec.name()] = &action;
|
||||
unique_triplets.insert(action.spec.triplet().canonical_name());
|
||||
|
@ -103,28 +103,15 @@ namespace vcpkg::Dependencies
|
||||
const PortFileProvider& m_provider;
|
||||
};
|
||||
|
||||
std::vector<PackageSpec> AnyParagraph::dependencies(const Triplet& triplet) const
|
||||
static std::vector<PackageSpec> source_paragraphs_dependencies(Span<const StatusParagraph* const> spghs)
|
||||
{
|
||||
if (const auto p = this->status_paragraph.get())
|
||||
{
|
||||
return PackageSpec::from_dependencies_of_port(p->package.spec.name(), p->package.depends, triplet);
|
||||
}
|
||||
if (spghs.size() == 0) return {};
|
||||
|
||||
if (const auto p = this->binary_control_file.get())
|
||||
{
|
||||
auto deps = Util::fmap_flatten(p->features, [](const BinaryParagraph& pgh) { return pgh.depends; });
|
||||
deps.insert(deps.end(), p->core_paragraph.depends.cbegin(), p->core_paragraph.depends.cend());
|
||||
return PackageSpec::from_dependencies_of_port(p->core_paragraph.spec.name(), deps, triplet);
|
||||
}
|
||||
auto deps = Util::fmap_flatten(
|
||||
spghs, [](const StatusParagraph* pgh) -> std::vector<std::string> const& { return pgh->package.depends; });
|
||||
|
||||
if (const auto p = this->source_control_file.get())
|
||||
{
|
||||
return PackageSpec::from_dependencies_of_port(
|
||||
p->core_paragraph->name, filter_dependencies(p->core_paragraph->depends, triplet), triplet);
|
||||
}
|
||||
|
||||
Checks::exit_with_message(VCPKG_LINE_INFO,
|
||||
"Cannot get dependencies because there was none of: source/binary/status paragraphs");
|
||||
auto&& spec = spghs[0]->package.spec;
|
||||
return PackageSpec::from_dependencies_of_port(spec.name(), deps, spec.triplet());
|
||||
}
|
||||
|
||||
std::string to_output_string(RequestType request_type,
|
||||
@ -154,45 +141,28 @@ namespace vcpkg::Dependencies
|
||||
InstallPlanAction::InstallPlanAction() : plan_type(InstallPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
|
||||
|
||||
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
||||
const SourceControlFile& any_paragraph,
|
||||
const SourceControlFile& scf,
|
||||
const std::unordered_set<std::string>& features,
|
||||
const RequestType& request_type)
|
||||
: spec(spec), plan_type(InstallPlanType::BUILD_AND_INSTALL), request_type(request_type), feature_list(features)
|
||||
{
|
||||
this->any_paragraph.source_control_file = any_paragraph;
|
||||
}
|
||||
|
||||
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
||||
const std::unordered_set<std::string>& features,
|
||||
const RequestType& request_type)
|
||||
: spec(spec), plan_type(InstallPlanType::ALREADY_INSTALLED), request_type(request_type), feature_list(features)
|
||||
: spec(spec)
|
||||
, source_control_file(scf)
|
||||
, plan_type(InstallPlanType::BUILD_AND_INSTALL)
|
||||
, request_type(request_type)
|
||||
, feature_list(features)
|
||||
{
|
||||
}
|
||||
|
||||
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
|
||||
const AnyParagraph& any_paragraph,
|
||||
std::vector<const StatusParagraph*>&& spghs,
|
||||
const std::unordered_set<std::string>& features,
|
||||
const RequestType& request_type)
|
||||
: spec(spec), any_paragraph(any_paragraph), plan_type(InstallPlanType::UNKNOWN), request_type(request_type)
|
||||
: spec(spec)
|
||||
, status_paragraphs(std::move(spghs))
|
||||
, plan_type(InstallPlanType::ALREADY_INSTALLED)
|
||||
, request_type(request_type)
|
||||
, feature_list(features)
|
||||
{
|
||||
if (auto p = any_paragraph.status_paragraph.get())
|
||||
{
|
||||
this->plan_type = InstallPlanType::ALREADY_INSTALLED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto p = any_paragraph.binary_control_file.get())
|
||||
{
|
||||
this->plan_type = InstallPlanType::INSTALL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto p = any_paragraph.source_control_file.get())
|
||||
{
|
||||
this->plan_type = InstallPlanType::BUILD_AND_INSTALL;
|
||||
return;
|
||||
}
|
||||
|
||||
Checks::unreachable(VCPKG_LINE_INFO);
|
||||
Checks::check_exit(VCPKG_LINE_INFO, status_paragraphs.get()->size() > 0);
|
||||
}
|
||||
|
||||
std::string InstallPlanAction::displayname() const
|
||||
@ -243,21 +213,30 @@ namespace vcpkg::Dependencies
|
||||
ExportPlanAction::ExportPlanAction() : plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
|
||||
|
||||
ExportPlanAction::ExportPlanAction(const PackageSpec& spec,
|
||||
const AnyParagraph& any_paragraph,
|
||||
std::vector<const StatusParagraph*>&& status_paragraphs,
|
||||
const RequestType& request_type)
|
||||
: spec(spec), any_paragraph(any_paragraph), plan_type(ExportPlanType::UNKNOWN), request_type(request_type)
|
||||
: spec(spec)
|
||||
, plan_type(ExportPlanType::ALREADY_BUILT)
|
||||
, request_type(request_type)
|
||||
, m_spghs(std::move(status_paragraphs))
|
||||
{
|
||||
if (auto p = any_paragraph.binary_control_file.get())
|
||||
{
|
||||
this->plan_type = ExportPlanType::ALREADY_BUILT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto p = any_paragraph.source_control_file.get())
|
||||
{
|
||||
this->plan_type = ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT;
|
||||
return;
|
||||
}
|
||||
ExportPlanAction::ExportPlanAction(const PackageSpec& spec, const RequestType& request_type)
|
||||
: spec(spec), plan_type(ExportPlanType::PORT_AVAILABLE_BUT_NOT_BUILT), request_type(request_type)
|
||||
{
|
||||
}
|
||||
|
||||
Optional<const BinaryParagraph&> ExportPlanAction::core_paragraph() const
|
||||
{
|
||||
auto it = m_spghs.begin();
|
||||
if (it == m_spghs.end()) return nullopt;
|
||||
return (*it)->package;
|
||||
}
|
||||
|
||||
std::vector<PackageSpec> ExportPlanAction::dependencies(const Triplet&) const
|
||||
{
|
||||
return source_paragraphs_dependencies(m_spghs);
|
||||
}
|
||||
|
||||
bool RemovePlanAction::compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right)
|
||||
@ -404,7 +383,7 @@ namespace vcpkg::Dependencies
|
||||
|
||||
std::vector<PackageSpec> adjacency_list(const ExportPlanAction& plan) const override
|
||||
{
|
||||
return plan.any_paragraph.dependencies(plan.spec.triplet());
|
||||
return plan.dependencies(plan.spec.triplet());
|
||||
}
|
||||
|
||||
ExportPlanAction load_vertex_data(const PackageSpec& spec) const override
|
||||
@ -413,14 +392,22 @@ namespace vcpkg::Dependencies
|
||||
? RequestType::USER_REQUESTED
|
||||
: RequestType::AUTO_SELECTED;
|
||||
|
||||
Expected<BinaryControlFile> maybe_bpgh = Paragraphs::try_load_cached_control_package(paths, spec);
|
||||
if (auto bcf = maybe_bpgh.get())
|
||||
return ExportPlanAction{spec, AnyParagraph{nullopt, std::move(*bcf), nullopt}, request_type};
|
||||
auto spghs = status_db.find_all_installed(spec);
|
||||
|
||||
auto maybe_scf = provider.get_control_file(spec.name());
|
||||
if (auto scf = maybe_scf.get()) return ExportPlanAction{spec, {nullopt, nullopt, *scf}, request_type};
|
||||
|
||||
Checks::exit_with_message(VCPKG_LINE_INFO, "Could not find package %s", spec);
|
||||
if (spghs.size() == 0)
|
||||
{
|
||||
return ExportPlanAction{spec, request_type};
|
||||
}
|
||||
else
|
||||
{
|
||||
return ExportPlanAction{
|
||||
spec,
|
||||
Util::fmap(spghs,
|
||||
[](std::unique_ptr<StatusParagraph> const* const& p) -> const StatusParagraph* {
|
||||
return p->get();
|
||||
}),
|
||||
request_type};
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_string(const PackageSpec& spec) const override { return spec.to_string(); }
|
||||
@ -642,6 +629,7 @@ namespace vcpkg::Dependencies
|
||||
if (p_cluster->request_type != RequestType::USER_REQUESTED) continue;
|
||||
plan.emplace_back(InstallPlanAction{
|
||||
p_cluster->spec,
|
||||
{p_cluster->status_paragraphs.begin(), p_cluster->status_paragraphs.end()},
|
||||
p_cluster->original_features,
|
||||
p_cluster->request_type,
|
||||
});
|
||||
@ -664,17 +652,18 @@ namespace vcpkg::Dependencies
|
||||
|
||||
cluster.transient_uninstalled = false;
|
||||
|
||||
cluster.status_paragraphs.emplace_back(status_paragraph);
|
||||
|
||||
auto& status_paragraph_feature = status_paragraph->package.feature;
|
||||
|
||||
// In this case, empty string indicates the "core" paragraph for a package.
|
||||
if (status_paragraph_feature.empty())
|
||||
{
|
||||
cluster.original_features.insert("core");
|
||||
cluster.status_paragraphs.emplace(cluster.status_paragraphs.begin(), status_paragraph);
|
||||
}
|
||||
else
|
||||
{
|
||||
cluster.original_features.insert(status_paragraph_feature);
|
||||
cluster.status_paragraphs.emplace_back(status_paragraph);
|
||||
}
|
||||
}
|
||||
|
||||
@ -739,7 +728,6 @@ namespace vcpkg::Dependencies
|
||||
{
|
||||
switch (install_action->plan_type)
|
||||
{
|
||||
case InstallPlanType::INSTALL: only_install_plans.emplace_back(install_action); break;
|
||||
case InstallPlanType::ALREADY_INSTALLED:
|
||||
if (install_action->request_type == RequestType::USER_REQUESTED)
|
||||
already_installed_plans.emplace_back(install_action);
|
||||
|
@ -385,7 +385,7 @@ namespace vcpkg::Export
|
||||
" %s"
|
||||
"\n",
|
||||
cmake_variable.s);
|
||||
};
|
||||
}
|
||||
|
||||
static void handle_raw_based_export(Span<const ExportPlanAction> export_plan,
|
||||
const ExportArguments& opts,
|
||||
@ -410,8 +410,7 @@ namespace vcpkg::Export
|
||||
const std::string display_name = action.spec.to_string();
|
||||
System::println("Exporting package %s... ", display_name);
|
||||
|
||||
const BinaryParagraph& binary_paragraph =
|
||||
action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph;
|
||||
const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO);
|
||||
|
||||
const InstallDir dirs = InstallDir::from_destination_root(
|
||||
raw_exported_dir_path / "installed",
|
||||
|
@ -292,12 +292,11 @@ namespace vcpkg::Install
|
||||
System::println("Building package %s... ", display_name_with_features);
|
||||
|
||||
auto result = [&]() -> Build::ExtendedBuildResult {
|
||||
const Build::BuildPackageConfig build_config{
|
||||
action.any_paragraph.source_control_file.value_or_exit(VCPKG_LINE_INFO),
|
||||
action.spec.triplet(),
|
||||
paths.port_dir(action.spec),
|
||||
action.build_options,
|
||||
action.feature_list};
|
||||
const Build::BuildPackageConfig build_config{action.source_control_file.value_or_exit(VCPKG_LINE_INFO),
|
||||
action.spec.triplet(),
|
||||
paths.port_dir(action.spec),
|
||||
action.build_options,
|
||||
action.feature_list};
|
||||
return Build::build_package(paths, build_config, status_db);
|
||||
}();
|
||||
|
||||
@ -315,18 +314,6 @@ namespace vcpkg::Install
|
||||
return {code, std::move(bcf)};
|
||||
}
|
||||
|
||||
if (plan_type == InstallPlanType::INSTALL)
|
||||
{
|
||||
if (use_head_version && is_user_requested)
|
||||
{
|
||||
System::println(
|
||||
System::Color::warning, "Package %s is already built -- not building from HEAD", display_name);
|
||||
}
|
||||
auto code = aux_install(display_name_with_features,
|
||||
action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (plan_type == InstallPlanType::EXCLUDED)
|
||||
{
|
||||
System::println(System::Color::warning, "Package %s is excluded", display_name);
|
||||
@ -662,11 +649,10 @@ namespace vcpkg::Install
|
||||
if (action)
|
||||
if (auto p_install_plan = action->install_action.get())
|
||||
{
|
||||
if (auto p_bcf = p_install_plan->any_paragraph.binary_control_file.get())
|
||||
return &p_bcf->core_paragraph;
|
||||
else if (auto p_status = p_install_plan->any_paragraph.status_paragraph.get())
|
||||
if (auto p_status = p_install_plan->status_paragraphs.get())
|
||||
{
|
||||
return &p_status->package;
|
||||
Checks::check_exit(VCPKG_LINE_INFO, p_status->size() > 0);
|
||||
return &(*p_status->begin())->package;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -18,7 +18,28 @@ namespace vcpkg
|
||||
{
|
||||
if (p->package.spec.name() == name && p->package.spec.triplet() == triplet)
|
||||
{
|
||||
spghs.emplace_back(&p);
|
||||
if (p->package.feature.empty())
|
||||
spghs.emplace(spghs.begin(), &p);
|
||||
else
|
||||
spghs.emplace_back(&p);
|
||||
}
|
||||
}
|
||||
return spghs;
|
||||
}
|
||||
|
||||
std::vector<const std::unique_ptr<StatusParagraph>*> StatusParagraphs::find_all_installed(
|
||||
const PackageSpec& spec) const
|
||||
{
|
||||
std::vector<const std::unique_ptr<StatusParagraph>*> spghs;
|
||||
for (auto&& p : *this)
|
||||
{
|
||||
if (p->package.spec.name() == spec.name() && p->package.spec.triplet() == spec.triplet() &&
|
||||
p->is_installed())
|
||||
{
|
||||
if (p->package.feature.empty())
|
||||
spghs.emplace(spghs.begin(), &p);
|
||||
else
|
||||
spghs.emplace_back(&p);
|
||||
}
|
||||
}
|
||||
return spghs;
|
||||
|
Loading…
Reference in New Issue
Block a user