Skip to content

Commit

Permalink
[vcpkg] Change version field in baseline.json (microsoft#15633)
Browse files Browse the repository at this point in the history
* [vcpkg] Change version field in `baseline.json`

* Change name from `version-tag` to `baseline`

* [vcpkg] x-history serializes version scheme

* Update e2e tests

* Update baseline e2e test
  • Loading branch information
vicroms committed Jan 14, 2021
1 parent bb726c2 commit 5985c51
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 75 deletions.
4 changes: 2 additions & 2 deletions include/vcpkg/registries.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace vcpkg
std::unique_ptr<Json::IDeserializer<std::vector<Registry>>> get_registry_array_deserializer(
const fs::path& configuration_directory);

ExpectedS<std::vector<std::pair<VersionT, std::string>>> get_builtin_versions(const VcpkgPaths& paths,
StringView port_name);
ExpectedS<std::vector<std::pair<SchemedVersion, std::string>>> get_builtin_versions(const VcpkgPaths& paths,
StringView port_name);

ExpectedS<std::map<std::string, VersionT, std::less<>>> get_builtin_baseline(const VcpkgPaths& paths);
}
5 changes: 5 additions & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vcpkg/packagespec.h>
#include <vcpkg/paragraphparser.h>
#include <vcpkg/platform-expression.h>
#include <vcpkg/versiondeserializers.h>
#include <vcpkg/versions.h>

namespace vcpkg
Expand Down Expand Up @@ -107,6 +108,10 @@ namespace vcpkg
const FeatureFlagSettings& flags) const;

VersionT to_versiont() const { return core_paragraph->to_versiont(); }
SchemedVersion to_schemed_version() const
{
return SchemedVersion{core_paragraph->version_scheme, core_paragraph->to_versiont()};
}

friend bool operator==(const SourceControlFile& lhs, const SourceControlFile& rhs);
friend bool operator!=(const SourceControlFile& lhs, const SourceControlFile& rhs) { return !(lhs == rhs); }
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/versiondeserializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace vcpkg
{
Json::IDeserializer<VersionT>& get_versiont_deserializer_instance();
Json::IDeserializer<VersionT>& get_versiontag_deserializer_instance();
std::unique_ptr<Json::IDeserializer<std::string>> make_version_deserializer(StringLiteral type_name);

struct SchemedVersion
Expand Down
65 changes: 48 additions & 17 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,51 @@ using namespace vcpkg;

namespace
{
using VersionGitTree = std::pair<VersionT, std::string>;
constexpr StringLiteral BASELINE = "baseline";
constexpr StringLiteral VERSION_RELAXED = "version";
constexpr StringLiteral VERSION_SEMVER = "version-semver";
constexpr StringLiteral VERSION_DATE = "version-date";
constexpr StringLiteral VERSION_STRING = "version-string";

void insert_version_to_json_object(Json::Object& obj, const VersionT& version)
using VersionGitTree = std::pair<SchemedVersion, std::string>;

void insert_version_to_json_object(Json::Object& obj, const VersionT& version, StringLiteral version_field)
{
obj.insert("version-string", Json::Value::string(version.text()));
obj.insert(version_field, Json::Value::string(version.text()));
obj.insert("port-version", Json::Value::integer(version.port_version()));
}

void insert_schemed_version_to_json_object(Json::Object& obj, const SchemedVersion& version)
{
if (version.scheme == Versions::Scheme::Relaxed)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_RELAXED);
}

if (version.scheme == Versions::Scheme::Semver)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_SEMVER);
}

if (version.scheme == Versions::Scheme::Date)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_DATE);
}

if (version.scheme == Versions::Scheme::String)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_STRING);
}
Checks::unreachable(VCPKG_LINE_INFO);
}

