x-add-version: check version scheme format
* x-add-version: check version scheme format
One should use `version` or `version-date` instead of `version-string` if the version format fits
* Apply CR
* clang-format
* Add message.
MODIFY
azure-pipelines/end-to-end-tests-dir/versions.ps1
azure-pipelines/end-to-end-tests-dir/versions.ps1
@@ -57,7 +57,7 @@ $CurrentTest = "x-add-version fish (must fail)"
$out = Run-Vcpkg @portsRedirectArgsIncomplete x-add-version fish
Throw-IfNotFailed
$CurrentTest = "x-add-version fish --overwrite-version"
-Run-Vcpkg @portsRedirectArgsIncomplete x-add-version fish --overwrite-version
+Run-Vcpkg @portsRedirectArgsIncomplete x-add-version fish --overwrite-version --skip-version-format-check
Throw-IfFailed
$CurrentTest = "x-add-version mouse"

MODIFY
include/vcpkg/base/messages.h
include/vcpkg/base/messages.h
@@ -199,6 +199,8 @@ namespace vcpkg::msg
DECLARE_MSG_ARG(option, "editable");
DECLARE_MSG_ARG(expected_version, "1.3.8");
DECLARE_MSG_ARG(actual_version, "1.3.8");
+ DECLARE_MSG_ARG(new_scheme, "version");
+ DECLARE_MSG_ARG(old_scheme, "version-string");
#undef DECLARE_MSG_ARG
// These are `...` instead of

MODIFY
include/vcpkg/versions.h
include/vcpkg/versions.h
@@ -22,7 +22,7 @@ namespace vcpkg
// VersionMapLess is provided as a less than comparison for use in std::map.
friend struct VersionMapLess;
- const std::string text() const { return m_text; }
+ const std::string& text() const { return m_text; }
int port_version() const { return m_port_version; }
private:

MODIFY
locales/messages.en.json
locales/messages.en.json
"ProcessorArchitectureMissing": "The required environment variable %PROCESSOR_ARCHITECTURE% is missing.",
"ProcessorArchitectureW6432Malformed": "Failed to parse %PROCESSOR_ARCHITEW6432% ({arch}) as a valid CPU architecture. Falling back to %PROCESSOR_ARCHITECTURE%.",
"SeeURL": "See {url} for more information.",
+ "SuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".\nUse `--{option}` to disable this check.",
"UnsupportedSystemName": "Error: Could not map VCPKG_CMAKE_SYSTEM_NAME '{system_name}' to a vcvarsall platform. Supported system names are '', 'Windows' and 'WindowsStore'.",
"UnsupportedToolchain": "Error: in triplet {triplet}: Unable to find a valid toolchain combination.\n The requested target architecture was {arch}\n The selected Visual Studio instance is at {path}\n The available toolchain combinations are {list}\n",
"UsingManifestAt": "Using manifest file at {path}.",

MODIFY
locales/messages.json
locales/messages.json
"_ProcessorArchitectureW6432Malformed.comment": "example of {arch} is 'x64'.\n",
"SeeURL": "See {url} for more information.",
"_SeeURL.comment": "example of {url} is 'https://github.com/microsoft/vcpkg'.\n",
+ "SuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".\nUse `--{option}` to disable this check.",
+ "_SuggestNewVersionScheme.comment": "example of {new_scheme} is 'version'.\nexample of {old_scheme} is 'version-string'.\nexample of {package_name} is 'zlib'.\nexample of {option} is 'editable'.\n",
"UnsupportedSystemName": "Error: Could not map VCPKG_CMAKE_SYSTEM_NAME '{system_name}' to a vcvarsall platform. Supported system names are '', 'Windows' and 'WindowsStore'.",
"_UnsupportedSystemName.comment": "example of {system_name} is 'Darwin'.\n",
"UnsupportedToolchain": "Error: in triplet {triplet}: Unable to find a valid toolchain combination.\n The requested target architecture was {arch}\n The selected Visual Studio instance is at {path}\n The available toolchain combinations are {list}\n",

