From 1f79c92eb099de356a5cb1e42234bb227e09d543 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 18 Sep 2018 20:55:35 -0700 Subject: Add command x-vsinstances --- toolsrc/src/vcpkg/commands.cpp | 1 + toolsrc/src/vcpkg/commands.xvsinstances.cpp | 29 +++++++++++++++++ toolsrc/src/vcpkg/visualstudio.cpp | 49 +++++++++++++++++++++-------- 3 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 toolsrc/src/vcpkg/commands.xvsinstances.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/commands.cpp b/toolsrc/src/vcpkg/commands.cpp index 7204b6e78..db265514f 100644 --- a/toolsrc/src/vcpkg/commands.cpp +++ b/toolsrc/src/vcpkg/commands.cpp @@ -46,6 +46,7 @@ namespace vcpkg::Commands {"autocomplete", &Autocomplete::perform_and_exit}, {"hash", &Hash::perform_and_exit}, {"fetch", &Fetch::perform_and_exit}, + {"x-vsinstances", &X_VSInstances::perform_and_exit}, }; return t; } diff --git a/toolsrc/src/vcpkg/commands.xvsinstances.cpp b/toolsrc/src/vcpkg/commands.xvsinstances.cpp new file mode 100644 index 000000000..3aa54f424 --- /dev/null +++ b/toolsrc/src/vcpkg/commands.xvsinstances.cpp @@ -0,0 +1,29 @@ +#include "pch.h" + +#include +#include +#include + +namespace vcpkg::Commands::X_VSInstances +{ + const CommandStructure COMMAND_STRUCTURE = { + Help::create_example_string("x-vsinstances"), + 0, + 0, + {{}, {}}, + nullptr, + }; + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) + { + const ParsedArguments parsed_args = args.parse_arguments(COMMAND_STRUCTURE); + + const auto instances = vcpkg::VisualStudio::get_visual_studio_instances(paths); + for (const std::string& instance : instances) + { + System::println(instance); + } + + Checks::exit_success(VCPKG_LINE_INFO); + } +} diff --git a/toolsrc/src/vcpkg/visualstudio.cpp b/toolsrc/src/vcpkg/visualstudio.cpp index 9480a11bf..4f6b2a37b 100644 --- a/toolsrc/src/vcpkg/visualstudio.cpp +++ b/toolsrc/src/vcpkg/visualstudio.cpp @@ -22,6 +22,17 @@ namespace vcpkg::VisualStudio LEGACY }; + static std::string release_type_to_string(const ReleaseType& release_type) + { + switch (release_type) + { + case ReleaseType::STABLE: return "STABLE"; + case ReleaseType::PRERELEASE: return "PRERELEASE"; + case ReleaseType::LEGACY: return "LEGACY"; + default: Checks::unreachable(VCPKG_LINE_INFO); + } + } + static bool preferred_first_comparator(const VisualStudioInstance& left, const VisualStudioInstance& right) { const auto get_preference_weight = [](const ReleaseType& type) -> int { @@ -51,10 +62,15 @@ namespace vcpkg::VisualStudio std::string version; ReleaseType release_type; + std::string to_string() const + { + return Strings::format("%s, %s, %s", root_path.u8string(), version, release_type_to_string(release_type)); + } + std::string major_version() const { return version.substr(0, 2); } }; - static std::vector get_visual_studio_instances(const VcpkgPaths& paths) + static std::vector get_visual_studio_instances_internal(const VcpkgPaths& paths) { const auto& fs = paths.get_filesystem(); std::vector instances; @@ -114,9 +130,9 @@ namespace vcpkg::VisualStudio { // We want lexically_normal(), but it is not available // Correct root path might be 2 or 3 levels up, depending on if the path has trailing backslash. Try both. - auto common7_tools = fs::path{*path_as_string}; - append_if_has_cl(fs::path{*path_as_string}.parent_path().parent_path()); - append_if_has_cl(fs::path{*path_as_string}.parent_path().parent_path().parent_path()); + auto common7_tools = fs::path {*path_as_string}; + append_if_has_cl(fs::path {*path_as_string}.parent_path().parent_path()); + append_if_has_cl(fs::path {*path_as_string}.parent_path().parent_path().parent_path()); } // VS2015 instance from Program Files @@ -125,6 +141,13 @@ namespace vcpkg::VisualStudio return instances; } + std::vector get_visual_studio_instances(const VcpkgPaths& paths) + { + std::vector sorted {get_visual_studio_instances_internal(paths)}; + std::sort(sorted.begin(), sorted.end(), VisualStudioInstance::preferred_first_comparator); + return Util::fmap(sorted, [](const VisualStudioInstance& instance) { return instance.to_string(); }); + } + std::vector find_toolset_instances_preferred_first(const VcpkgPaths& paths) { using CPU = System::CPUArchitecture; @@ -137,8 +160,8 @@ namespace vcpkg::VisualStudio std::vector found_toolsets; std::vector excluded_toolsets; - const SortedVector sorted{get_visual_studio_instances(paths), - VisualStudioInstance::preferred_first_comparator}; + const SortedVector sorted {get_visual_studio_instances_internal(paths), + VisualStudioInstance::preferred_first_comparator}; const bool v140_is_available = Util::find_if(sorted, [&](const VisualStudioInstance& vs_instance) { return vs_instance.major_version() == "14"; @@ -194,7 +217,7 @@ namespace vcpkg::VisualStudio paths_examined.push_back(dumpbin_path); if (fs.exists(dumpbin_path)) { - const Toolset v141_toolset{ + const Toolset v141_toolset { vs_instance.root_path, dumpbin_path, vcvarsall_bat, {}, V_141, supported_architectures}; const auto english_language_pack = dumpbin_path.parent_path() / "1033"; @@ -209,12 +232,12 @@ namespace vcpkg::VisualStudio if (v140_is_available) { - const Toolset v140_toolset{vs_instance.root_path, - dumpbin_path, - vcvarsall_bat, - {"-vcvars_ver=14.0"}, - V_140, - supported_architectures}; + const Toolset v140_toolset {vs_instance.root_path, + dumpbin_path, + vcvarsall_bat, + {"-vcvars_ver=14.0"}, + V_140, + supported_architectures}; found_toolsets.push_back(v140_toolset); } -- cgit v1.2.3 From a1a18eada148562d0906b103c70c9e36b6a648ce Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Tue, 18 Sep 2018 21:03:00 -0700 Subject: Add -all flag to vswhere.exe call --- toolsrc/src/vcpkg/visualstudio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/visualstudio.cpp b/toolsrc/src/vcpkg/visualstudio.cpp index 4f6b2a37b..e3656a7d2 100644 --- a/toolsrc/src/vcpkg/visualstudio.cpp +++ b/toolsrc/src/vcpkg/visualstudio.cpp @@ -82,7 +82,7 @@ namespace vcpkg::VisualStudio if (fs.exists(vswhere_exe)) { const auto code_and_output = System::cmd_execute_and_capture_output( - Strings::format(R"("%s" -prerelease -legacy -products * -format xml)", vswhere_exe.u8string())); + Strings::format(R"("%s" -all -prerelease -legacy -products * -format xml)", vswhere_exe.u8string())); Checks::check_exit(VCPKG_LINE_INFO, code_and_output.exit_code == 0, "Running vswhere.exe failed with message:\n%s", -- cgit v1.2.3 From 1faf5c7d289f5b693fbcaa98af8b41833e6a5a04 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Wed, 19 Sep 2018 17:09:27 -0700 Subject: [vcpkg] Hotfix build break on non-windows platforms in commands.xvsinstances.cpp --- toolsrc/src/vcpkg/commands.xvsinstances.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/commands.xvsinstances.cpp b/toolsrc/src/vcpkg/commands.xvsinstances.cpp index 3aa54f424..d748b6b2f 100644 --- a/toolsrc/src/vcpkg/commands.xvsinstances.cpp +++ b/toolsrc/src/vcpkg/commands.xvsinstances.cpp @@ -16,6 +16,7 @@ namespace vcpkg::Commands::X_VSInstances void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) { +#if defined(_WIN32) const ParsedArguments parsed_args = args.parse_arguments(COMMAND_STRUCTURE); const auto instances = vcpkg::VisualStudio::get_visual_studio_instances(paths); @@ -25,5 +26,8 @@ namespace vcpkg::Commands::X_VSInstances } Checks::exit_success(VCPKG_LINE_INFO); +#else + Checks::exit_with_message(VCPKG_LINE_INFO, "This command is not supported on non-windows platforms."); +#endif } } -- cgit v1.2.3