mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-28 11:21:12 +08:00
Improve x-ci-verify-versions
error messages (#15651)
* [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 * [x-ci-verify-versions] Improve error messages * Enable CI check for port_versions * Fix missing and extra line breaks. * Remove CI check
This commit is contained in:
parent
1515d080fe
commit
eb6655cac5
@ -15,6 +15,17 @@ namespace
|
|||||||
{
|
{
|
||||||
using namespace vcpkg;
|
using namespace vcpkg;
|
||||||
|
|
||||||
|
std::string get_scheme_name(Versions::Scheme scheme)
|
||||||
|
{
|
||||||
|
switch (scheme)
|
||||||
|
{
|
||||||
|
case Versions::Scheme::Relaxed: return "version";
|
||||||
|
case Versions::Scheme::Semver: return "version-semver";
|
||||||
|
case Versions::Scheme::String: return "version-string";
|
||||||
|
case Versions::Scheme::Date: return "version-date";
|
||||||
|
default: Checks::unreachable(VCPKG_LINE_INFO);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace vcpkg::Commands::CIVerifyVersions
|
namespace vcpkg::Commands::CIVerifyVersions
|
||||||
@ -52,8 +63,11 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (!maybe_versions.has_value())
|
if (!maybe_versions.has_value())
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format(
|
Strings::format("Error: While attempting to parse versions for port %s from file: %s\n"
|
||||||
"Error: Cannot parse `%s`.\n\t%s", fs::u8string(versions_file_path), maybe_versions.error()),
|
" Found the following error(s):\n%s",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
|
maybe_versions.error()),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -62,7 +76,10 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (versions.empty())
|
if (versions.empty())
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: File `%s` contains no versions.", fs::u8string(versions_file_path)),
|
Strings::format("Error: While reading versions for port %s from file: %s\n"
|
||||||
|
" File contains no versions.",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path)),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -83,9 +100,14 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (!maybe_scf.has_value())
|
if (!maybe_scf.has_value())
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Unable to parse `%s` used in version `%s`.\n%s\n",
|
Strings::format("Error: While reading versions for port %s from file: %s\n"
|
||||||
treeish,
|
" While validating version: %s.\n"
|
||||||
|
" While trying to load port from: %s\n"
|
||||||
|
" Found the following error(s):\n%s",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
version_entry.first.versiont,
|
version_entry.first.versiont,
|
||||||
|
treeish,
|
||||||
maybe_scf.error()->error),
|
maybe_scf.error()->error),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
@ -96,12 +118,16 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (version_entry.first.versiont != git_tree_version.versiont)
|
if (version_entry.first.versiont != git_tree_version.versiont)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Version in git-tree `%s` does not match version in file "
|
Strings::format(
|
||||||
"`%s`.\n\tgit-tree version: %s\n\t file version: %s\n",
|
"Error: While reading versions for port %s from file: %s\n"
|
||||||
version_entry.second,
|
" While validating version: %s.\n"
|
||||||
fs::u8string(versions_file_path),
|
" The version declared in file does not match checked-out version: %s\n"
|
||||||
git_tree_version.versiont,
|
" Checked out Git SHA: %s",
|
||||||
version_entry.first.versiont),
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
|
version_entry.first.versiont,
|
||||||
|
git_tree_version.versiont,
|
||||||
|
version_entry.second),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -112,11 +138,15 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (!version_ok)
|
if (!version_ok)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: The git-tree `%s` for version `%s` in `%s` does not contain a "
|
Strings::format(
|
||||||
"CONTROL file or vcpkg.json file.",
|
"Error: While reading versions for port %s from file: %s\n"
|
||||||
version_entry.second,
|
" While validating version: %s.\n"
|
||||||
version_entry.first.versiont,
|
" The checked-out object does not contain a CONTROL file or vcpkg.json file.\n"
|
||||||
fs::u8string(versions_file_path)),
|
" Checked out Git SHA: %s",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
|
version_entry.first.versiont,
|
||||||
|
version_entry.second),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -129,48 +159,87 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (!maybe_scf.has_value())
|
if (!maybe_scf.has_value())
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Cannot load port `%s`.\n\t%s", port_name, maybe_scf.error()->error),
|
Strings::format("Error: While attempting to load local port %s.\n"
|
||||||
|
" Found the following error(s):\n%s",
|
||||||
|
port_name,
|
||||||
|
maybe_scf.error()->error),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto found_version = maybe_scf.value_or_exit(VCPKG_LINE_INFO)->to_schemed_version();
|
const auto local_port_version = maybe_scf.value_or_exit(VCPKG_LINE_INFO)->to_schemed_version();
|
||||||
if (top_entry.first.versiont != found_version.versiont)
|
|
||||||
|
if (top_entry.first.versiont != local_port_version.versiont)
|
||||||
{
|
{
|
||||||
auto versions_end = versions.end();
|
auto versions_end = versions.end();
|
||||||
auto it = std::find_if(versions.begin(), versions_end, [&](auto&& entry) {
|
auto it = std::find_if(versions.begin(), versions_end, [&](auto&& entry) {
|
||||||
return entry.first.versiont == found_version.versiont;
|
return entry.first.versiont == local_port_version.versiont;
|
||||||
});
|
});
|
||||||
if (it != versions_end)
|
if (it != versions_end)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Version `%s` found but is not the top entry in `%s`.",
|
Strings::format("Error: While reading versions for port %s from file: %s\n"
|
||||||
found_version.versiont,
|
" Local port version `%s` exists in version file but it's not the first "
|
||||||
fs::u8string(versions_file_path)),
|
"entry in the \"versions\" array.",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
|
local_port_version.versiont),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Version `%s` not found in `%s`.",
|
Strings::format("Error: While reading versions for port %s from file: %s\n"
|
||||||
found_version.versiont,
|
" Version `%s` was not found in versions file.\n"
|
||||||
fs::u8string(versions_file_path)),
|
" Run:\n\n"
|
||||||
|
" vcpkg x-add-version %s\n\n"
|
||||||
|
" to add the new port version.",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
|
local_port_version.versiont,
|
||||||
|
port_name),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (top_entry.first.scheme != local_port_version.scheme)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
Strings::format("Error: While reading versions for port %s from file: %s\n"
|
||||||
|
" File declares version `%s` with scheme: `%s`.\n"
|
||||||
|
" But local port declares the same version with a different scheme: `%s`.\n"
|
||||||
|
" Version must be unique even between different schemes.\n"
|
||||||
|
" Run:\n\n"
|
||||||
|
" vcpkg x-add-version %s --overwrite-version\n\n"
|
||||||
|
" to overwrite the declared version's scheme.",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
|
top_entry.first.versiont,
|
||||||
|
get_scheme_name(top_entry.first.scheme),
|
||||||
|
get_scheme_name(local_port_version.scheme),
|
||||||
|
port_name),
|
||||||
|
expected_right_tag,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (local_git_tree != top_entry.second)
|
if (local_git_tree != top_entry.second)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Git tree-ish object for version `%s` in `%s` does not match local port files.\n"
|
Strings::format("Error: While reading versions for port %s from file: %s\n"
|
||||||
"\tLocal SHA: %s\n"
|
" File declares version `%s` with SHA: %s\n"
|
||||||
"\t File SHA: %s",
|
" But local port with the same verion has a differint SHA: %s\n"
|
||||||
found_version.versiont,
|
" This may be caused by locally commited changes to the port.\n"
|
||||||
|
" Run:\n\n"
|
||||||
|
" vcpkg x-add-version %s --overwrite-version\n\n"
|
||||||
|
" to overwrite the declared version's SHA.",
|
||||||
|
port_name,
|
||||||
fs::u8string(versions_file_path),
|
fs::u8string(versions_file_path),
|
||||||
|
top_entry.first.versiont,
|
||||||
local_git_tree,
|
local_git_tree,
|
||||||
top_entry.second),
|
top_entry.second,
|
||||||
|
port_name),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -179,7 +248,14 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (maybe_baseline == baseline.end())
|
if (maybe_baseline == baseline.end())
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: Couldn't find baseline version for port `%s`.", port_name),
|
Strings::format("Error: While reading baseline version for port %s.\n"
|
||||||
|
" Baseline version not found.\n"
|
||||||
|
" Run:\n\n"
|
||||||
|
" vcpkg x-add-version %s\n\n"
|
||||||
|
" to set version %s as the baseline version.",
|
||||||
|
port_name,
|
||||||
|
port_name,
|
||||||
|
local_port_version.versiont),
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -188,27 +264,18 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (baseline_version != top_entry.first.versiont)
|
if (baseline_version != top_entry.first.versiont)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Strings::format("Error: The baseline version for port `%s` doesn't match the latest version.\n"
|
Strings::format("Error: While reading baseline version for port %s.\n"
|
||||||
"\tBaseline version: %s\n"
|
" While validating latest version from file: %s\n"
|
||||||
"\t Latest version: %s (%s)",
|
" Baseline file declares version: %s.\n"
|
||||||
|
" But the latest version in version files is: %s.\n"
|
||||||
|
" Run:\n\n"
|
||||||
|
" vcpkg x-add-version %s\n\n"
|
||||||
|
" to update the baseline version.",
|
||||||
port_name,
|
port_name,
|
||||||
|
fs::u8string(versions_file_path),
|
||||||
baseline_version,
|
baseline_version,
|
||||||
top_entry.first.versiont,
|
top_entry.first.versiont,
|
||||||
fs::u8string(versions_file_path)),
|
port_name),
|
||||||
expected_right_tag,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (local_git_tree != top_entry.second)
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
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.versiont,
|
|
||||||
fs::u8string(versions_file_path),
|
|
||||||
local_git_tree,
|
|
||||||
top_entry.second),
|
|
||||||
expected_right_tag,
|
expected_right_tag,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -238,7 +305,7 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
auto maybe_port_git_tree_map = paths.git_get_local_port_treeish_map();
|
auto maybe_port_git_tree_map = paths.git_get_local_port_treeish_map();
|
||||||
Checks::check_exit(VCPKG_LINE_INFO,
|
Checks::check_exit(VCPKG_LINE_INFO,
|
||||||
maybe_port_git_tree_map.has_value(),
|
maybe_port_git_tree_map.has_value(),
|
||||||
"Error: Failed to obtain git treeish objects for local ports.\n%s",
|
"Fatal error: Failed to obtain git SHAs for local ports.\n%s",
|
||||||
maybe_port_git_tree_map.error());
|
maybe_port_git_tree_map.error());
|
||||||
auto port_git_tree_map = maybe_port_git_tree_map.value_or_exit(VCPKG_LINE_INFO);
|
auto port_git_tree_map = maybe_port_git_tree_map.value_or_exit(VCPKG_LINE_INFO);
|
||||||
|
|
||||||
@ -260,7 +327,17 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (git_tree_it == port_git_tree_map.end())
|
if (git_tree_it == port_git_tree_map.end())
|
||||||
{
|
{
|
||||||
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
||||||
errors.emplace(Strings::format("Error: Missing local git tree object for port `%s`.", port_name));
|
errors.emplace(Strings::format("Error: While validating port %s.\n"
|
||||||
|
" Missing Git SHA.\n"
|
||||||
|
" Run:\n\n"
|
||||||
|
" git add %s.\n"
|
||||||
|
" git commit -m \"[%s] Add new port\"\n"
|
||||||
|
" vcpkg x-add-version %s\n\n"
|
||||||
|
" to commit the new port and create its version file.",
|
||||||
|
port_name,
|
||||||
|
fs::u8string(port_path),
|
||||||
|
port_name,
|
||||||
|
port_name));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto git_tree = git_tree_it->second;
|
auto git_tree = git_tree_it->second;
|
||||||
@ -274,7 +351,9 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
{
|
{
|
||||||
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
||||||
errors.emplace(
|
errors.emplace(
|
||||||
Strings::format("Error: Both a manifest file and a CONTROL file exist in port directory: %s",
|
Strings::format("Error: While validating port %s.\n"
|
||||||
|
" Both a manifest file and a CONTROL file exist in port directory: %s",
|
||||||
|
port_name,
|
||||||
fs::u8string(port_path)));
|
fs::u8string(port_path)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -282,7 +361,9 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (!manifest_exists && !control_exists)
|
if (!manifest_exists && !control_exists)
|
||||||
{
|
{
|
||||||
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
||||||
errors.emplace(Strings::format("Error: No manifest file or CONTROL file exist in port directory: %s",
|
errors.emplace(Strings::format("Error: While validating port %s.\n"
|
||||||
|
" No manifest file or CONTROL file exist in port directory: %s",
|
||||||
|
port_name,
|
||||||
fs::u8string(port_path)));
|
fs::u8string(port_path)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -292,7 +373,8 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
if (!fs.exists(versions_file_path))
|
if (!fs.exists(versions_file_path))
|
||||||
{
|
{
|
||||||
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
System::printf(System::Color::error, "FAIL: %s\n", port_name);
|
||||||
errors.emplace(Strings::format("Error: Missing versions file for `%s`. Expected at `%s`.",
|
errors.emplace(Strings::format("Error: While validating port %s.\n"
|
||||||
|
" Missing expected versions file at: %s",
|
||||||
port_name,
|
port_name,
|
||||||
fs::u8string(versions_file_path)));
|
fs::u8string(versions_file_path)));
|
||||||
continue;
|
continue;
|
||||||
@ -318,6 +400,9 @@ namespace vcpkg::Commands::CIVerifyVersions
|
|||||||
{
|
{
|
||||||
System::printf(System::Color::error, "%s\n", error);
|
System::printf(System::Color::error, "%s\n", error);
|
||||||
}
|
}
|
||||||
|
System::print2(System::Color::error,
|
||||||
|
"\nTo attempt to resolve all erros at once, run:\n\n"
|
||||||
|
" vcpkg x-add-version --all --overwrite-versions\n\n");
|
||||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||||
}
|
}
|
||||||
Checks::exit_success(VCPKG_LINE_INFO);
|
Checks::exit_success(VCPKG_LINE_INFO);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user