87 lines
2.9 KiB
C++
Raw Normal View History

2017-01-27 12:49:09 -08:00
#include "pch.h"
2017-04-27 18:08:52 -07:00
#include <vcpkg/base/system.h>
#include <vcpkg/commands.h>
#include <vcpkg/help.h>
#include <vcpkg/paragraphs.h>
#include <vcpkg/update.h>
#include <vcpkg/vcpkglib.h>
namespace vcpkg::Update
{
2017-04-03 16:03:31 -07:00
bool OutdatedPackage::compare_by_name(const OutdatedPackage& left, const OutdatedPackage& right)
2017-03-29 18:14:48 -07:00
{
return left.spec.name() < right.spec.name();
}
std::vector<OutdatedPackage> find_outdated_packages(const Dependencies::PortFileProvider& provider,
const StatusParagraphs& status_db)
2017-03-29 15:10:28 -07:00
{
auto installed_packages = get_installed_ports(status_db);
2017-03-29 17:33:08 -07:00
2017-04-03 16:03:31 -07:00
std::vector<OutdatedPackage> output;
for (auto&& ipv : installed_packages)
2017-03-29 15:10:28 -07:00
{
const auto& pgh = ipv.core;
auto maybe_scf = provider.get_control_file(pgh->package.spec.name());
if (auto p_scf = maybe_scf.get())
2017-03-29 15:10:28 -07:00
{
auto&& port_version = p_scf->core_paragraph->version;
auto&& installed_version = pgh->package.version;
if (installed_version != port_version)
{
output.push_back({pgh->package.spec, VersionDiff(installed_version, port_version)});
}
2017-03-29 15:10:28 -07:00
}
else
2017-03-29 15:10:28 -07:00
{
// No portfile available
2017-03-29 15:10:28 -07:00
}
}
2017-03-29 17:33:08 -07:00
return output;
2017-03-29 15:10:28 -07:00
}
const CommandStructure COMMAND_STRUCTURE = {
Help::create_example_string("update"),
0,
0,
{},
nullptr,
};
2017-04-03 16:29:11 -07:00
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{
args.parse_arguments(COMMAND_STRUCTURE);
System::println("Using local portfile versions. To update the local portfiles, use `git pull`.");
2017-03-29 17:33:08 -07:00
const StatusParagraphs status_db = database_load_check(paths);
Dependencies::PathsPortFileProvider provider(paths);
const auto outdated_packages = SortedVector<OutdatedPackage>(find_outdated_packages(provider, status_db),
&OutdatedPackage::compare_by_name);
2017-03-29 17:33:08 -07:00
if (outdated_packages.empty())
{
System::println("No packages need updating.");
}
else
{
System::println("The following packages differ from their port versions:");
2017-03-29 17:33:08 -07:00
for (auto&& package : outdated_packages)
{
2017-04-07 16:17:54 -07:00
System::println(" %-32s %s", package.spec, package.version_diff.to_string());
}
System::println("\n"
"To update these packages and all dependencies, run\n"
" .\\vcpkg upgrade\n"
"\n"
"To only remove outdated packages, run\n"
" .\\vcpkg remove --outdated\n");
}
Checks::exit_success(VCPKG_LINE_INFO);
}
}