mirror of https://github.com/microsoft/vcpkg.git
Version_t
This commit is contained in:
parent
9b9a35fa38
commit
e074718209
|
|
@ -5,6 +5,7 @@
|
|||
#include "vcpkg_expected.h"
|
||||
#include "BinaryParagraph.h"
|
||||
#include "vcpkg_paths.h"
|
||||
#include "version_t.h"
|
||||
|
||||
namespace vcpkg::Paragraphs
|
||||
{
|
||||
|
|
@ -19,5 +20,5 @@ namespace vcpkg::Paragraphs
|
|||
|
||||
std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir);
|
||||
|
||||
std::map<std::string, std::string> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs);
|
||||
std::map<std::string, version_t> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
#include "pch.h"
|
||||
#include "version_t.h"
|
||||
#include "vcpkg_Strings.h"
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
version_t::version_t() : value("0.0.0") {}
|
||||
version_t::version_t(const std::string& value) : value(value) {}
|
||||
bool operator==(const version_t& left, const version_t& right) { return left.value == right.value; }
|
||||
bool operator!=(const version_t& left, const version_t& right) { return left.value != right.value; }
|
||||
std::string to_printf_arg(const version_t& version) { return version.value; }
|
||||
|
||||
version_diff_t::version_diff_t() : left(), right() {}
|
||||
version_diff_t::version_diff_t(const version_t& left, const version_t& right) : left(left), right(right) {}
|
||||
|
||||
std::string version_diff_t::toString() const
|
||||
{
|
||||
return Strings::format("%s -> %s", left.value, right.value);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
struct version_t
|
||||
{
|
||||
version_t();
|
||||
version_t(const std::string& value);
|
||||
|
||||
std::string value;
|
||||
};
|
||||
|
||||
bool operator ==(const version_t& left, const version_t& right);
|
||||
bool operator !=(const version_t& left, const version_t& right);
|
||||
std::string to_printf_arg(const version_t& version);
|
||||
|
||||
struct version_diff_t
|
||||
{
|
||||
version_t left;
|
||||
version_t right;
|
||||
|
||||
version_diff_t();
|
||||
version_diff_t(const version_t& left, const version_t& right);
|
||||
|
||||
std::string toString() const;
|
||||
};
|
||||
}
|
||||
|
|
@ -229,9 +229,9 @@ namespace vcpkg::Paragraphs
|
|||
return output;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs)
|
||||
std::map<std::string, version_t> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs)
|
||||
{
|
||||
std::map<std::string, std::string> names_and_versions;
|
||||
std::map<std::string, version_t> names_and_versions;
|
||||
for (const SourceParagraph& port : source_paragraphs)
|
||||
{
|
||||
names_and_versions.emplace(port.name, port.version);
|
||||
|
|
|
|||
|
|
@ -7,28 +7,28 @@
|
|||
|
||||
namespace vcpkg::Commands::PortsDiff
|
||||
{
|
||||
static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, const std::map<std::string, std::string>& names_and_versions)
|
||||
static void do_print_name_and_version(const std::vector<std::string>& ports_to_print, const std::map<std::string, version_t>& names_and_versions)
|
||||
{
|
||||
for (const std::string& name : ports_to_print)
|
||||
{
|
||||
const std::string& version = names_and_versions.at(name);
|
||||
const version_t& version = names_and_versions.at(name);
|
||||
System::println("%-20s %-16s", name, version);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_print_name_and_previous_version_and_current_version(const std::vector<std::string>& ports_to_print,
|
||||
const std::map<std::string, std::string>& previous_names_and_versions,
|
||||
const std::map<std::string, std::string>& current_names_and_versions)
|
||||
const std::map<std::string, version_t>& previous_names_and_versions,
|
||||
const std::map<std::string, version_t>& current_names_and_versions)
|
||||
{
|
||||
for (const std::string& name : ports_to_print)
|
||||
{
|
||||
const std::string& previous_version = previous_names_and_versions.at(name);
|
||||
const std::string& current_version = current_names_and_versions.at(name);
|
||||
const version_t& previous_version = previous_names_and_versions.at(name);
|
||||
const version_t& current_version = current_names_and_versions.at(name);
|
||||
System::println("%-20s %-16s -> %s", name, previous_version, current_version);
|
||||
}
|
||||
}
|
||||
|
||||
static std::map<std::string, std::string> read_ports_from_commit(const vcpkg_paths& paths, const std::wstring& git_commit_id)
|
||||
static std::map<std::string, version_t> read_ports_from_commit(const vcpkg_paths& paths, const std::wstring& git_commit_id)
|
||||
{
|
||||
const fs::path& git_exe = paths.get_git_exe();
|
||||
const fs::path dot_git_dir = paths.root / ".git";
|
||||
|
|
@ -47,7 +47,7 @@ namespace vcpkg::Commands::PortsDiff
|
|||
git_exe.native());
|
||||
System::cmd_execute_clean(cmd);
|
||||
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(temp_checkout_path / ports_dir_name_as_string);
|
||||
const std::map<std::string, std::string> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
|
||||
const std::map<std::string, version_t> names_and_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
|
||||
fs::remove_all(temp_checkout_path);
|
||||
return names_and_versions;
|
||||
}
|
||||
|
|
@ -76,8 +76,8 @@ namespace vcpkg::Commands::PortsDiff
|
|||
check_commit_exists(git_exe, git_commit_id_for_current_snapshot);
|
||||
check_commit_exists(git_exe, git_commit_id_for_previous_snapshot);
|
||||
|
||||
const std::map<std::string, std::string> current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot);
|
||||
const std::map<std::string, std::string> previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot);
|
||||
const std::map<std::string, version_t> current_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_current_snapshot);
|
||||
const std::map<std::string, version_t> previous_names_and_versions = read_ports_from_commit(paths, git_commit_id_for_previous_snapshot);
|
||||
|
||||
// Already sorted, so set_difference can work on std::vector too
|
||||
std::vector<std::string> current_ports = Maps::extract_keys(current_names_and_versions);
|
||||
|
|
|
|||
|
|
@ -7,16 +7,41 @@
|
|||
|
||||
namespace vcpkg::Commands::Update
|
||||
{
|
||||
std::map<std::string, version_diff_t> find_outdated_packages(const StatusParagraphs& status_db)
|
||||
{
|
||||
std::map<std::string, version_diff_t> output;
|
||||
for (auto&& pgh : status_db)
|
||||
{
|
||||
if (pgh->state == install_state_t::not_installed && pgh->want == want_t::purge)
|
||||
continue;
|
||||
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)
|
||||
{
|
||||
packages_output.push_back(Strings::format("%-27s %s -> %s",
|
||||
pgh->package.displayname(),
|
||||
pgh->package.version,
|
||||
it->second));
|
||||
packages_list.append(" " + pgh->package.displayname());
|
||||
}
|
||||
}
|
||||
std::sort(packages_output.begin(), packages_output.end());
|
||||
}
|
||||
|
||||
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
||||
{
|
||||
args.check_exact_arg_count(0);
|
||||
args.check_and_get_optional_command_arguments({});
|
||||
System::println("Using local portfile versions. To update the local portfiles, use `git pull`.");
|
||||
|
||||
auto status_db = database_load_check(paths);
|
||||
StatusParagraphs status_db = database_load_check(paths);
|
||||
|
||||
const std::vector<SourceParagraph> source_paragraphs = Paragraphs::load_all_ports(paths.ports);
|
||||
const std::map<std::string, std::string> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
|
||||
const std::map<std::string, version_t> src_names_to_versions = Paragraphs::extract_port_names_and_versions(source_paragraphs);
|
||||
|
||||
std::vector<StatusParagraph*> installed_packages = get_installed_ports(status_db);
|
||||
|
||||
|
|
|
|||
|
|
@ -179,8 +179,10 @@
|
|||
<ClInclude Include="..\include\vcpkg_Sets.h" />
|
||||
<ClInclude Include="..\include\vcpkg_Strings.h" />
|
||||
<ClInclude Include="..\include\vcpkg_System.h" />
|
||||
<ClInclude Include="..\include\version_t.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\include\version_t.cpp" />
|
||||
<ClCompile Include="..\src\BinaryParagraph.cpp" />
|
||||
<ClCompile Include="..\src\commands_ci.cpp" />
|
||||
<ClCompile Include="..\src\LineInfo.cpp" />
|
||||
|
|
|
|||
|
|
@ -174,6 +174,9 @@
|
|||
<ClCompile Include="..\src\paragraph_parse_result.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\include\version_t.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\package_spec.h">
|
||||
|
|
@ -305,5 +308,10 @@
|
|||
<ClInclude Include="..\include\cstring_view.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\version_t.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue