aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2018-01-23 06:50:24 -0800
committerRobert Schumacher <roschuma@microsoft.com>2018-01-23 06:50:24 -0800
commit3beeb94ec5ca73636d1a26bd9c2ec386b15df9b7 (patch)
tree0f898d0b59691705faf3138690c4090c7b81b860
parent18f44c353d369b4da54cd7d352b9fba0fb911457 (diff)
downloadvcpkg-3beeb94ec5ca73636d1a26bd9c2ec386b15df9b7.tar.gz
vcpkg-3beeb94ec5ca73636d1a26bd9c2ec386b15df9b7.zip
[vcpkg] Use InstalledPackageView instead of unsorted raw vectors
-rw-r--r--toolsrc/include/vcpkg/dependencies.h8
-rw-r--r--toolsrc/include/vcpkg/remove.h4
-rw-r--r--toolsrc/include/vcpkg/statusparagraph.h15
-rw-r--r--toolsrc/include/vcpkg/statusparagraphs.h2
-rw-r--r--toolsrc/src/vcpkg/dependencies.cpp56
-rw-r--r--toolsrc/src/vcpkg/install.cpp5
-rw-r--r--toolsrc/src/vcpkg/remove.cpp39
-rw-r--r--toolsrc/src/vcpkg/statusparagraph.cpp12
-rw-r--r--toolsrc/src/vcpkg/statusparagraphs.cpp17
9 files changed, 92 insertions, 66 deletions
diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h
index 14f51c216..c3f00018d 100644
--- a/toolsrc/include/vcpkg/dependencies.h
+++ b/toolsrc/include/vcpkg/dependencies.h
@@ -38,7 +38,7 @@ namespace vcpkg::Dependencies
InstallPlanAction();
InstallPlanAction(const PackageSpec& spec,
- std::vector<const StatusParagraph*>&& spghs,
+ InstalledPackageView&& spghs,
const std::unordered_set<std::string>& features,
const RequestType& request_type);
@@ -52,7 +52,7 @@ namespace vcpkg::Dependencies
PackageSpec spec;
Optional<const SourceControlFile&> source_control_file;
- Optional<std::vector<const StatusParagraph*>> status_paragraphs;
+ Optional<InstalledPackageView> installed_package;
InstallPlanType plan_type;
RequestType request_type;
@@ -103,7 +103,7 @@ namespace vcpkg::Dependencies
ExportPlanAction();
ExportPlanAction(const PackageSpec& spec,
- std::vector<const StatusParagraph*>&& status_paragraphs,
+ InstalledPackageView&& installed_package,
const RequestType& request_type);
ExportPlanAction(const PackageSpec& spec, const RequestType& request_type);
@@ -116,7 +116,7 @@ namespace vcpkg::Dependencies
std::vector<PackageSpec> dependencies(const Triplet& triplet) const;
private:
- std::vector<const StatusParagraph*> m_spghs;
+ Optional<InstalledPackageView> m_installed_package;
};
struct PortFileProvider
diff --git a/toolsrc/include/vcpkg/remove.h b/toolsrc/include/vcpkg/remove.h
index 6d8a3ebe9..0610bd127 100644
--- a/toolsrc/include/vcpkg/remove.h
+++ b/toolsrc/include/vcpkg/remove.h
@@ -17,10 +17,10 @@ namespace vcpkg::Remove
void perform_remove_plan_action(const VcpkgPaths& paths,
const Dependencies::RemovePlanAction& action,
const Purge purge,
- StatusParagraphs& status_db);
+ const StatusParagraphs& status_db);
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet);
- void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db);
+ void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, const StatusParagraphs& status_db);
}
diff --git a/toolsrc/include/vcpkg/statusparagraph.h b/toolsrc/include/vcpkg/statusparagraph.h
index 051acf95f..0802de530 100644
--- a/toolsrc/include/vcpkg/statusparagraph.h
+++ b/toolsrc/include/vcpkg/statusparagraph.h
@@ -44,4 +44,19 @@ namespace vcpkg
std::string to_string(InstallState f);
std::string to_string(Want f);
+
+ struct InstalledPackageView
+ {
+ InstalledPackageView() : core(nullptr) {}
+
+ InstalledPackageView(const StatusParagraph* c, std::vector<const StatusParagraph*>&& fs)
+ : core(c), features(std::move(fs))
+ {
+ }
+
+ std::vector<PackageSpec> dependencies() const;
+
+ const StatusParagraph* core;
+ std::vector<const StatusParagraph*> features;
+ };
}
diff --git a/toolsrc/include/vcpkg/statusparagraphs.h b/toolsrc/include/vcpkg/statusparagraphs.h
index 4e31b48d8..fd33f8094 100644
--- a/toolsrc/include/vcpkg/statusparagraphs.h
+++ b/toolsrc/include/vcpkg/statusparagraphs.h
@@ -21,7 +21,7 @@ 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;
+ Optional<InstalledPackageView> find_all_installed(const PackageSpec& spec) const;
const_iterator find_installed(const PackageSpec& spec) const;
bool is_installed(const PackageSpec& spec) const;
diff --git a/toolsrc/src/vcpkg/dependencies.cpp b/toolsrc/src/vcpkg/dependencies.cpp
index 277de0557..5ce96a3e1 100644
--- a/toolsrc/src/vcpkg/dependencies.cpp
+++ b/toolsrc/src/vcpkg/dependencies.cpp
@@ -22,7 +22,8 @@ namespace vcpkg::Dependencies
struct Cluster : Util::MoveOnlyBase
{
- std::vector<StatusParagraph*> status_paragraphs;
+ InstalledPackageView installed_package;
+
Optional<const SourceControlFile*> source_control_file;
PackageSpec spec;
std::unordered_map<std::string, FeatureNodeEdges> edges;
@@ -103,17 +104,6 @@ namespace vcpkg::Dependencies
const PortFileProvider& m_provider;
};
- static std::vector<PackageSpec> source_paragraphs_dependencies(Span<const StatusParagraph* const> spghs)
- {
- if (spghs.size() == 0) return {};
-
- auto deps = Util::fmap_flatten(
- spghs, [](const StatusParagraph* pgh) -> std::vector<std::string> const& { return pgh->package.depends; });
-
- 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,
const CStringView s,
const Build::BuildPackageOptions& options)
@@ -153,16 +143,15 @@ namespace vcpkg::Dependencies
}
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
- std::vector<const StatusParagraph*>&& spghs,
+ InstalledPackageView&& ipv,
const std::unordered_set<std::string>& features,
const RequestType& request_type)
: spec(spec)
- , status_paragraphs(std::move(spghs))
+ , installed_package(std::move(ipv))
, plan_type(InstallPlanType::ALREADY_INSTALLED)
, request_type(request_type)
, feature_list(features)
{
- Checks::check_exit(VCPKG_LINE_INFO, status_paragraphs.get()->size() > 0);
}
std::string InstallPlanAction::displayname() const
@@ -213,12 +202,12 @@ namespace vcpkg::Dependencies
ExportPlanAction::ExportPlanAction() : plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
ExportPlanAction::ExportPlanAction(const PackageSpec& spec,
- std::vector<const StatusParagraph*>&& status_paragraphs,
+ InstalledPackageView&& installed_package,
const RequestType& request_type)
: spec(spec)
, plan_type(ExportPlanType::ALREADY_BUILT)
, request_type(request_type)
- , m_spghs(std::move(status_paragraphs))
+ , m_installed_package(std::move(installed_package))
{
}
@@ -229,14 +218,19 @@ namespace vcpkg::Dependencies
Optional<const BinaryParagraph&> ExportPlanAction::core_paragraph() const
{
- auto it = m_spghs.begin();
- if (it == m_spghs.end()) return nullopt;
- return (*it)->package;
+ if (auto p_ip = m_installed_package.get())
+ {
+ return p_ip->core->package;
+ }
+ return nullopt;
}
std::vector<PackageSpec> ExportPlanAction::dependencies(const Triplet&) const
{
- return source_paragraphs_dependencies(m_spghs);
+ if (auto p_ip = m_installed_package.get())
+ return p_ip->dependencies();
+ else
+ return {};
}
bool RemovePlanAction::compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right)
@@ -392,21 +386,15 @@ namespace vcpkg::Dependencies
? RequestType::USER_REQUESTED
: RequestType::AUTO_SELECTED;
- auto spghs = status_db.find_all_installed(spec);
+ auto maybe_ipv = status_db.find_all_installed(spec);
- if (spghs.size() == 0)
+ if (auto p_ipv = maybe_ipv.get())
{
- return ExportPlanAction{spec, request_type};
+ return ExportPlanAction{spec, std::move(*p_ipv), request_type};
}
else
{
- return ExportPlanAction{
- spec,
- Util::fmap(spghs,
- [](std::unique_ptr<StatusParagraph> const* const& p) -> const StatusParagraph* {
- return p->get();
- }),
- request_type};
+ return ExportPlanAction{spec, request_type};
}
}
@@ -629,7 +617,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()},
+ InstalledPackageView{p_cluster->installed_package},
p_cluster->original_features,
p_cluster->request_type,
});
@@ -658,12 +646,12 @@ namespace vcpkg::Dependencies
if (status_paragraph_feature.empty())
{
cluster.original_features.insert("core");
- cluster.status_paragraphs.emplace(cluster.status_paragraphs.begin(), status_paragraph);
+ cluster.installed_package.core = status_paragraph;
}
else
{
cluster.original_features.insert(status_paragraph_feature);
- cluster.status_paragraphs.emplace_back(status_paragraph);
+ cluster.installed_package.features.emplace_back(status_paragraph);
}
}
diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp
index 368ca6487..7a1ba4698 100644
--- a/toolsrc/src/vcpkg/install.cpp
+++ b/toolsrc/src/vcpkg/install.cpp
@@ -649,10 +649,9 @@ namespace vcpkg::Install
if (action)
if (auto p_install_plan = action->install_action.get())
{
- if (auto p_status = p_install_plan->status_paragraphs.get())
+ if (auto p_status = p_install_plan->installed_package.get())
{
- Checks::check_exit(VCPKG_LINE_INFO, p_status->size() > 0);
- return &(*p_status->begin())->package;
+ return &p_status->core->package;
}
}
return nullptr;
diff --git a/toolsrc/src/vcpkg/remove.cpp b/toolsrc/src/vcpkg/remove.cpp
index e03df2ed2..3815c3ce7 100644
--- a/toolsrc/src/vcpkg/remove.cpp
+++ b/toolsrc/src/vcpkg/remove.cpp
@@ -18,22 +18,31 @@ namespace vcpkg::Remove
using Dependencies::RequestType;
using Update::OutdatedPackage;
- void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db)
+ void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, const StatusParagraphs& status_db)
{
auto& fs = paths.get_filesystem();
- auto spghs = status_db->find_all(spec.name(), spec.triplet());
- const auto core_pkg = **status_db->find(spec.name(), spec.triplet(), "");
+ auto maybe_ipv = status_db.find_all_installed(spec);
+
+ Checks::check_exit(
+ VCPKG_LINE_INFO, maybe_ipv.has_value(), "unable to remove package %s: already removed", spec);
+
+ auto&& ipv = maybe_ipv.value_or_exit(VCPKG_LINE_INFO);
+
+ std::vector<StatusParagraph> spghs;
+ spghs.emplace_back(*ipv.core);
+ for (auto&& feature : ipv.features)
+ {
+ spghs.emplace_back(*feature);
+ }
for (auto&& spgh : spghs)
{
- StatusParagraph& pkg = **spgh;
- if (pkg.state != InstallState::INSTALLED) continue;
- pkg.want = Want::PURGE;
- pkg.state = InstallState::HALF_INSTALLED;
- write_update(paths, pkg);
+ spgh.want = Want::PURGE;
+ spgh.state = InstallState::HALF_INSTALLED;
+ write_update(paths, spgh);
}
- auto maybe_lines = fs.read_lines(paths.listfile_path(core_pkg.package));
+ auto maybe_lines = fs.read_lines(paths.listfile_path(ipv.core->package));
if (const auto lines = maybe_lines.get())
{
@@ -90,15 +99,13 @@ namespace vcpkg::Remove
}
}
- fs.remove(paths.listfile_path(core_pkg.package));
+ fs.remove(paths.listfile_path(ipv.core->package));
}
for (auto&& spgh : spghs)
{
- StatusParagraph& pkg = **spgh;
- if (pkg.state != InstallState::HALF_INSTALLED) continue;
- pkg.state = InstallState::NOT_INSTALLED;
- write_update(paths, pkg);
+ spgh.state = InstallState::NOT_INSTALLED;
+ write_update(paths, spgh);
}
}
@@ -136,7 +143,7 @@ namespace vcpkg::Remove
void perform_remove_plan_action(const VcpkgPaths& paths,
const RemovePlanAction& action,
const Purge purge,
- StatusParagraphs& status_db)
+ const StatusParagraphs& status_db)
{
const std::string display_name = action.spec.to_string();
@@ -147,7 +154,7 @@ namespace vcpkg::Remove
break;
case RemovePlanType::REMOVE:
System::println("Removing package %s... ", display_name);
- remove_package(paths, action.spec, &status_db);
+ remove_package(paths, action.spec, status_db);
System::println(System::Color::success, "Removing package %s... done", display_name);
break;
case RemovePlanType::UNKNOWN:
diff --git a/toolsrc/src/vcpkg/statusparagraph.cpp b/toolsrc/src/vcpkg/statusparagraph.cpp
index 5f00825e1..05238ba8b 100644
--- a/toolsrc/src/vcpkg/statusparagraph.cpp
+++ b/toolsrc/src/vcpkg/statusparagraph.cpp
@@ -1,5 +1,6 @@
#include "pch.h"
+#include <vcpkg/base/util.h>
#include <vcpkg/statusparagraph.h>
using namespace vcpkg::Parse;
@@ -83,4 +84,15 @@ namespace vcpkg
default: return "error";
}
}
+ std::vector<PackageSpec> InstalledPackageView::dependencies() const
+ {
+ auto deps = Util::fmap_flatten(features, [](const StatusParagraph* pgh) -> std::vector<std::string> const& {
+ return pgh->package.depends;
+ });
+
+ deps.insert(deps.end(), core->package.depends.begin(), core->package.depends.end());
+
+ auto&& spec = core->package.spec;
+ return PackageSpec::from_dependencies_of_port(spec.name(), deps, spec.triplet());
+ }
}
diff --git a/toolsrc/src/vcpkg/statusparagraphs.cpp b/toolsrc/src/vcpkg/statusparagraphs.cpp
index fb5267b95..475f86279 100644
--- a/toolsrc/src/vcpkg/statusparagraphs.cpp
+++ b/toolsrc/src/vcpkg/statusparagraphs.cpp
@@ -27,22 +27,27 @@ namespace vcpkg
return spghs;
}
- std::vector<const std::unique_ptr<StatusParagraph>*> StatusParagraphs::find_all_installed(
- const PackageSpec& spec) const
+ Optional<InstalledPackageView> StatusParagraphs::find_all_installed(const PackageSpec& spec) const
{
- std::vector<const std::unique_ptr<StatusParagraph>*> spghs;
+ InstalledPackageView ipv;
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);
+ {
+ Checks::check_exit(VCPKG_LINE_INFO, ipv.core == nullptr);
+ ipv.core = p.get();
+ }
else
- spghs.emplace_back(&p);
+ ipv.features.emplace_back(p.get());
}
}
- return spghs;
+ if (ipv.core != nullptr)
+ return std::move(ipv);
+ else
+ return nullopt;
}
StatusParagraphs::iterator StatusParagraphs::find(const std::string& name,