Skip to content

Commit

Permalink
[vcpkg-env] Added internal 'env' command to help diagnose environment…
Browse files Browse the repository at this point in the history
… issues.
  • Loading branch information
ras0219-msft committed Apr 3, 2017
1 parent f9c01a8 commit cb5cbc4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg_Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions toolsrc/src/commands_available_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion toolsrc/src/commands_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()");
Expand All @@ -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,
{
Expand Down
17 changes: 17 additions & 0 deletions toolsrc/src/commands_env.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions toolsrc/vcpkglib/vcpkglib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 3 additions & 0 deletions toolsrc/vcpkglib/vcpkglib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit cb5cbc4

Please sign in to comment.