[vcpkg-env] Added internal 'env' command to help diagnose environment issues.
MODIFY
include/vcpkg_Commands.h
include/vcpkg_Commands.h
@@ -29,6 +29,8 @@ namespace vcpkg::Commands
std::string create_error_message(const BuildResult build_result, const package_spec& spec);
std::string create_user_troubleshooting_message(const package_spec& spec);
+ std::wstring make_build_env_cmd(const triplet& target_triplet, const toolset_t& toolset);
+
BuildResult build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir, const StatusParagraphs& status_db);
void perform_and_exit(const package_spec& spec, const fs::path& port_dir, const std::unordered_set<std::string>& options, const vcpkg_paths& paths);
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
@@ -69,6 +71,11 @@ namespace vcpkg::Commands
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);
}
+ namespace Env
+ {
+ void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_triplet);
+ }
+
namespace Create
{
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);

MODIFY
src/commands_available_commands.cpp
src/commands_available_commands.cpp
@@ -10,6 +10,7 @@ namespace vcpkg::Commands
{ "ci", &CI::perform_and_exit },
{"remove", &Remove::perform_and_exit},
{"build", &Build::perform_and_exit},
+ {"env", &Env::perform_and_exit},
{"build_external", &BuildExternal::perform_and_exit}
};
return t;

MODIFY
src/commands_build.cpp
src/commands_build.cpp
@@ -25,6 +25,13 @@ namespace vcpkg::Commands::Build
std::ofstream(binary_control_file) << bpgh;
}
+ std::wstring make_build_env_cmd(const triplet& target_triplet, const toolset_t& toolset)
+ {
+ return Strings::wformat(LR"("%s" %s >nul 2>&1)",
+ toolset.vcvarsall.native(),
+ Strings::utf8_to_utf16(target_triplet.architecture()));
+ }
+
BuildResult build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir, const StatusParagraphs& status_db)
{
Checks::check_exit(VCPKG_LINE_INFO, spec.name() == source_paragraph.name, "inconsistent arguments to build_package()");
@@ -43,7 +50,7 @@ namespace vcpkg::Commands::Build
const fs::path ports_cmake_script_path = paths.ports_cmake;
const toolset_t& toolset = paths.get_toolset();
- const std::wstring cmd_set_environment = Strings::wformat(LR"("%s" %s >nul 2>&1)", toolset.vcvarsall.native(), Strings::utf8_to_utf16(target_triplet.architecture()));
+ const auto cmd_set_environment = make_build_env_cmd(target_triplet, toolset);
const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path, ports_cmake_script_path,
{

ADD
src/commands_env.cpp
+#include "pch.h"
+#include "vcpkg_Commands.h"
+#include "vcpkg_System.h"
+
+namespace vcpkg::Commands::Env
+{
+ void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_triplet)
+ {
+ static const std::string example = Commands::Help::create_example_string(R"(env --triplet x64-windows)");
+ args.check_exact_arg_count(0, example);
+ args.check_and_get_optional_command_arguments({});
+
+ System::cmd_execute_clean(Build::make_build_env_cmd(default_triplet, paths.get_toolset()) + L" && cmd");
+
+ Checks::exit_success(VCPKG_LINE_INFO);
+ }
+}

MODIFY
vcpkglib/vcpkglib.vcxproj
vcpkglib/vcpkglib.vcxproj
<ClCompile Include="..\include\version_t.cpp" />
<ClCompile Include="..\src\BinaryParagraph.cpp" />
<ClCompile Include="..\src\commands_ci.cpp" />
+ <ClCompile Include="..\src\commands_env.cpp" />
<ClCompile Include="..\src\LineInfo.cpp" />
<ClCompile Include="..\src\paragraph_parse_result.cpp" />
<ClCompile Include="..\src\PostBuildLint_BuildInfo.cpp" />

MODIFY
vcpkglib/vcpkglib.vcxproj.filters
vcpkglib/vcpkglib.vcxproj.filters
<ClCompile Include="..\include\version_t.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\src\commands_env.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\package_spec.h">

[vcpkg-env] Added internal 'env' command to help diagnose environment issues.