2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2016-09-22 14:51:45 +08:00
|
|
|
#include "vcpkg_Commands.h"
|
2017-01-26 11:32:50 +08:00
|
|
|
#include "vcpkglib.h"
|
2016-09-22 14:51:45 +08:00
|
|
|
#include "vcpkg_System.h"
|
|
|
|
#include "vcpkg_Files.h"
|
2016-11-08 08:06:36 +08:00
|
|
|
#include "Paragraphs.h"
|
2016-09-22 14:51:45 +08:00
|
|
|
|
2017-01-13 14:03:57 +08:00
|
|
|
namespace vcpkg::Commands::Update
|
2016-09-22 14:51:45 +08:00
|
|
|
{
|
2017-03-30 09:14:48 +08:00
|
|
|
bool outdated_package::compare_by_name(const outdated_package& left, const outdated_package& right)
|
|
|
|
{
|
|
|
|
return left.spec.name() < right.spec.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<outdated_package> find_outdated_packages(const vcpkg_paths& paths, const StatusParagraphs& status_db)
|
2017-03-30 06:10:28 +08:00
|
|
|
{
|
2017-03-30 08:33:08 +08:00
|
|
|
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports);
|
|
|
|
const std::map<std::string, version_t> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
|
|
|
|
const std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
|
|
|
|
|
2017-03-30 09:14:48 +08:00
|
|
|
std::vector<outdated_package> output;
|
2017-03-30 08:33:08 +08:00
|
|
|
for (const StatusParagraph* pgh : installed_packages)
|
2017-03-30 06:10:28 +08:00
|
|
|
{
|
|
|
|
auto it = src_names_to_versions.find(pgh->package.spec.name());
|
|
|
|
if (it == src_names_to_versions.end())
|
|
|
|
{
|
|
|
|
// Package was not installed from portfile
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (it->second != pgh->package.version)
|
|
|
|
{
|
2017-03-30 09:14:48 +08:00
|
|
|
output.push_back({ pgh->package.spec, version_diff_t(pgh->package.version, it->second) });
|
2017-03-30 06:10:28 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-30 08:33:08 +08:00
|
|
|
|
|
|
|
return output;
|
2017-03-30 06:10:28 +08:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:03:57 +08:00
|
|
|
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
2016-09-22 14:51:45 +08:00
|
|
|
{
|
2016-10-01 02:24:04 +08:00
|
|
|
args.check_exact_arg_count(0);
|
2017-02-18 07:32:10 +08:00
|
|
|
args.check_and_get_optional_command_arguments({});
|
2016-09-30 02:50:31 +08:00
|
|
|
System::println("Using local portfile versions. To update the local portfiles, use `git pull`.");
|
|
|
|
|
2017-03-30 08:33:08 +08:00
|
|
|
const StatusParagraphs status_db = database_load_check(paths);
|
2016-09-22 14:51:45 +08:00
|
|
|
|
2017-04-01 18:30:52 +08:00
|
|
|
const auto outdated_packages = SortedVector<outdated_package>(find_outdated_packages(paths, status_db),
|
2017-03-30 09:14:48 +08:00
|
|
|
&outdated_package::compare_by_name);
|
2016-09-22 14:51:45 +08:00
|
|
|
|
2017-03-30 08:33:08 +08:00
|
|
|
if (outdated_packages.empty())
|
2016-09-22 14:51:45 +08:00
|
|
|
{
|
|
|
|
System::println("No packages need updating.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System::println("The following packages differ from their port versions:");
|
2017-03-30 08:33:08 +08:00
|
|
|
for (auto&& package : outdated_packages)
|
2016-09-22 14:51:45 +08:00
|
|
|
{
|
2017-04-01 18:58:45 +08:00
|
|
|
System::println(" %-32s %s", package.spec.display_name(), package.version_diff.toString());
|
2016-09-22 14:51:45 +08:00
|
|
|
}
|
|
|
|
System::println("\nTo update these packages, run\n vcpkg remove --purge <pkgs>...\n vcpkg install <pkgs>...");
|
|
|
|
}
|
|
|
|
|
2016-12-17 11:40:58 +08:00
|
|
|
auto version_file = Files::read_contents(paths.root / "toolsrc" / "VERSION.txt");
|
2016-09-22 14:51:45 +08:00
|
|
|
if (auto version_contents = version_file.get())
|
|
|
|
{
|
|
|
|
int maj1, min1, rev1;
|
|
|
|
auto num1 = sscanf_s(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1);
|
|
|
|
|
|
|
|
int maj2, min2, rev2;
|
2017-02-18 12:08:29 +08:00
|
|
|
auto num2 = sscanf_s(Version::version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2);
|
2016-09-22 14:51:45 +08:00
|
|
|
|
|
|
|
if (num1 == 3 && num2 == 3)
|
|
|
|
{
|
|
|
|
if (maj1 != maj2 || min1 != min2 || rev1 != rev2)
|
|
|
|
{
|
2017-04-01 18:58:45 +08:00
|
|
|
System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use bootstrap-vcpkg.bat to update.",
|
2016-09-22 14:51:45 +08:00
|
|
|
maj2, min2, rev2,
|
|
|
|
maj1, min1, rev1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 08:45:39 +08:00
|
|
|
Checks::exit_success(VCPKG_LINE_INFO);
|
2016-09-22 14:51:45 +08:00
|
|
|
}
|
|
|
|
}
|