From febde070ea83b69baad51c68a9dde0c76d44d309 Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Sat, 21 May 2022 23:48:23 +0200 Subject: [PATCH 1/8] [localization] localize binarycache --- src/vcpkg/binarycaching.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 39db0196da..afc330778a 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -105,6 +105,14 @@ namespace (msg::binary_source), "", "invalid argument: binary config '{binary_source}' requires 2 or 3 arguments"); + DECLARE_AND_REGISTER_MESSAGE(CompressFolderFailed, + (msg::path, msg::exit_code), + "", + "Failed to compress folder '{path}', exit code: {exit_code}"); + DECLARE_AND_REGISTER_MESSAGE(ErrorNoAbiDuringCI, + (msg::package_name), + "", + "package {package_name} did not have an abi during ci."); struct ConfigSegmentsParser : ParserBase { @@ -1087,8 +1095,8 @@ namespace paths.get_filesystem(), paths.get_tool_cache(), paths.package_dir(spec), tmp_archive_path); if (code != 0) { - vcpkg::print2( - Color::warning, "Failed to compress folder '", paths.package_dir(spec), "', exit code: ", code); + vcpkg::msg::print_warning(msgCompressFolderFailed, + msg::path = paths.package_dir(spec), msg::exit_code = code); return; } @@ -1463,10 +1471,14 @@ namespace vcpkg { auto& action = actions[idx]; const auto abi = action.package_abi().get(); - Checks::check_exit(VCPKG_LINE_INFO, - abi, - "Error: package %s did not have an abi during ci. This is an internal error.\n", - action.spec); + Checks::msg_check_exit(VCPKG_LINE_INFO, + abi, + msg::format(msg::msgInternalErrorMessage) + .append(msgErrorNoAbiDuringCI, + msg::package_name = action.spec + ).appendnl()); + + cache_status[idx] = &m_status[*abi]; } From 66096dafd18ada4e1fc8cf37349bd75e7024213f Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Sun, 22 May 2022 12:05:05 +0200 Subject: [PATCH 2/8] Localize edit command --- src/vcpkg/commands.edit.cpp | 46 +++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/vcpkg/commands.edit.cpp b/src/vcpkg/commands.edit.cpp index d1ffee9263..2f10bd2b46 100644 --- a/src/vcpkg/commands.edit.cpp +++ b/src/vcpkg/commands.edit.cpp @@ -11,6 +11,35 @@ #include +namespace +{ + using namespace vcpkg; + + DECLARE_AND_REGISTER_MESSAGE( + EnvStrFailedToExtract, + (), + "", + "could not expand the environment string:"); + + DECLARE_AND_REGISTER_MESSAGE( + ErrorVsCodeNotFound, + (msg::env_var), + "", + "Visual Studio Code was not found and the environment variable '{env_var}' is not set or invalid."); + + DECLARE_AND_REGISTER_MESSAGE( + ErrorVsCodeNotFoundPathExamined, + (), + "", + "The following paths were examined:"); + + DECLARE_AND_REGISTER_MESSAGE( + InfoSetEnvVar, + (msg::env_var), + "In this context 'editor' means IDE", + "You can also set the environment variable '{env_var}' to your editor of choice."); +} + #if defined(_WIN32) namespace { @@ -66,8 +95,11 @@ namespace ExpandEnvironmentStringsW(widened.c_str(), &result[0], static_cast(result.size() + 1)); if (required_size == 0) { - vcpkg::print2(vcpkg::Color::error, "Error: could not expand the environment string:\n"); - vcpkg::print2(vcpkg::Color::error, input); + msg::print_error( + msg::format(msg::msgErrorMessage) + .append(msgEnvStrFailedToExtract) + .appendnl() + .append(input)); vcpkg::Checks::exit_fail(VCPKG_LINE_INFO); } @@ -240,12 +272,12 @@ namespace vcpkg::Commands::Edit const auto it = Util::find_if(candidate_paths, [&](const Path& p) { return fs.exists(p, IgnoreErrors{}); }); if (it == candidate_paths.cend()) { - print2( - Color::error, - "Error: Visual Studio Code was not found and the environment variable EDITOR is not set or invalid.\n"); - print2("The following paths were examined:\n"); + msg::print_error(msg::format(msg::msgErrorMessage) + .append(msgErrorVsCodeNotFound, msg::env_var = "EDITOR") + .appendnl() + .append(msgErrorVsCodeNotFoundPathExamined)); print_paths(candidate_paths); - print2("You can also set the environmental variable EDITOR to your editor of choice.\n"); + msg::println(msgInfoSetEnvVar, msg::env_var = "EDITOR"); Checks::exit_fail(VCPKG_LINE_INFO); } From 644b75f51ef9492141d984a6f7612a74160c93d1 Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Sun, 22 May 2022 12:18:02 +0200 Subject: [PATCH 3/8] Revert binary cache --- include/vcpkg/base/messages.h | 10 ++++++++++ src/vcpkg/binarycaching.cpp | 16 ++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/vcpkg/base/messages.h b/include/vcpkg/base/messages.h index 258551a21e..55480cbc0f 100644 --- a/include/vcpkg/base/messages.h +++ b/include/vcpkg/base/messages.h @@ -340,4 +340,14 @@ namespace vcpkg::msg { print(Color::error, format(msgErrorMessage).append(format(m, args...).appendnl())); } + + inline void print_success(const LocalizedString& s) + { + print(Color::success, format(s).appendnl()); + } + template + typename Message::is_message_type print_success(Message m, Ts... args) + { + print(Color::success, format(format(m, args...).appendnl())); + } } diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index afc330778a..230a0171f5 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -109,10 +109,6 @@ namespace (msg::path, msg::exit_code), "", "Failed to compress folder '{path}', exit code: {exit_code}"); - DECLARE_AND_REGISTER_MESSAGE(ErrorNoAbiDuringCI, - (msg::package_name), - "", - "package {package_name} did not have an abi during ci."); struct ConfigSegmentsParser : ParserBase { @@ -1471,14 +1467,10 @@ namespace vcpkg { auto& action = actions[idx]; const auto abi = action.package_abi().get(); - Checks::msg_check_exit(VCPKG_LINE_INFO, - abi, - msg::format(msg::msgInternalErrorMessage) - .append(msgErrorNoAbiDuringCI, - msg::package_name = action.spec - ).appendnl()); - - + Checks::check_exit(VCPKG_LINE_INFO, + abi, + "Error: package %s did not have an abi during ci. This is an internal error.\n", + action.spec); cache_status[idx] = &m_status[*abi]; } From 978a431c571dcb2db64bc883f9a665790cb38b77 Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Sun, 22 May 2022 12:19:22 +0200 Subject: [PATCH 4/8] Revert print_success --- include/vcpkg/base/messages.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/vcpkg/base/messages.h b/include/vcpkg/base/messages.h index 55480cbc0f..258551a21e 100644 --- a/include/vcpkg/base/messages.h +++ b/include/vcpkg/base/messages.h @@ -340,14 +340,4 @@ namespace vcpkg::msg { print(Color::error, format(msgErrorMessage).append(format(m, args...).appendnl())); } - - inline void print_success(const LocalizedString& s) - { - print(Color::success, format(s).appendnl()); - } - template - typename Message::is_message_type print_success(Message m, Ts... args) - { - print(Color::success, format(format(m, args...).appendnl())); - } } From c305f62267299ce2a0be0fcfe1802cd0a4643724 Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Sun, 22 May 2022 12:36:33 +0200 Subject: [PATCH 5/8] Fix error --- src/vcpkg/commands.edit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcpkg/commands.edit.cpp b/src/vcpkg/commands.edit.cpp index 2f10bd2b46..cd47b167be 100644 --- a/src/vcpkg/commands.edit.cpp +++ b/src/vcpkg/commands.edit.cpp @@ -99,7 +99,7 @@ namespace msg::format(msg::msgErrorMessage) .append(msgEnvStrFailedToExtract) .appendnl() - .append(input)); + .append(LocalizedString::from_raw(input))); vcpkg::Checks::exit_fail(VCPKG_LINE_INFO); } From c1636a95de2896d0c60c2b227feab7eb61b67698 Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Sun, 22 May 2022 15:42:10 +0200 Subject: [PATCH 6/8] Apply patch --- locales/messages.en.json | 5 +++++ locales/messages.json | 8 ++++++++ src/vcpkg/binarycaching.cpp | 4 ++-- src/vcpkg/commands.edit.cpp | 32 +++++++++++--------------------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/locales/messages.en.json b/locales/messages.en.json index 560f140254..85247d18b6 100644 --- a/locales/messages.en.json +++ b/locales/messages.en.json @@ -67,6 +67,7 @@ "CiBaselineUnexpectedPass": "PASSING, REMOVE FROM FAIL LIST: {spec} ({path}).", "CmakeTargetsExcluded": "note: {count} additional targets are not displayed.", "CommandFailed": "command:\n{command_line}\nfailed with the following results:\n", + "CompressFolderFailed": "Failed to compress folder '{path}', exit code: {exit_code}", "CouldNotDeduceNugetIdAndVersion": "Could not deduce nuget id and version from filename: {path}", "CurlReportedUnexpectedResults": "curl has reported unexpected results to vcpkg and vcpkg cannot continue.\nPlease review the following text for sensitive information and open an issue on the Microsoft/vcpkg GitHub to help fix this problem!\ncmd: {command_line}\n=== curl output ===\n{actual}\n=== end curl output ===\n", "DownloadAvailable": "A downloadable copy of this tool is available and can be used by unsetting {env_var}.", @@ -75,6 +76,7 @@ "DownloadingVcpkgCeBundleLatest": "Downloading latest vcpkg-ce bundle...", "ElapsedForPackage": "Elapsed time to handle {spec}: {elapsed}", "EmptyLicenseExpression": "SPDX license expression was empty.", + "EnvStrFailedToExtract": "could not expand the environment string:", "ErrorIndividualPackagesUnsupported": "Error: In manifest mode, `vcpkg install` does not support individual package arguments.\nTo install additional packages, edit vcpkg.json and then run `vcpkg install` without any package arguments.", "ErrorInvalidClassicModeOption": "Error: The option --{option} is not supported in classic mode and no manifest was found.", "ErrorInvalidManifestModeOption": "Error: The option --{option} is not supported in manifest mode.", @@ -88,6 +90,8 @@ "ErrorRequirePackagesList": "Error: `vcpkg install` requires a list of packages to install in classic mode.", "ErrorRequirePackagesToInstall": "Error: No packages were listed for installation and no manifest was found.", "ErrorVcvarsUnsupported": "Error: in triplet {triplet}: Use of Visual Studio's Developer Prompt is unsupported on non-Windows hosts.\nDefine 'VCPKG_CMAKE_SYSTEM_NAME' or 'VCPKG_CHAINLOAD_TOOLCHAIN_FILE' in the triplet file.", + "ErrorVsCodeNotFound": "Visual Studio Code was not found and the environment variable '{env_var}' is not set or invalid.", + "ErrorVsCodeNotFoundPathExamined": "The following paths were examined:", "ExcludedPackage": "Excluded {spec}", "ExpectedCharacterHere": "expected '{expected}' here", "ExpectedFailOrSkip": "expected 'fail' or 'skip' here", @@ -112,6 +116,7 @@ "HeaderOnlyUsage": "{package_name} is header-only and can be used from CMake via:", "IllegalFeatures": "error: List of features is not allowed in this context", "IllegalPlatformSpec": "error: Platform qualifier is not allowed in this context", + "InfoSetEnvVar": "You can also set the environment variable '{env_var}' to your editor of choice.", "InstallWithSystemManager": "You may be able to install this tool via your system package manager.", "InstallWithSystemManagerMono": "Ubuntu 18.04 users may need a newer version of mono, available at {url}.", "InstallWithSystemManagerPkg": "You may be able to install this tool via your system package manager ({command_line}).", diff --git a/locales/messages.json b/locales/messages.json index c160e24fcf..6c3bae2ec9 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -123,6 +123,8 @@ "_CmakeTargetsExcluded.comment": "example of {count} is '42'.\n", "CommandFailed": "command:\n{command_line}\nfailed with the following results:\n", "_CommandFailed.comment": "example of {command_line} is 'vcpkg install zlib'.\n", + "CompressFolderFailed": "Failed to compress folder '{path}', exit code: {exit_code}", + "_CompressFolderFailed.comment": "example of {path} is '/foo/bar'.\nexample of {exit_code} is '127'.\n", "CouldNotDeduceNugetIdAndVersion": "Could not deduce nuget id and version from filename: {path}", "_CouldNotDeduceNugetIdAndVersion.comment": "example of {path} is '/foo/bar'.\n", "CurlReportedUnexpectedResults": "curl has reported unexpected results to vcpkg and vcpkg cannot continue.\nPlease review the following text for sensitive information and open an issue on the Microsoft/vcpkg GitHub to help fix this problem!\ncmd: {command_line}\n=== curl output ===\n{actual}\n=== end curl output ===\n", @@ -138,6 +140,7 @@ "ElapsedForPackage": "Elapsed time to handle {spec}: {elapsed}", "_ElapsedForPackage.comment": "example of {spec} is 'zlib:x64-windows'.\nexample of {elapsed} is '3.532 min'.\n", "EmptyLicenseExpression": "SPDX license expression was empty.", + "EnvStrFailedToExtract": "could not expand the environment string:", "ErrorIndividualPackagesUnsupported": "Error: In manifest mode, `vcpkg install` does not support individual package arguments.\nTo install additional packages, edit vcpkg.json and then run `vcpkg install` without any package arguments.", "ErrorInvalidClassicModeOption": "Error: The option --{option} is not supported in classic mode and no manifest was found.", "_ErrorInvalidClassicModeOption.comment": "example of {option} is 'editable'.\n", @@ -159,6 +162,9 @@ "ErrorRequirePackagesToInstall": "Error: No packages were listed for installation and no manifest was found.", "ErrorVcvarsUnsupported": "Error: in triplet {triplet}: Use of Visual Studio's Developer Prompt is unsupported on non-Windows hosts.\nDefine 'VCPKG_CMAKE_SYSTEM_NAME' or 'VCPKG_CHAINLOAD_TOOLCHAIN_FILE' in the triplet file.", "_ErrorVcvarsUnsupported.comment": "example of {triplet} is 'x64-windows'.\n", + "ErrorVsCodeNotFound": "Visual Studio Code was not found and the environment variable '{env_var}' is not set or invalid.", + "_ErrorVsCodeNotFound.comment": "example of {env_var} is 'VCPKG_DEFAULT_TRIPLET'.\n", + "ErrorVsCodeNotFoundPathExamined": "The following paths were examined:", "ExcludedPackage": "Excluded {spec}", "_ExcludedPackage.comment": "example of {spec} is 'zlib:x64-windows'.\n", "ExpectedCharacterHere": "expected '{expected}' here", @@ -195,6 +201,8 @@ "_HeaderOnlyUsage.comment": "'header' refers to C/C++ .h files\nexample of {package_name} is 'zlib'.\n", "IllegalFeatures": "error: List of features is not allowed in this context", "IllegalPlatformSpec": "error: Platform qualifier is not allowed in this context", + "InfoSetEnvVar": "You can also set the environment variable '{env_var}' to your editor of choice.", + "_InfoSetEnvVar.comment": "In this context 'editor' means IDE\nexample of {env_var} is 'VCPKG_DEFAULT_TRIPLET'.\n", "InstallWithSystemManager": "You may be able to install this tool via your system package manager.", "InstallWithSystemManagerMono": "Ubuntu 18.04 users may need a newer version of mono, available at {url}.", "_InstallWithSystemManagerMono.comment": "example of {url} is 'https://github.com/microsoft/vcpkg'.\n", diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 230a0171f5..46d4245688 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1091,8 +1091,8 @@ namespace paths.get_filesystem(), paths.get_tool_cache(), paths.package_dir(spec), tmp_archive_path); if (code != 0) { - vcpkg::msg::print_warning(msgCompressFolderFailed, - msg::path = paths.package_dir(spec), msg::exit_code = code); + vcpkg::msg::print_warning( + msgCompressFolderFailed, msg::path = paths.package_dir(spec), msg::exit_code = code); return; } diff --git a/src/vcpkg/commands.edit.cpp b/src/vcpkg/commands.edit.cpp index cd47b167be..3b9c23a350 100644 --- a/src/vcpkg/commands.edit.cpp +++ b/src/vcpkg/commands.edit.cpp @@ -15,29 +15,20 @@ namespace { using namespace vcpkg; - DECLARE_AND_REGISTER_MESSAGE( - EnvStrFailedToExtract, - (), - "", - "could not expand the environment string:"); - + DECLARE_AND_REGISTER_MESSAGE(EnvStrFailedToExtract, (), "", "could not expand the environment string:"); + DECLARE_AND_REGISTER_MESSAGE( ErrorVsCodeNotFound, (msg::env_var), "", "Visual Studio Code was not found and the environment variable '{env_var}' is not set or invalid."); - DECLARE_AND_REGISTER_MESSAGE( - ErrorVsCodeNotFoundPathExamined, - (), - "", - "The following paths were examined:"); + DECLARE_AND_REGISTER_MESSAGE(ErrorVsCodeNotFoundPathExamined, (), "", "The following paths were examined:"); - DECLARE_AND_REGISTER_MESSAGE( - InfoSetEnvVar, - (msg::env_var), - "In this context 'editor' means IDE", - "You can also set the environment variable '{env_var}' to your editor of choice."); + DECLARE_AND_REGISTER_MESSAGE(InfoSetEnvVar, + (msg::env_var), + "In this context 'editor' means IDE", + "You can also set the environment variable '{env_var}' to your editor of choice."); } #if defined(_WIN32) @@ -95,11 +86,10 @@ namespace ExpandEnvironmentStringsW(widened.c_str(), &result[0], static_cast(result.size() + 1)); if (required_size == 0) { - msg::print_error( - msg::format(msg::msgErrorMessage) - .append(msgEnvStrFailedToExtract) - .appendnl() - .append(LocalizedString::from_raw(input))); + msg::print_error(msg::format(msg::msgErrorMessage) + .append(msgEnvStrFailedToExtract) + .appendnl() + .append(LocalizedString::from_raw(input))); vcpkg::Checks::exit_fail(VCPKG_LINE_INFO); } From e2c0407aad2a15650aaa0ec3f4f50e4e7eb6e8a8 Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Mon, 23 May 2022 23:51:10 +0200 Subject: [PATCH 7/8] Fix error messages --- src/vcpkg/commands.edit.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/vcpkg/commands.edit.cpp b/src/vcpkg/commands.edit.cpp index 3b9c23a350..3f0da89932 100644 --- a/src/vcpkg/commands.edit.cpp +++ b/src/vcpkg/commands.edit.cpp @@ -86,10 +86,8 @@ namespace ExpandEnvironmentStringsW(widened.c_str(), &result[0], static_cast(result.size() + 1)); if (required_size == 0) { - msg::print_error(msg::format(msg::msgErrorMessage) - .append(msgEnvStrFailedToExtract) - .appendnl() - .append(LocalizedString::from_raw(input))); + msg::print_error( + msg::format(msgEnvStrFailedToExtract).appendnl().append(LocalizedString::from_raw(input))); vcpkg::Checks::exit_fail(VCPKG_LINE_INFO); } @@ -262,8 +260,7 @@ namespace vcpkg::Commands::Edit const auto it = Util::find_if(candidate_paths, [&](const Path& p) { return fs.exists(p, IgnoreErrors{}); }); if (it == candidate_paths.cend()) { - msg::print_error(msg::format(msg::msgErrorMessage) - .append(msgErrorVsCodeNotFound, msg::env_var = "EDITOR") + msg::print_error(msg::format(msgErrorVsCodeNotFound, msg::env_var = "EDITOR") .appendnl() .append(msgErrorVsCodeNotFoundPathExamined)); print_paths(candidate_paths); From 6e9fe33b84a7cdd63800395087a424e99cf9a43a Mon Sep 17 00:00:00 2001 From: Thomas Heinrichs <46387399+Thomas1664@users.noreply.github.com> Date: Tue, 24 May 2022 00:00:12 +0200 Subject: [PATCH 8/8] Adopt deletion of printnl --- src/vcpkg/commands.edit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vcpkg/commands.edit.cpp b/src/vcpkg/commands.edit.cpp index 3f0da89932..4a266226c6 100644 --- a/src/vcpkg/commands.edit.cpp +++ b/src/vcpkg/commands.edit.cpp @@ -87,7 +87,7 @@ namespace if (required_size == 0) { msg::print_error( - msg::format(msgEnvStrFailedToExtract).appendnl().append(LocalizedString::from_raw(input))); + msg::format(msgEnvStrFailedToExtract).append_raw('\n').append(LocalizedString::from_raw(input))); vcpkg::Checks::exit_fail(VCPKG_LINE_INFO); } @@ -261,7 +261,7 @@ namespace vcpkg::Commands::Edit if (it == candidate_paths.cend()) { msg::print_error(msg::format(msgErrorVsCodeNotFound, msg::env_var = "EDITOR") - .appendnl() + .append_raw('\n') .append(msgErrorVsCodeNotFoundPathExamined)); print_paths(candidate_paths); msg::println(msgInfoSetEnvVar, msg::env_var = "EDITOR");