2017-01-27 12:49:09 -08:00
|
|
|
#include "pch.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
|
|
|
|
#include "Paragraphs.h"
|
2016-09-21 23:51:45 -07:00
|
|
|
#include "vcpkg_Commands.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
#include "vcpkg_System.h"
|
|
|
|
#include "vcpkglib.h"
|
2016-09-21 23:51:45 -07:00
|
|
|
|
2017-01-12 22:03:57 -08:00
|
|
|
namespace vcpkg::Commands::Update
|
2016-09-21 23:51:45 -07:00
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 -07:00
|
|
|
std::vector<OutdatedPackage> find_outdated_packages(const VcpkgPaths& paths, const StatusParagraphs& status_db)
|
2017-03-29 15:10:28 -07:00
|
|
|
{
|
2017-04-27 18:08:52 -07:00
|
|
|
const std::map<std::string, VersionT> src_names_to_versions =
|
2017-06-17 02:39:14 -07:00
|
|
|
Paragraphs::load_all_port_names_and_versions(paths.get_filesystem(), paths.ports);
|
2017-03-29 17:33:08 -07:00
|
|
|
const std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
|
|
|
|
|
2017-04-03 16:03:31 -07:00
|
|
|
std::vector<OutdatedPackage> output;
|
2017-03-29 17:33:08 -07:00
|
|
|
for (const StatusParagraph* pgh : installed_packages)
|
2017-03-29 15:10:28 -07:00
|
|
|
{
|
2017-09-14 04:04:15 -07:00
|
|
|
const auto it = src_names_to_versions.find(pgh->package.spec.name());
|
2017-03-29 15:10:28 -07:00
|
|
|
if (it == src_names_to_versions.end())
|
|
|
|
{
|
|
|
|
// Package was not installed from portfile
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (it->second != pgh->package.version)
|
|
|
|
{
|
2017-04-28 12:55:50 -07:00
|
|
|
output.push_back({pgh->package.spec, VersionDiff(pgh->package.version, it->second)});
|
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
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 -07:00
|
|
|
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
|
2016-09-21 23:51:45 -07:00
|
|
|
{
|
2016-09-30 11:24:04 -07:00
|
|
|
args.check_exact_arg_count(0);
|
2017-02-17 15:32:10 -08:00
|
|
|
args.check_and_get_optional_command_arguments({});
|
2016-09-29 11:50:31 -07:00
|
|
|
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);
|
2016-09-21 23:51:45 -07:00
|
|
|
|
2017-04-27 18:08:52 -07:00
|
|
|
const auto outdated_packages =
|
|
|
|
SortedVector<OutdatedPackage>(find_outdated_packages(paths, status_db), &OutdatedPackage::compare_by_name);
|
2016-09-21 23:51:45 -07:00
|
|
|
|
2017-03-29 17:33:08 -07:00
|
|
|
if (outdated_packages.empty())
|
2016-09-21 23:51:45 -07:00
|
|
|
{
|
|
|
|
System::println("No packages need updating.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-08 11:45:01 +02:00
|
|
|
std::string install_line;
|
2016-09-21 23:51:45 -07:00
|
|
|
System::println("The following packages differ from their port versions:");
|
2017-03-29 17:33:08 -07:00
|
|
|
for (auto&& package : outdated_packages)
|
2016-09-21 23:51:45 -07:00
|
|
|
{
|
2017-05-08 11:45:01 +02:00
|
|
|
install_line += package.spec.to_string();
|
|
|
|
install_line += " ";
|
2017-04-07 16:17:54 -07:00
|
|
|
System::println(" %-32s %s", package.spec, package.version_diff.to_string());
|
2016-09-21 23:51:45 -07:00
|
|
|
}
|
2017-04-04 12:58:34 -07:00
|
|
|
System::println("\n"
|
2017-04-27 18:08:52 -07:00
|
|
|
"To update these packages, run\n"
|
2017-05-04 09:29:17 +02:00
|
|
|
" .\\vcpkg remove --outdated\n"
|
2017-06-17 02:39:14 -07:00
|
|
|
" .\\vcpkg install " +
|
|
|
|
install_line);
|
2016-09-21 23:51:45 -07:00
|
|
|
}
|
|
|
|
|
2017-03-22 17:45:39 -07:00
|
|
|
Checks::exit_success(VCPKG_LINE_INFO);
|
2016-09-21 23:51:45 -07:00
|
|
|
}
|
|
|
|
}
|