MODIFY
src/vcpkg/commands.add-version.cpp
src/vcpkg/commands.add-version.cpp
@@ -23,6 +23,18 @@ namespace
constexpr StringLiteral VERSION_DATE = "version-date";
constexpr StringLiteral VERSION_STRING = "version-string";
+ static constexpr StringLiteral OPTION_ALL = "all";
+ static constexpr StringLiteral OPTION_OVERWRITE_VERSION = "overwrite-version";
+ static constexpr StringLiteral OPTION_SKIP_FORMATTING_CHECK = "skip-formatting-check";
+ static constexpr StringLiteral OPTION_SKIP_VERSION_FORMAT_CHECK = "skip-version-format-check";
+ static constexpr StringLiteral OPTION_VERBOSE = "verbose";
+
+ DECLARE_AND_REGISTER_MESSAGE(SuggestNewVersionScheme,
+ (msg::new_scheme, msg::old_scheme, msg::package_name, msg::option),
+ "",
+ "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port "
+ "\"{package_name}\".\nUse `--{option}` to disable this check.");
+
using VersionGitTree = std::pair<SchemedVersion, std::string>;
void insert_version_to_json_object(Json::Object& obj, const Version& version, StringLiteral version_field)
@@ -55,6 +67,31 @@ namespace
Checks::unreachable(VCPKG_LINE_INFO);
}
+ void check_used_version_scheme(const SchemedVersion& version, const std::string& port_name)
+ {
+ if (version.scheme == VersionScheme::String)
+ {
+ if (DateVersion::try_parse(version.version.text()))
+ {
+ Checks::exit_with_message(VCPKG_LINE_INFO,
+ msgSuggestNewVersionScheme,
+ msg::new_scheme = VERSION_DATE,
+ msg::old_scheme = VERSION_STRING,
+ msg::package_name = port_name,
+ msg::option = OPTION_SKIP_VERSION_FORMAT_CHECK);
+ }
+ if (DotVersion::try_parse_relaxed(version.version.text()))
+ {
+ Checks::exit_with_message(VCPKG_LINE_INFO,
+ msgSuggestNewVersionScheme,
+ msg::new_scheme = VERSION_RELAXED,
+ msg::old_scheme = VERSION_STRING,
+ msg::package_name = port_name,
+ msg::option = OPTION_SKIP_VERSION_FORMAT_CHECK);
+ }
+ }
+ }
+
static Json::Object serialize_baseline(const std::map<std::string, Version, std::less<>>& baseline)
{
Json::Object port_entries_obj;
@@ -154,11 +191,16 @@ namespace
const Path& version_db_file_path,
bool overwrite_version,
bool print_success,
- bool keep_going)
+ bool keep_going,
+ bool skip_version_format_check)
{
auto& fs = paths.get_filesystem();
if (!fs.exists(version_db_file_path, VCPKG_LINE_INFO))
{
+ if (!skip_version_format_check)
+ {
+ check_used_version_scheme(port_version, port_name);
+ }
std::vector<VersionGitTree> new_entry{{port_version, git_tree}};
write_versions_file(fs, new_entry, version_db_file_path);
if (print_success)
@@ -236,6 +278,11 @@ namespace
versions->insert(versions->begin(), std::make_pair(port_version, git_tree));
}
+ if (!skip_version_format_check)
+ {
+ check_used_version_scheme(port_version, port_name);
+ }
+
write_versions_file(fs, *versions, version_db_file_path);
if (print_success)
{
@@ -255,15 +302,11 @@ namespace
namespace vcpkg::Commands::AddVersion
{
- static constexpr StringLiteral OPTION_ALL = "all";
- static constexpr StringLiteral OPTION_OVERWRITE_VERSION = "overwrite-version";
- static constexpr StringLiteral OPTION_SKIP_FORMATTING_CHECK = "skip-formatting-check";
- static constexpr StringLiteral OPTION_VERBOSE = "verbose";
-
const CommandSwitch COMMAND_SWITCHES[] = {
{OPTION_ALL, "Process versions for all ports."},
{OPTION_OVERWRITE_VERSION, "Overwrite `git-tree` of an existing version."},
{OPTION_SKIP_FORMATTING_CHECK, "Skips the formatting check of vcpkg.json files."},
+ {OPTION_SKIP_VERSION_FORMAT_CHECK, "Skips the version format check."},
{OPTION_VERBOSE, "Print success messages instead of just errors."},
};
@@ -281,6 +324,8 @@ namespace vcpkg::Commands::AddVersion
const bool add_all = Util::Sets::contains(parsed_args.switches, OPTION_ALL);
const bool overwrite_version = Util::Sets::contains(parsed_args.switches, OPTION_OVERWRITE_VERSION);
const bool skip_formatting_check = Util::Sets::contains(parsed_args.switches, OPTION_SKIP_FORMATTING_CHECK);
+ const bool skip_version_format_check =
+ Util::Sets::contains(parsed_args.switches, OPTION_SKIP_VERSION_FORMAT_CHECK);
const bool verbose = Util::Sets::contains(parsed_args.switches, OPTION_VERBOSE);
auto& fs = paths.get_filesystem();
@@ -383,8 +428,15 @@ namespace vcpkg::Commands::AddVersion
char prefix[] = {port_name[0], '-', '\0'};
auto port_versions_path = paths.builtin_registry_versions / prefix / Strings::concat(port_name, ".json");
- update_version_db_file(
- paths, port_name, schemed_version, git_tree, port_versions_path, overwrite_version, verbose, add_all);
+ update_version_db_file(paths,
+ port_name,
+ schemed_version,
+ git_tree,
+ port_versions_path,
+ overwrite_version,
+ verbose,
+ add_all,
+ skip_version_format_check);
update_baseline_version(paths, port_name, schemed_version.version, baseline_path, baseline_map, verbose);
}
Checks::exit_success(VCPKG_LINE_INFO);

x-add-version: check version scheme format (#352)

* x-add-version: check version scheme format

One should use `version` or `version-date` instead of `version-string` if the version format fits

* Apply CR

* clang-format

* Add message.

Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>