From a0b005f4954f9a30b916ad0ae3f3d22802fb1641 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Sat, 30 Dec 2023 01:42:59 +0100 Subject: [PATCH 01/15] add a way to run custom scripts for environment setup --- include/vcpkg/commands.build.h | 2 ++ src/vcpkg/cmakevars.cpp | 1 + src/vcpkg/commands.build.cpp | 53 ++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/include/vcpkg/commands.build.h b/include/vcpkg/commands.build.h index 8929386791..b9cb02afc5 100644 --- a/include/vcpkg/commands.build.h +++ b/include/vcpkg/commands.build.h @@ -161,6 +161,7 @@ namespace vcpkg Optional public_abi_override; std::vector passthrough_env_vars; std::vector passthrough_env_vars_tracked; + std::vector environment_setup_scripts; Optional gamedk_latest_path; Path toolchain_file() const; @@ -171,6 +172,7 @@ namespace vcpkg }; vcpkg::Command make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); + vcpkg::Command make_setup_env_cmd(const VcpkgPaths& paths, const Path& script); struct ExtendedBuildResult { diff --git a/src/vcpkg/cmakevars.cpp b/src/vcpkg/cmakevars.cpp index 9b19154959..71cfa7a666 100644 --- a/src/vcpkg/cmakevars.cpp +++ b/src/vcpkg/cmakevars.cpp @@ -150,6 +150,7 @@ VCPKG_ENV_PASSTHROUGH=${VCPKG_ENV_PASSTHROUGH} VCPKG_ENV_PASSTHROUGH_UNTRACKED=${VCPKG_ENV_PASSTHROUGH_UNTRACKED} VCPKG_LOAD_VCVARS_ENV=${VCPKG_LOAD_VCVARS_ENV} VCPKG_DISABLE_COMPILER_TRACKING=${VCPKG_DISABLE_COMPILER_TRACKING} +VCPKG_ENVIRONMENT_SETUP_SCRIPTS=${VCPKG_ENVIRONMENT_SETUP_SCRIPTS} VCPKG_XBOX_CONSOLE_TARGET=${VCPKG_XBOX_CONSOLE_TARGET} Z_VCPKG_GameDKLatest=$ENV{GameDKLatest} e1e74b5c-18cb-4474-a6bd-5c1c8bc81f3f diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 94ea38118a..fefb4b6670 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -472,16 +472,25 @@ namespace vcpkg return base_env.cmd_cache.get_lazy(build_env_cmd, [&]() { const Path& powershell_exe_path = paths.get_tool_exe("powershell-core", stdout_sink); auto clean_env = get_modified_clean_environment(base_env.env_map, powershell_exe_path.parent_path()); - if (build_env_cmd.empty()) - return clean_env; - else - return cmd_execute_and_capture_environment(build_env_cmd, clean_env); + auto action_env = build_env_cmd.empty() ? clean_env : cmd_execute_and_capture_environment(build_env_cmd, clean_env); + for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) + { + const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); + action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + } + return action_env; }); } #else const Environment& EnvCache::get_action_env(const VcpkgPaths&, const PreBuildInfo&, const Toolset&) { - return get_clean_environment(); + auto action_env = get_clean_environment(); + for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) + { + const auto env_setup_cmd = make_setup_env_cmd(pre_build_info, env_setup_script); + action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + } + return action_env; } #endif @@ -591,6 +600,33 @@ namespace vcpkg #endif } + vcpkg::Command make_setup_env_cmd(const VcpkgPaths& paths, const Path& script) + { + vcpkg::Command env_setup_cmd; + const auto& fs = paths.get_filesystem(); + + if(script.is_relative() || !fs.is_regular_file(script)) { + // Throw error + //Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidEnvSetupScripts, msg::path = env_setup_script_file); + } + + if(script.extension() == ".cmake") + { + env_setup_cmd = vcpkg::make_cmake_cmd(paths, script, {}); + } + else + { +#ifdef _WIN32 + env_setup_cmd = vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c"); + env_setup_cmd.raw_arg(fmt::format(R"("{}" 2>&1 &1 fspecs_to_pspecs(View fspecs) { std::set set; @@ -833,7 +869,7 @@ namespace vcpkg bool PreBuildInfo::using_vcvars() const { - return (!external_toolchain_file.has_value() || load_vcvars_env) && + return (!external_toolchain_file.has_value() || !environment_setup_scripts.empty() || load_vcvars_env) && (cmake_system_name.empty() || cmake_system_name == "WindowsStore"); } @@ -1789,6 +1825,7 @@ namespace vcpkg PUBLIC_ABI_OVERRIDE, LOAD_VCVARS_ENV, DISABLE_COMPILER_TRACKING, + ENVIRONMENT_SETUP_SCRIPTS, XBOX_CONSOLE_TARGET, Z_VCPKG_GameDKLatest }; @@ -1808,6 +1845,7 @@ namespace vcpkg // Note: this value must come after VCPKG_CHAINLOAD_TOOLCHAIN_FILE because its default depends upon it. {"VCPKG_LOAD_VCVARS_ENV", VcpkgTripletVar::LOAD_VCVARS_ENV}, {"VCPKG_DISABLE_COMPILER_TRACKING", VcpkgTripletVar::DISABLE_COMPILER_TRACKING}, + {"VCPKG_ENVIRONMENT_SETUP_SCRIPTS", VcpkgTripletVar::ENVIRONMENT_SETUP_SCRIPTS}, {"VCPKG_XBOX_CONSOLE_TARGET", VcpkgTripletVar::XBOX_CONSOLE_TARGET}, {"Z_VCPKG_GameDKLatest", VcpkgTripletVar::Z_VCPKG_GameDKLatest}, }; @@ -1875,6 +1913,9 @@ namespace vcpkg from_cmake_bool(variable_value, kv.first).value_or_exit(VCPKG_LINE_INFO); } break; + case VcpkgTripletVar::ENVIRONMENT_SETUP_SCRIPTS: + environment_setup_scripts = Strings::split(variable_value, ';'); + break; case VcpkgTripletVar::XBOX_CONSOLE_TARGET: if (!variable_value.empty()) { From bca096f203aedd12ad45d683b3d816eb60381ab2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Sat, 30 Dec 2023 07:37:56 +0100 Subject: [PATCH 02/15] add invalid message --- include/vcpkg/base/message-data.inc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index b880ca22e2..7083506d9d 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -1893,6 +1893,10 @@ DECLARE_MESSAGE(InvalidCommentStyle, "comments.") DECLARE_MESSAGE(InvalidCommitId, (msg::commit_sha), "", "Invalid commit id: {commit_sha}") DECLARE_MESSAGE(InvalidDefaultFeatureName, (), "", "'default' is a reserved feature name") +DECLARE_MESSAGE(InvalidEnvSetupScripts, (msg::path), + "", + "Variable VCPKG_ENVIRONMENT_SETUP_SCRIPTS contains invalid file path: '{path}'. The value must be " + "an absolute path to an existent file.") DECLARE_MESSAGE(InvalidFeature, (), "", From 5f257a17eb2bc10de05e432473a6731b01d4a420 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Sat, 30 Dec 2023 07:38:10 +0100 Subject: [PATCH 03/15] adjust for !windows --- include/vcpkg/base/system.process.h | 2 -- src/vcpkg/base/system.process.cpp | 5 ++++- src/vcpkg/commands.build.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/vcpkg/base/system.process.h b/include/vcpkg/base/system.process.h index 4a93139063..c5812edee7 100644 --- a/include/vcpkg/base/system.process.h +++ b/include/vcpkg/base/system.process.h @@ -122,10 +122,8 @@ namespace vcpkg const Environment& env = default_environment); ExpectedL cmd_execute_clean(const Command& cmd_line, const WorkingDirectory& wd = default_working_directory); -#if defined(_WIN32) Environment cmd_execute_and_capture_environment(const Command& cmd_line, const Environment& env = default_environment); -#endif void cmd_execute_background(const Command& cmd_line); diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 462f7d6690..4217256d10 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1252,8 +1252,11 @@ namespace vcpkg static StringLiteral magic_string = "cdARN4xjKueKScMy9C6H"; auto actual_cmd_line = cmd_line; +#ifdef _WIN32 actual_cmd_line.raw_arg(Strings::concat(" & echo ", magic_string, " & set")); - +#else + actual_cmd_line.raw_arg(Strings::concat(" && echo ", magic_string, " && printenv")); +#endif Debug::print("command line: ", actual_cmd_line.command_line(), "\n"); auto maybe_rc_output = cmd_execute_and_capture_output(actual_cmd_line, default_working_directory, env); if (!maybe_rc_output) diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index fefb4b6670..4835151cae 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -607,7 +607,7 @@ namespace vcpkg if(script.is_relative() || !fs.is_regular_file(script)) { // Throw error - //Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidEnvSetupScripts, msg::path = env_setup_script_file); + Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidEnvSetupScripts, msg::path = script); } if(script.extension() == ".cmake") @@ -620,7 +620,7 @@ namespace vcpkg env_setup_cmd = vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c"); env_setup_cmd.raw_arg(fmt::format(R"("{}" 2>&1 &1 &1 Date: Sun, 31 Dec 2023 12:21:59 +0100 Subject: [PATCH 04/15] make env capturing work on linux. lazy capture still missing --- src/vcpkg/base/system.process.cpp | 12 +++++++----- src/vcpkg/commands.build.cpp | 31 +++++++++++++++++++++++-------- src/vcpkg/vcpkgcmdarguments.cpp | 7 ++++++- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 4217256d10..15de144494 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1246,7 +1246,6 @@ namespace namespace vcpkg { -#if defined(_WIN32) Environment cmd_execute_and_capture_environment(const Command& cmd_line, const Environment& env) { static StringLiteral magic_string = "cdARN4xjKueKScMy9C6H"; @@ -1262,7 +1261,7 @@ namespace vcpkg if (!maybe_rc_output) { Checks::msg_exit_with_error( - VCPKG_LINE_INFO, msg::format(msgVcvarsRunFailed).append_raw("\n").append(maybe_rc_output.error())); + VCPKG_LINE_INFO, msg::format(msgVcvarsRunFailed).append_raw("\n").append(maybe_rc_output.error())); // This msg is incorrect } auto& rc_output = maybe_rc_output.value_or_exit(VCPKG_LINE_INFO); @@ -1270,13 +1269,13 @@ namespace vcpkg if (rc_output.exit_code != 0) { Checks::msg_exit_with_error( - VCPKG_LINE_INFO, msgVcvarsRunFailedExitCode, msg::exit_code = rc_output.exit_code); + VCPKG_LINE_INFO, msgVcvarsRunFailedExitCode, msg::exit_code = rc_output.exit_code); // This msg is incorrect } auto it = Strings::search(rc_output.output, magic_string); const char* const last = rc_output.output.data() + rc_output.output.size(); - Checks::check_exit(VCPKG_LINE_INFO, it != last); + Checks::check_exit(VCPKG_LINE_INFO, it != last); // magic string not found ! // find the first non-whitespace character after the magic string it = std::find_if_not(it + magic_string.size(), last, ::isspace); Checks::check_exit(VCPKG_LINE_INFO, it != last); @@ -1288,7 +1287,11 @@ namespace vcpkg auto equal_it = std::find(it, last, '='); if (equal_it == last) break; StringView variable_name(it, equal_it); +#ifdef _WIN32 auto newline_it = std::find(equal_it + 1, last, '\r'); +#else + auto newline_it = std::find(equal_it + 1, last, '\n'); +#endif if (newline_it == last) break; StringView value(equal_it + 1, newline_it); @@ -1300,7 +1303,6 @@ namespace vcpkg return new_env; } -#endif } // namespace vcpkg namespace diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 4835151cae..115762b145 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -475,20 +475,35 @@ namespace vcpkg auto action_env = build_env_cmd.empty() ? clean_env : cmd_execute_and_capture_environment(build_env_cmd, clean_env); for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) { - const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); - action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); + if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) + { + cmd_execute(env_setup_cmd, default_working_directory, action_env); + } + else + { + action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + } + } return action_env; }); } #else - const Environment& EnvCache::get_action_env(const VcpkgPaths&, const PreBuildInfo&, const Toolset&) + const Environment& EnvCache::get_action_env(const VcpkgPaths& paths, const PreBuildInfo& pre_build_info, const Toolset&) { - auto action_env = get_clean_environment(); + static auto action_env = get_clean_environment(); for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) { - const auto env_setup_cmd = make_setup_env_cmd(pre_build_info, env_setup_script); - action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); + if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) + { + cmd_execute(env_setup_cmd, default_working_directory, action_env); + } + else + { + action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + } } return action_env; } @@ -604,7 +619,7 @@ namespace vcpkg { vcpkg::Command env_setup_cmd; const auto& fs = paths.get_filesystem(); - + if(script.is_relative() || !fs.is_regular_file(script)) { // Throw error Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidEnvSetupScripts, msg::path = script); @@ -620,7 +635,7 @@ namespace vcpkg env_setup_cmd = vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c"); env_setup_cmd.raw_arg(fmt::format(R"("{}" 2>&1 &1 &1 Date: Sun, 31 Dec 2023 16:02:27 +0100 Subject: [PATCH 05/15] make env scripts lazy for linux --- include/vcpkg/commands.build.h | 2 -- src/vcpkg/commands.build.cpp | 35 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/vcpkg/commands.build.h b/include/vcpkg/commands.build.h index b9cb02afc5..984832ad55 100644 --- a/include/vcpkg/commands.build.h +++ b/include/vcpkg/commands.build.h @@ -311,7 +311,6 @@ namespace vcpkg const TripletMapEntry& get_triplet_cache(const ReadOnlyFilesystem& fs, const Path& p) const; -#if defined(_WIN32) struct EnvMapEntry { std::unordered_map env_map; @@ -319,7 +318,6 @@ namespace vcpkg }; Cache, EnvMapEntry> envs; -#endif bool m_compiler_tracking; }; diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 115762b145..8c984a022b 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -492,20 +492,27 @@ namespace vcpkg #else const Environment& EnvCache::get_action_env(const VcpkgPaths& paths, const PreBuildInfo& pre_build_info, const Toolset&) { - static auto action_env = get_clean_environment(); - for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) - { - const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); - if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) - { - cmd_execute(env_setup_cmd, default_working_directory, action_env); - } - else - { - action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); - } - } - return action_env; + auto action_env = get_clean_environment(); + const auto& base_env = envs.get_lazy(pre_build_info.environment_setup_scripts,[] () {return EnvMapEntry{};}); + + // I think this should be done differently but I don't exactly know how to build the commands beforehand. + // Can I stack base_env.cmd_cache.get_lazy in a loop? + + return base_env.cmd_cache.get_lazy(vcpkg::Command{}, [&]() { + for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) + { + const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); + if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) + { + cmd_execute(env_setup_cmd, default_working_directory, action_env); + } + else + { + action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + } + } + return action_env; + }); } #endif From a22e3490e979159902b270c0628c636e92503f05 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 20:33:15 +0200 Subject: [PATCH 06/15] fix merge compile errors. --- src/vcpkg/commands.build.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 4ba08ca88d..6f8cdfdd1d 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -476,7 +476,9 @@ namespace vcpkg const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) { - cmd_execute(env_setup_cmd, default_working_directory, action_env); + ProcessLaunchSettings settings; + settings.environment = action_env; + cmd_execute(env_setup_cmd, settings); } else { @@ -502,7 +504,9 @@ namespace vcpkg const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) { - cmd_execute(env_setup_cmd, default_working_directory, action_env); + ProcessLaunchSettings settings; + settings.environment = action_env; + cmd_execute(env_setup_cmd, settings); } else { From d325419d047ed968e356dd0bbbca63478fc50dba Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 20:40:09 +0200 Subject: [PATCH 07/15] Fix !windows builds --- src/vcpkg/base/system.process.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index c57ab01511..e563906852 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1270,7 +1270,9 @@ namespace vcpkg RedirectedProcessLaunchSettings settings; settings.environment = env; +#ifdef _WIN32 settings.create_new_console = CreateNewConsole::Yes; +#endif auto maybe_rc_output = cmd_execute_and_capture_output(actual_cmd, settings); if (!maybe_rc_output) From 0b095143eef0e139aee5fab08f191e9afcfd072f Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 21:42:50 +0200 Subject: [PATCH 08/15] Adjust error messages --- include/vcpkg/base/message-data.inc.h | 8 ++++---- src/vcpkg/base/system.process.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index 539485417c..239400757f 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -2833,11 +2833,11 @@ DECLARE_MESSAGE(VcpkgRegistriesCacheIsNotDirectory, DECLARE_MESSAGE(VcpkgRootRequired, (), "", "Setting VCPKG_ROOT is required for standalone bootstrap.") DECLARE_MESSAGE(VcpkgRootsDir, (msg::env_var), "", "The vcpkg root directory (default: {env_var})") DECLARE_MESSAGE(VcpkgSendMetricsButDisabled, (), "", "passed --sendmetrics, but metrics are disabled.") -DECLARE_MESSAGE(VcvarsRunFailed, (), "", "failed to run vcvarsall.bat to get a Visual Studio environment") -DECLARE_MESSAGE(VcvarsRunFailedExitCode, - (msg::exit_code), +DECLARE_MESSAGE(CaptureCmdRunFailed, (msg::command_name, msg::error_msg), "", "failed to run '{command_name}' to get environment ({msg::error_msg}).") +DECLARE_MESSAGE(CaptureCmdEnvFailedExitCode, + (msg::command_name, msg::exit_code), "", - "while trying to get a Visual Studio environment, vcvarsall.bat returned {exit_code}") + "while trying to capture an environment, '{command_name}' returned {exit_code}.") DECLARE_MESSAGE(VersionBaselineMismatch, (msg::expected, msg::actual, msg::package_name), "{expected} and {actual} are versions", diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index e563906852..47a23c2fbe 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1278,7 +1278,7 @@ namespace vcpkg if (!maybe_rc_output) { Checks::msg_exit_with_error( - VCPKG_LINE_INFO, msg::format(msgVcvarsRunFailed).append_raw("\n").append(maybe_rc_output.error())); // This msg is incorrect + VCPKG_LINE_INFO, msgCaptureCmdRunFailed, msg::command_name = actual_cmd.command_line(), msg::error_msg = maybe_rc_output.error()); } auto& rc_output = maybe_rc_output.value_or_exit(VCPKG_LINE_INFO); @@ -1286,7 +1286,7 @@ namespace vcpkg if (rc_output.exit_code != 0) { Checks::msg_exit_with_error( - VCPKG_LINE_INFO, msgVcvarsRunFailedExitCode, msg::exit_code = rc_output.exit_code); // This msg is incorrect + VCPKG_LINE_INFO, msgCaptureCmdEnvFailedExitCode, msg::command_name = actual_cmd.command_line(), msg::exit_code = rc_output.exit_code); } auto it = Strings::search(rc_output.output, magic_string); From 5a0bdff2a32254a1184e6a64cb456f73cc314ed2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 23:35:12 +0200 Subject: [PATCH 09/15] fix copy pasta --- src/vcpkg/commands.build.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 6f8cdfdd1d..36752b2c23 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -1895,7 +1895,7 @@ namespace vcpkg Util::Vectors::append(&passthrough_env_vars, Strings::split(*value, ';')); } - if (auto value = Util::value_if_set_and_nonempty(cmakevars, CMakeVariableHashAdditionalFiles)) + if (auto value = Util::value_if_set_and_nonempty(cmakevars, CMakeVariableEnvSetupScripts)) { Util::Vectors::append(&environment_setup_scripts, Strings::split(*value, ';')); } From 888c5402e9598716069b9791dcfa04fdbdd53dca Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 23:41:15 +0200 Subject: [PATCH 10/15] Add e2e test --- .../e2e-ports/env-scripts/env-cmake-script.cmake | 2 ++ .../e2e-ports/env-scripts/env-scripts.cmake | 15 +++++++++++++++ .../e2e-ports/env-scripts/env-set-script | 4 ++++ .../e2e-ports/env-scripts/env-set-script.bat | 2 ++ .../env-scripts/test-env-scripts/portfile.cmake | 16 ++++++++++++++++ .../env-scripts/test-env-scripts/vcpkg.json | 5 +++++ .../end-to-end-tests-dir/env-scripts.ps1 | 4 ++++ 7 files changed, 48 insertions(+) create mode 100644 azure-pipelines/e2e-ports/env-scripts/env-cmake-script.cmake create mode 100644 azure-pipelines/e2e-ports/env-scripts/env-scripts.cmake create mode 100644 azure-pipelines/e2e-ports/env-scripts/env-set-script create mode 100644 azure-pipelines/e2e-ports/env-scripts/env-set-script.bat create mode 100644 azure-pipelines/e2e-ports/env-scripts/test-env-scripts/portfile.cmake create mode 100644 azure-pipelines/e2e-ports/env-scripts/test-env-scripts/vcpkg.json create mode 100644 azure-pipelines/end-to-end-tests-dir/env-scripts.ps1 diff --git a/azure-pipelines/e2e-ports/env-scripts/env-cmake-script.cmake b/azure-pipelines/e2e-ports/env-scripts/env-cmake-script.cmake new file mode 100644 index 0000000000..65238a0393 --- /dev/null +++ b/azure-pipelines/e2e-ports/env-scripts/env-cmake-script.cmake @@ -0,0 +1,2 @@ + +file(WRITE "${BUILDTREES_DIR}/env-script.log" "DOWNLOADS:${DOWNLOADS}") diff --git a/azure-pipelines/e2e-ports/env-scripts/env-scripts.cmake b/azure-pipelines/e2e-ports/env-scripts/env-scripts.cmake new file mode 100644 index 0000000000..38b9a0a26c --- /dev/null +++ b/azure-pipelines/e2e-ports/env-scripts/env-scripts.cmake @@ -0,0 +1,15 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) +if(APPLE) +set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +elseif(UNIX) +set(VCPKG_CMAKE_SYSTEM_NAME Linux) +endif() + +set(script_ext ".bat" ) +if(UNIX) + set(script_ext "" ) +endif() +set(VCPKG_ENVIRONMENT_SETUP_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/env-set-script${script_ext}") +list(APPEND VCPKG_ENVIRONMENT_SETUP_SCRIPTS "${CMAKE_CURRENT_LIST_DIR}/env-cmake-script.cmake") diff --git a/azure-pipelines/e2e-ports/env-scripts/env-set-script b/azure-pipelines/e2e-ports/env-scripts/env-set-script new file mode 100644 index 0000000000..92be19a842 --- /dev/null +++ b/azure-pipelines/e2e-ports/env-scripts/env-set-script @@ -0,0 +1,4 @@ +#!/usr/bin/bash + +export VCPKG_ENV_TEST=TRUE +export VCPKG_ENV_TEST2=MORE_TESTING diff --git a/azure-pipelines/e2e-ports/env-scripts/env-set-script.bat b/azure-pipelines/e2e-ports/env-scripts/env-set-script.bat new file mode 100644 index 0000000000..c01be61258 --- /dev/null +++ b/azure-pipelines/e2e-ports/env-scripts/env-set-script.bat @@ -0,0 +1,2 @@ +set VCPKG_ENV_TEST=TRUE +set VCPKG_ENV_TEST2=MORE_TESTING diff --git a/azure-pipelines/e2e-ports/env-scripts/test-env-scripts/portfile.cmake b/azure-pipelines/e2e-ports/env-scripts/test-env-scripts/portfile.cmake new file mode 100644 index 0000000000..afa4a998ac --- /dev/null +++ b/azure-pipelines/e2e-ports/env-scripts/test-env-scripts/portfile.cmake @@ -0,0 +1,16 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +if(NOT DEFINED ENV{VCPKG_ENV_TEST} AND NOT "$ENV{VCPKG_ENV_TEST}" STREQUAL "TRUE") + message(FATAL_ERROR "ENV{VCPKG_ENV_TEST} not set or has wrong value of '$ENV{VCPKG_ENV_TEST}' (expected TRUE)") +endif() + +if(NOT DEFINED ENV{VCPKG_ENV_TEST2} AND NOT "$ENV{VCPKG_ENV_TEST2}" STREQUAL "MORE_TESTING") + message(FATAL_ERROR "ENV{VCPKG_ENV_TEST2} not set or has wrong value of '$ENV{VCPKG_ENV_TEST2}' (expected MORE_TESTING)") +endif() + +file(READ "${CURRENT_BUILDTREES_DIR}/../env-script.log" contents) +file(REMOVE "${CURRENT_BUILDTREES_DIR}/../env-script.log") + +if(NOT contents STREQUAL "DOWNLOADS:${DOWNLOADS}") + message(FATAL_ERROR "contents (${contents}) of 'env-script.log' are not equal to 'DOWNLOADS:${DOWNLOADS}'") +endif() diff --git a/azure-pipelines/e2e-ports/env-scripts/test-env-scripts/vcpkg.json b/azure-pipelines/e2e-ports/env-scripts/test-env-scripts/vcpkg.json new file mode 100644 index 0000000000..028ffa718a --- /dev/null +++ b/azure-pipelines/e2e-ports/env-scripts/test-env-scripts/vcpkg.json @@ -0,0 +1,5 @@ +{ + "name": "test-env-scripts", + "version": "0", + "description": "A port that tests VCPKG_ENVIRONMENT_SETUP_SCRIPTS" +} diff --git a/azure-pipelines/end-to-end-tests-dir/env-scripts.ps1 b/azure-pipelines/end-to-end-tests-dir/env-scripts.ps1 new file mode 100644 index 0000000000..6cea85e492 --- /dev/null +++ b/azure-pipelines/end-to-end-tests-dir/env-scripts.ps1 @@ -0,0 +1,4 @@ +. $PSScriptRoot/../end-to-end-tests-prelude.ps1 + +Run-Vcpkg @directoryArgs "--overlay-triplets=$PSScriptRoot/../e2e-ports/env-scripts" "--overlay-ports=$PSScriptRoot/../e2e-ports/env-scripts" x-set-installed test-env-scripts --triplet env-scripts --binarysource=clear --debug +Throw-IfFailed From 372e4431a6a7ad1c433ad583f682448e95fb7ba3 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 23:48:05 +0200 Subject: [PATCH 11/15] fix msg format --- include/vcpkg/base/message-data.inc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index 239400757f..872e8610d5 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -2833,7 +2833,7 @@ DECLARE_MESSAGE(VcpkgRegistriesCacheIsNotDirectory, DECLARE_MESSAGE(VcpkgRootRequired, (), "", "Setting VCPKG_ROOT is required for standalone bootstrap.") DECLARE_MESSAGE(VcpkgRootsDir, (msg::env_var), "", "The vcpkg root directory (default: {env_var})") DECLARE_MESSAGE(VcpkgSendMetricsButDisabled, (), "", "passed --sendmetrics, but metrics are disabled.") -DECLARE_MESSAGE(CaptureCmdRunFailed, (msg::command_name, msg::error_msg), "", "failed to run '{command_name}' to get environment ({msg::error_msg}).") +DECLARE_MESSAGE(CaptureCmdRunFailed, (msg::command_name, msg::error_msg), "", "failed to run '{command_name}' to get environment ({error_msg}).") DECLARE_MESSAGE(CaptureCmdEnvFailedExitCode, (msg::command_name, msg::exit_code), "", From 61b0fc859ee28101e6a22b7042ae0820a373a69b Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Tue, 28 May 2024 21:52:02 +0000 Subject: [PATCH 12/15] Format and regenerate messages --- include/vcpkg/base/message-data.inc.h | 10 +++-- include/vcpkg/commands.build.h | 1 - locales/messages.json | 9 ++-- src/vcpkg/base/system.process.cpp | 12 ++++-- src/vcpkg/commands.build.cpp | 60 ++++++++++++++------------- src/vcpkg/vcpkgcmdarguments.cpp | 5 +-- 6 files changed, 54 insertions(+), 43 deletions(-) diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index 872e8610d5..bbc3c3e8b9 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -1840,8 +1840,9 @@ DECLARE_MESSAGE(InvalidCommentStyle, "comments.") DECLARE_MESSAGE(InvalidCommitId, (msg::commit_sha), "", "Invalid commit id: {commit_sha}") DECLARE_MESSAGE(InvalidDefaultFeatureName, (), "", "'default' is a reserved feature name") -DECLARE_MESSAGE(InvalidEnvSetupScripts, (msg::path), - "", +DECLARE_MESSAGE(InvalidEnvSetupScripts, + (msg::path), + "", "Variable VCPKG_ENVIRONMENT_SETUP_SCRIPTS contains invalid file path: '{path}'. The value must be " "an absolute path to an existent file.") DECLARE_MESSAGE(InvalidFeature, @@ -2833,7 +2834,10 @@ DECLARE_MESSAGE(VcpkgRegistriesCacheIsNotDirectory, DECLARE_MESSAGE(VcpkgRootRequired, (), "", "Setting VCPKG_ROOT is required for standalone bootstrap.") DECLARE_MESSAGE(VcpkgRootsDir, (msg::env_var), "", "The vcpkg root directory (default: {env_var})") DECLARE_MESSAGE(VcpkgSendMetricsButDisabled, (), "", "passed --sendmetrics, but metrics are disabled.") -DECLARE_MESSAGE(CaptureCmdRunFailed, (msg::command_name, msg::error_msg), "", "failed to run '{command_name}' to get environment ({error_msg}).") +DECLARE_MESSAGE(CaptureCmdRunFailed, + (msg::command_name, msg::error_msg), + "", + "failed to run '{command_name}' to get environment ({error_msg}).") DECLARE_MESSAGE(CaptureCmdEnvFailedExitCode, (msg::command_name, msg::exit_code), "", diff --git a/include/vcpkg/commands.build.h b/include/vcpkg/commands.build.h index 83294ecf10..9215627272 100644 --- a/include/vcpkg/commands.build.h +++ b/include/vcpkg/commands.build.h @@ -135,7 +135,6 @@ namespace vcpkg std::vector environment_setup_scripts; std::vector hash_additional_files; - Optional gamedk_latest_path; Path toolchain_file() const; diff --git a/locales/messages.json b/locales/messages.json index 0d82c56f8a..130aa19f7e 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -265,6 +265,10 @@ "_CMakeToolChainFile.comment": "An example of {path} is /foo/bar.", "CMakeUsingExportedLibs": "To use exported libraries in CMake projects, add {value} to your CMake command line.", "_CMakeUsingExportedLibs.comment": "{value} is a CMake command line switch of the form -DFOO=BAR", + "CaptureCmdEnvFailedExitCode": "while trying to capture an environment, '{command_name}' returned {exit_code}.", + "_CaptureCmdEnvFailedExitCode.comment": "An example of {command_name} is install. An example of {exit_code} is 127.", + "CaptureCmdRunFailed": "failed to run '{command_name}' to get environment ({error_msg}).", + "_CaptureCmdRunFailed.comment": "An example of {command_name} is install. An example of {error_msg} is File Not Found.", "CheckedOutGitSha": "Checked out Git SHA: {commit_sha}", "_CheckedOutGitSha.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.", "CheckedOutObjectMissingManifest": "The checked-out object does not contain a CONTROL file or vcpkg.json file.", @@ -1032,6 +1036,8 @@ "InvalidCommitId": "Invalid commit id: {commit_sha}", "_InvalidCommitId.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.", "InvalidDefaultFeatureName": "'default' is a reserved feature name", + "InvalidEnvSetupScripts": "Variable VCPKG_ENVIRONMENT_SETUP_SCRIPTS contains invalid file path: '{path}'. The value must be an absolute path to an existent file.", + "_InvalidEnvSetupScripts.comment": "An example of {path} is /foo/bar.", "InvalidFeature": "features must be lowercase alphanumeric+hyphens, and not one of the reserved names", "InvalidFileType": "failed: {path} cannot handle file type", "_InvalidFileType.comment": "An example of {path} is /foo/bar.", @@ -1568,9 +1574,6 @@ "VcpkgSendMetricsButDisabled": "passed --sendmetrics, but metrics are disabled.", "VcpkgUsage": "usage: vcpkg [--switches] [--options=values] [arguments] @response_file", "_VcpkgUsage.comment": "This is describing a command line, everything should be localized except 'vcpkg'; symbols like <>s, []s, or --s should be preserved. @response_file should be localized to be consistent with the message named 'ResponseFileCode'.", - "VcvarsRunFailed": "failed to run vcvarsall.bat to get a Visual Studio environment", - "VcvarsRunFailedExitCode": "while trying to get a Visual Studio environment, vcvarsall.bat returned {exit_code}", - "_VcvarsRunFailedExitCode.comment": "An example of {exit_code} is 127.", "VersionBaselineMismatch": "The latest version is {expected}, but the baseline file contains {actual}.\nRun:\nvcpkg x-add-version {package_name}\ngit add versions\ngit commit -m \"Update version database\"\nto update the baseline version.", "_VersionBaselineMismatch.comment": "{expected} and {actual} are versions An example of {package_name} is zlib.", "VersionBuiltinPortTreeEntryMissing": "no version database entry for {package_name} at {expected}; using the checked out ports tree version ({actual}).", diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 47a23c2fbe..15f74d5040 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1277,16 +1277,20 @@ namespace vcpkg if (!maybe_rc_output) { - Checks::msg_exit_with_error( - VCPKG_LINE_INFO, msgCaptureCmdRunFailed, msg::command_name = actual_cmd.command_line(), msg::error_msg = maybe_rc_output.error()); + Checks::msg_exit_with_error(VCPKG_LINE_INFO, + msgCaptureCmdRunFailed, + msg::command_name = actual_cmd.command_line(), + msg::error_msg = maybe_rc_output.error()); } auto& rc_output = maybe_rc_output.value_or_exit(VCPKG_LINE_INFO); Debug::print(rc_output.output, "\n"); if (rc_output.exit_code != 0) { - Checks::msg_exit_with_error( - VCPKG_LINE_INFO, msgCaptureCmdEnvFailedExitCode, msg::command_name = actual_cmd.command_line(), msg::exit_code = rc_output.exit_code); + Checks::msg_exit_with_error(VCPKG_LINE_INFO, + msgCaptureCmdEnvFailedExitCode, + msg::command_name = actual_cmd.command_line(), + msg::exit_code = rc_output.exit_code); } auto it = Strings::search(rc_output.output, magic_string); diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 36752b2c23..b6f52bf03b 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -470,48 +470,50 @@ namespace vcpkg return base_env.cmd_cache.get_lazy(build_env_cmd, [&]() { const Path& powershell_exe_path = paths.get_tool_exe("powershell-core", out_sink); auto clean_env = get_modified_clean_environment(base_env.env_map, powershell_exe_path.parent_path()); - auto action_env = build_env_cmd.empty() ? clean_env : cmd_execute_and_capture_environment(build_env_cmd, clean_env); - for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) + auto action_env = + build_env_cmd.empty() ? clean_env : cmd_execute_and_capture_environment(build_env_cmd, clean_env); + for (const auto& env_setup_script : pre_build_info.environment_setup_scripts) { const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); - if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) + if (vcpkg::Strings::ends_with(env_setup_script, ".cmake")) { ProcessLaunchSettings settings; settings.environment = action_env; cmd_execute(env_setup_cmd, settings); } - else + else { action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); - } - + } } return action_env; }); } #else - const Environment& EnvCache::get_action_env(const VcpkgPaths& paths, const PreBuildInfo& pre_build_info, const Toolset&) + const Environment& EnvCache::get_action_env(const VcpkgPaths& paths, + const PreBuildInfo& pre_build_info, + const Toolset&) { auto action_env = get_clean_environment(); - const auto& base_env = envs.get_lazy(pre_build_info.environment_setup_scripts,[] () {return EnvMapEntry{};}); + const auto& base_env = envs.get_lazy(pre_build_info.environment_setup_scripts, []() { return EnvMapEntry{}; }); // I think this should be done differently but I don't exactly know how to build the commands beforehand. // Can I stack base_env.cmd_cache.get_lazy in a loop? return base_env.cmd_cache.get_lazy(vcpkg::Command{}, [&]() { - for(const auto& env_setup_script : pre_build_info.environment_setup_scripts) + for (const auto& env_setup_script : pre_build_info.environment_setup_scripts) { - const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); - if(vcpkg::Strings::ends_with(env_setup_script,".cmake")) - { - ProcessLaunchSettings settings; - settings.environment = action_env; - cmd_execute(env_setup_cmd, settings); - } - else - { - action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); - } + const auto env_setup_cmd = make_setup_env_cmd(paths, env_setup_script); + if (vcpkg::Strings::ends_with(env_setup_script, ".cmake")) + { + ProcessLaunchSettings settings; + settings.environment = action_env; + cmd_execute(env_setup_cmd, settings); + } + else + { + action_env = cmd_execute_and_capture_environment(env_setup_cmd, action_env); + } } return action_env; }); @@ -624,17 +626,18 @@ namespace vcpkg #endif } - vcpkg::Command make_setup_env_cmd(const VcpkgPaths& paths, const Path& script) + vcpkg::Command make_setup_env_cmd(const VcpkgPaths& paths, const Path& script) { vcpkg::Command env_setup_cmd; - const auto& fs = paths.get_filesystem(); - - if(script.is_relative() || !fs.is_regular_file(script)) { + const auto& fs = paths.get_filesystem(); + + if (script.is_relative() || !fs.is_regular_file(script)) + { // Throw error Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidEnvSetupScripts, msg::path = script); } - if(script.extension() == ".cmake") + if (script.extension() == ".cmake") { env_setup_cmd = vcpkg::make_cmake_cmd(paths, script, {}); } @@ -642,12 +645,11 @@ namespace vcpkg { #ifdef _WIN32 env_setup_cmd = vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c"); - env_setup_cmd.raw_arg(fmt::format(R"("{}" 2>&1 &1 &1 &1 Date: Wed, 29 May 2024 06:58:05 +0200 Subject: [PATCH 13/15] Minimal WS and comment cleanup --- azure-pipelines/e2e-ports/env-scripts/env-set-script | 1 - include/vcpkg/commands.build.h | 1 - src/vcpkg/base/system.process.cpp | 1 - src/vcpkg/commands.build.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/azure-pipelines/e2e-ports/env-scripts/env-set-script b/azure-pipelines/e2e-ports/env-scripts/env-set-script index 92be19a842..25a1f173e6 100644 --- a/azure-pipelines/e2e-ports/env-scripts/env-set-script +++ b/azure-pipelines/e2e-ports/env-scripts/env-set-script @@ -1,4 +1,3 @@ #!/usr/bin/bash - export VCPKG_ENV_TEST=TRUE export VCPKG_ENV_TEST2=MORE_TESTING diff --git a/include/vcpkg/commands.build.h b/include/vcpkg/commands.build.h index 9215627272..cbe21556ad 100644 --- a/include/vcpkg/commands.build.h +++ b/include/vcpkg/commands.build.h @@ -134,7 +134,6 @@ namespace vcpkg std::vector passthrough_env_vars_tracked; std::vector environment_setup_scripts; std::vector hash_additional_files; - Optional gamedk_latest_path; Path toolchain_file() const; diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 15f74d5040..e17536ea26 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -1274,7 +1274,6 @@ namespace vcpkg settings.create_new_console = CreateNewConsole::Yes; #endif auto maybe_rc_output = cmd_execute_and_capture_output(actual_cmd, settings); - if (!maybe_rc_output) { Checks::msg_exit_with_error(VCPKG_LINE_INFO, diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index b6f52bf03b..df142eecd4 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -633,7 +633,6 @@ namespace vcpkg if (script.is_relative() || !fs.is_regular_file(script)) { - // Throw error Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgInvalidEnvSetupScripts, msg::path = script); } From 1c655154c69be6da324ded25f59752abf54fbb0f Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Thu, 30 May 2024 10:02:14 +0200 Subject: [PATCH 14/15] Fix error case for cmake scripts. --- include/vcpkg/base/message-data.inc.h | 2 ++ locales/messages.json | 4 ++++ src/vcpkg/commands.build.cpp | 32 +++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index bbc3c3e8b9..d480ef07f0 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -2834,6 +2834,8 @@ DECLARE_MESSAGE(VcpkgRegistriesCacheIsNotDirectory, DECLARE_MESSAGE(VcpkgRootRequired, (), "", "Setting VCPKG_ROOT is required for standalone bootstrap.") DECLARE_MESSAGE(VcpkgRootsDir, (msg::env_var), "", "The vcpkg root directory (default: {env_var})") DECLARE_MESSAGE(VcpkgSendMetricsButDisabled, (), "", "passed --sendmetrics, but metrics are disabled.") +DECLARE_MESSAGE(CmdRunFailed, (msg::command_name, msg::error_msg), "", "failed to run '{command_name}' ({error_msg}).") +DECLARE_MESSAGE(CmdRunFailedExitCode, (msg::command_name, msg::exit_code), "", "'{command_name}' returned {exit_code}.") DECLARE_MESSAGE(CaptureCmdRunFailed, (msg::command_name, msg::error_msg), "", diff --git a/locales/messages.json b/locales/messages.json index 130aa19f7e..3f2bde5444 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -458,6 +458,10 @@ "CmdRemoveOptDryRun": "Prints the packages to be removed, but does not remove them", "CmdRemoveOptOutdated": "Removes all packages with versions that do not match the built-in registry", "CmdRemoveOptRecurse": "Allows removal of dependent packages not explicitly specified", + "CmdRunFailed": "failed to run '{command_name}' ({error_msg}).", + "_CmdRunFailed.comment": "An example of {command_name} is install. An example of {error_msg} is File Not Found.", + "CmdRunFailedExitCode": "'{command_name}' returned {exit_code}.", + "_CmdRunFailedExitCode.comment": "An example of {command_name} is install. An example of {exit_code} is 127.", "CmdSearchExample1": "vcpkg search ", "_CmdSearchExample1.comment": "This is a command line, only the part should be localized.", "CmdSetInstalledExample1": "vcpkg x-set-installed ...", diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index b6f52bf03b..0df378245d 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -479,7 +479,21 @@ namespace vcpkg { ProcessLaunchSettings settings; settings.environment = action_env; - cmd_execute(env_setup_cmd, settings); + auto cmd_res_output = cmd_execute(env_setup_cmd, settings); + if (!cmd_res_output) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, + msgCmdRunFailed, + msg::command_name = env_setup_cmd.command_line(), + msg::error_msg = cmd_res_output.error()); + } + if (auto err_code = cmd_res_output.value(VCPKG_LINE_INFO); err_code != 0) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, + msgCmdRunFailedExitCode, + msg::command_name = env_setup_cmd.command_line(), + msg::exit_code = err_code); + } } else { @@ -508,7 +522,21 @@ namespace vcpkg { ProcessLaunchSettings settings; settings.environment = action_env; - cmd_execute(env_setup_cmd, settings); + auto cmd_res_output = cmd_execute(env_setup_cmd, settings); + if (!cmd_res_output) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, + msgCmdRunFailed, + msg::command_name = env_setup_cmd.command_line(), + msg::error_msg = cmd_res_output.error()); + } + if (auto err_code = cmd_res_output.value(VCPKG_LINE_INFO); err_code != 0) + { + Checks::msg_exit_with_error(VCPKG_LINE_INFO, + msgCmdRunFailedExitCode, + msg::command_name = env_setup_cmd.command_line(), + msg::error_code = err_code); + } } else { From 724bd7bf0a2554fa7b51f59c5ae287d5c768eae3 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Thu, 30 May 2024 10:20:03 +0200 Subject: [PATCH 15/15] fix !windows build failures --- src/vcpkg/commands.build.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 6acd052d1d..1efa638e9f 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -535,7 +535,7 @@ namespace vcpkg Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgCmdRunFailedExitCode, msg::command_name = env_setup_cmd.command_line(), - msg::error_code = err_code); + msg::exit_code = err_code); } } else