static Json::Object serialize_baseline(const std::map<std::string, VersionT, std::less<>>& baseline)
{
Json::Object port_entries_obj;
for (auto&& kv_pair : baseline)
{
Json::Object baseline_version_obj;
insert_version_to_json_object(baseline_version_obj, kv_pair.second);
insert_version_to_json_object(baseline_version_obj, kv_pair.second, BASELINE);
port_entries_obj.insert(kv_pair.first, baseline_version_obj);
}

Expand All @@ -46,7 +76,7 @@ namespace
{
Json::Object version_obj;
version_obj.insert("git-tree", Json::Value::string(version.second));
insert_version_to_json_object(version_obj, version.first);
insert_schemed_version_to_json_object(version_obj, version.first);
versions_array.push_back(std::move(version_obj));
}

Expand Down Expand Up @@ -169,7 +199,7 @@ namespace

static void update_version_db_file(const VcpkgPaths& paths,
const std::string& port_name,
const VersionT& version,
const SchemedVersion& version,
const std::string& git_tree,
const fs::path& version_db_file_path,
bool overwrite_version,
Expand All @@ -185,7 +215,7 @@ namespace
{
System::printf(System::Color::success,
"Added version `%s` to `%s` (new file).\n",
version.to_string(),
version.versiont,
fs::u8string(version_db_file_path));
}
return;
Expand All @@ -200,13 +230,13 @@ namespace
versions->begin(), versions_end, [&](auto&& entry) -> bool { return entry.second == git_tree; });
if (found_same_sha != versions_end)
{
if (found_same_sha->first == version)
if (found_same_sha->first.versiont == version.versiont)
{
if (print_success)
{
System::printf(System::Color::success,
"Version `%s` is already in `%s`\n",
version.to_string(),
version.versiont,
fs::u8string(version_db_file_path));
}
return;
Expand All @@ -216,15 +246,16 @@ namespace
"-- SHA: %s\n"
"-- Did you remember to commit your changes?\n"
"***No files were updated.***\n",
found_same_sha->first.to_string(),
found_same_sha->first.versiont,
fs::u8string(version_db_file_path),
git_tree);
if (keep_going) return;
Checks::exit_fail(VCPKG_LINE_INFO);
}

auto it = std::find_if(
versions->begin(), versions_end, [&](auto&& entry) -> bool { return entry.first == version; });
auto it = std::find_if(versions->begin(), versions_end, [&](auto&& entry) -> bool {
return entry.first.versiont == version.versiont;
});

if (it != versions_end)
{
Expand All @@ -239,7 +270,7 @@ namespace
"-- Pass `--overwrite-version` to bypass this check.\n"
"***No files were updated.***\n",
port_name,
version.to_string(),
version.versiont,
it->second,
git_tree);
if (keep_going) return;
Expand All @@ -259,7 +290,7 @@ namespace
{
System::printf(System::Color::success,
"Added version `%s` to `%s`.\n",
version.to_string(),
version.versiont,
fs::u8string(version_db_file_path));
}
return;
Expand Down Expand Up @@ -352,7 +383,7 @@ namespace vcpkg::Commands::AddVersion
}

const auto& scf = maybe_scf.value_or_exit(VCPKG_LINE_INFO);
const auto& versiont = scf->to_versiont();
const auto& schemed_version = scf->to_schemed_version();

auto git_tree_it = git_tree_map.find(port_name);
if (git_tree_it == git_tree_map.end())
Expand All @@ -370,8 +401,8 @@ namespace vcpkg::Commands::AddVersion
auto port_versions_path =
paths.builtin_port_versions / Strings::concat(port_name[0], '-') / Strings::concat(port_name, ".json");
update_version_db_file(
paths, port_name, versiont, git_tree, port_versions_path, overwrite_version, verbose, add_all);
update_baseline_version(paths, port_name, versiont, baseline_path, verbose);
paths, port_name, schemed_version, git_tree, port_versions_path, overwrite_version, verbose, add_all);
update_baseline_version(paths, port_name, schemed_version.versiont, baseline_path, verbose);
}
Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
38 changes: 20 additions & 18 deletions src/vcpkg/commands.civerifyversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ namespace vcpkg::Commands::CIVerifyVersions
return {
Strings::format("Error: Unable to parse `%s` used in version `%s`.\n%s\n",
treeish,
version_entry.first.to_string(),
version_entry.first.versiont,
maybe_scf.error()->error),
expected_right_tag,
};
}

const auto& scf = maybe_scf.value_or_exit(VCPKG_LINE_INFO);
auto&& git_tree_version = scf.get()->to_versiont();
if (version_entry.first != git_tree_version)
auto&& git_tree_version = scf.get()->to_schemed_version();
if (version_entry.first.versiont != git_tree_version.versiont)
{
return {
Strings::format("Error: Version in git-tree `%s` does not match version in file "
"`%s`.\n\tgit-tree version: %s\n\t file version: %s\n",
version_entry.second,
fs::u8string(versions_file_path),
git_tree_version.to_string(),
version_entry.first.to_string()),
git_tree_version.versiont,
version_entry.first.versiont),
expected_right_tag,
};
}
Expand All @@ -115,7 +115,7 @@ namespace vcpkg::Commands::CIVerifyVersions
Strings::format("Error: The git-tree `%s` for version `%s` in `%s` does not contain a "
"CONTROL file or vcpkg.json file.",
version_entry.second,
version_entry.first,
version_entry.first.versiont,
fs::u8string(versions_file_path)),
expected_right_tag,
};
Expand All @@ -134,26 +134,28 @@ namespace vcpkg::Commands::CIVerifyVersions
};
}

const auto found_version = maybe_scf.value_or_exit(VCPKG_LINE_INFO)->to_versiont();
if (top_entry.first != found_version)
const auto found_version = maybe_scf.value_or_exit(VCPKG_LINE_INFO)->to_schemed_version();
if (top_entry.first.versiont != found_version.versiont)
{
auto versions_end = versions.end();
auto it = std::find_if(
versions.begin(), versions_end, [&](auto&& entry) { return entry.first == found_version; });
auto it = std::find_if(versions.begin(), versions_end, [&](auto&& entry) {
return entry.first.versiont == found_version.versiont;
});
if (it != versions_end)
{
return {
Strings::format("Error: Version `%s` found but is not the top entry in `%s`.",
found_version,
found_version.versiont,
fs::u8string(versions_file_path)),
expected_right_tag,
};
}
else
{
return {
Strings::format(
"Error: Version `%s` not found in `%s`.", found_version, fs::u8string(versions_file_path)),
Strings::format("Error: Version `%s` not found in `%s`.",
found_version.versiont,
fs::u8string(versions_file_path)),
expected_right_tag,
};
}
Expand All @@ -165,7 +167,7 @@ namespace vcpkg::Commands::CIVerifyVersions
Strings::format("Error: Git tree-ish object for version `%s` in `%s` does not match local port files.\n"
"\tLocal SHA: %s\n"
"\t File SHA: %s",
found_version,
found_version.versiont,
fs::u8string(versions_file_path),
local_git_tree,
top_entry.second),
Expand All @@ -183,15 +185,15 @@ namespace vcpkg::Commands::CIVerifyVersions
}

auto&& baseline_version = maybe_baseline->second;
if (baseline_version != top_entry.first)
if (baseline_version != top_entry.first.versiont)
{
return {
Strings::format("Error: The baseline version for port `%s` doesn't match the latest version.\n"
"\tBaseline version: %s\n"
"\t Latest version: %s (%s)",
port_name,
baseline_version,
top_entry.first,
top_entry.first.versiont,
fs::u8string(versions_file_path)),
expected_right_tag,
};
Expand All @@ -203,7 +205,7 @@ namespace vcpkg::Commands::CIVerifyVersions
Strings::format("Error: Git tree-ish object for version `%s` in `%s` does not match local port files.\n"
"\tLocal SHA: %s\n"
"\t File SHA: %s",
found_version,
found_version.versiont,
fs::u8string(versions_file_path),
local_git_tree,
top_entry.second),
Expand All @@ -212,7 +214,7 @@ namespace vcpkg::Commands::CIVerifyVersions
}

return {
Strings::format("OK: %s\t%s -> %s\n", top_entry.second, port_name, top_entry.first),
Strings::format("OK: %s\t%s -> %s\n", top_entry.second, port_name, top_entry.first.versiont),
expected_left_tag,
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/vcpkg/commands.porthistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace vcpkg::Commands::PortHistory
std::string version_string;
std::string version;
int port_version;
Versions::Scheme scheme;
};

const System::ExitCodeAndOutput run_git_command_inner(const VcpkgPaths& paths,
Expand Down Expand Up @@ -66,6 +67,7 @@ namespace vcpkg::Commands::PortHistory
{
auto version = scf->core_paragraph->version;
auto port_version = scf->core_paragraph->port_version;
auto scheme = scf->core_paragraph->version_scheme;
return HistoryVersion{
port_name,
git_tree,
Expand All @@ -74,6 +76,7 @@ namespace vcpkg::Commands::PortHistory
Strings::concat(version, "#", port_version),
version,
port_version,
scheme,
};
}
}
Expand Down Expand Up @@ -193,8 +196,7 @@ namespace vcpkg::Commands::PortHistory
Json::Object object;
object.insert("git-tree", Json::Value::string(version.git_tree));

serialize_schemed_version(
object, Versions::Scheme::String, version.version, version.port_version, true);
serialize_schemed_version(object, version.scheme, version.version, version.port_version, true);
versions_json.push_back(std::move(object));
}

Expand Down
10 changes: 6 additions & 4 deletions src/vcpkg/registries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ namespace
{
const auto& version_value = pr.second;
VersionT version;
r.visit_in_key(version_value, pr.first, version, get_versiont_deserializer_instance());
r.visit_in_key(version_value, pr.first, version, get_versiontag_deserializer_instance());

result.emplace(pr.first.to_string(), std::move(version));
}
Expand Down Expand Up @@ -964,15 +964,17 @@ namespace vcpkg
return true;
}

ExpectedS<std::vector<std::pair<VersionT, std::string>>> get_builtin_versions(const VcpkgPaths& paths,
StringView port_name)
ExpectedS<std::vector<std::pair<SchemedVersion, std::string>>> get_builtin_versions(const VcpkgPaths& paths,
StringView port_name)
{
auto maybe_versions =
load_versions_file(paths.get_filesystem(), VersionDbType::Git, paths.builtin_port_versions, port_name);
if (auto pversions = maybe_versions.get())
{
return Util::fmap(
*pversions, [](auto&& entry) -> auto { return std::make_pair(entry.version, entry.git_tree); });
*pversions, [](auto&& entry) -> auto {
return std::make_pair(SchemedVersion{entry.scheme, entry.version}, entry.git_tree);
});
}

return maybe_versions.error();
Expand Down
Loading

0 comments on commit 5985c51

Please sign in to comment.