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

This commit is contained in:
Robert Schumacher 2017-04-03 10:44:14 -07:00
parent f9c01a893e
commit cb5cbc4d84
6 changed files with 37 additions and 1 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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,
{

View File

@ -0,0 +1,17 @@
#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);
}
}

View File

@ -185,6 +185,7 @@
<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" />

View File

@ -177,6 +177,9 @@
<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">