2017-01-27 12:49:09 -08:00
|
|
|
#include "pch.h"
|
2017-04-27 18:08:52 -07:00
|
|
|
|
2017-10-13 18:37:41 -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>
|
2016-09-21 23:51:45 -07:00
|
|
|
|
2017-10-13 18:37:41 -07:00
|
|
|
namespace vcpkg::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-12-13 05:43:00 -08:00
|
|
|
std::vector<OutdatedPackage> find_outdated_packages(const Dependencies::PortFileProvider& provider,
|
2017-11-11 19:47:56 -08:00
|
|
|
const StatusParagraphs& status_db)
|
2017-03-29 15:10:28 -07:00
|
|
|
{
|
2018-04-10 04:48:02 -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;
|
2018-04-10 04:48:02 -07:00
|
|
|
for (auto&& ipv : installed_packages)
|
2017-03-29 15:10:28 -07:00
|
|
|
{
|
2018-04-10 04:48:02 -07:00
|
|
|
const auto& pgh = ipv.core;
|
2017-12-13 05:43:00 -08:00
|
|
|
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
|
|
|
{
|
2017-12-13 05:43:00 -08:00
|
|
|
auto&& port_version = p_scf->core_paragraph->version;
|
|
|
|
auto&& installed_version = pgh->package.version;
|
|
|
|
if (installed_version != port_version)
|
|
|
|
{
|
2017-12-23 07:29:12 -08:00
|
|
|
output.push_back({pgh->package.spec, VersionDiff(installed_version, port_version)});
|
2017-12-13 05:43:00 -08:00
|
|
|
}
|
2017-03-29 15:10:28 -07:00
|
|
|
}
|
2017-12-13 05:43:00 -08:00
|
|
|
else
|
2017-03-29 15:10:28 -07:00
|
|
|
{
|
2017-12-13 05:43:00 -08: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
|
|
|
}
|
|
|
|
|
2017-11-02 15:20:42 -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)
|
2016-09-21 23:51:45 -07:00
|
|
|
{
|
2017-11-02 15:20:42 -07:00
|
|
|
args.parse_arguments(COMMAND_STRUCTURE);
|
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-12-13 05:43:00 -08:00
|
|
|
Dependencies::PathsPortFileProvider provider(paths);
|
|
|
|
|
|
|
|
const auto outdated_packages = SortedVector<OutdatedPackage>(find_outdated_packages(provider, 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
|
|
|
|
{
|
|
|
|
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-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-12-13 05:43:00 -08:00
|
|
|
"To update these packages and all dependencies, run\n"
|
|
|
|
" .\\vcpkg upgrade\n"
|
|
|
|
"\n"
|
|
|
|
"To only remove outdated packages, run\n"
|
|
|
|
" .\\vcpkg remove --outdated\n");
|
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
|
|
|
}
|
|
|
|
}
|