From cb5cbc4d84d84e8199d58740e0e7ed3c6d3ba473 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Mon, 3 Apr 2017 10:44:14 -0700 Subject: [PATCH] [vcpkg-env] Added internal 'env' command to help diagnose environment issues. --- toolsrc/include/vcpkg_Commands.h | 7 +++++++ toolsrc/src/commands_available_commands.cpp | 1 + toolsrc/src/commands_build.cpp | 9 ++++++++- toolsrc/src/commands_env.cpp | 17 +++++++++++++++++ toolsrc/vcpkglib/vcpkglib.vcxproj | 1 + toolsrc/vcpkglib/vcpkglib.vcxproj.filters | 3 +++ 6 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 toolsrc/src/commands_env.cpp diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h index d73181bf4f..23575ca234 100644 --- a/toolsrc/include/vcpkg_Commands.h +++ b/toolsrc/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& 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); diff --git a/toolsrc/src/commands_available_commands.cpp b/toolsrc/src/commands_available_commands.cpp index 4c7e0df2c6..70e528704a 100644 --- a/toolsrc/src/commands_available_commands.cpp +++ b/toolsrc/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; diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 8791ef1c10..3c3fbeb662 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/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, { diff --git a/toolsrc/src/commands_env.cpp b/toolsrc/src/commands_env.cpp new file mode 100644 index 0000000000..314afb779b --- /dev/null +++ b/toolsrc/src/commands_env.cpp @@ -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); + } +} diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj index d79c77a940..9234f9c773 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj @@ -185,6 +185,7 @@ + diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters index acfecbcc50..9901bcd953 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters @@ -177,6 +177,9 @@ Source Files + + Source Files +