diff --git a/include/vcpkg/fwd/vcpkgcmdarguments.h b/include/vcpkg/fwd/vcpkgcmdarguments.h index f8fbaca821..55d45c3e42 100644 --- a/include/vcpkg/fwd/vcpkgcmdarguments.h +++ b/include/vcpkg/fwd/vcpkgcmdarguments.h @@ -11,4 +11,5 @@ namespace vcpkg struct HelpTableFormatter; struct VcpkgCmdArguments; struct FeatureFlagSettings; + struct PortApplicableSetting; } diff --git a/include/vcpkg/vcpkgcmdarguments.h b/include/vcpkg/vcpkgcmdarguments.h index f804051c24..b69d9d7526 100644 --- a/include/vcpkg/vcpkgcmdarguments.h +++ b/include/vcpkg/vcpkgcmdarguments.h @@ -80,6 +80,21 @@ namespace vcpkg bool dependency_graph; }; + struct PortApplicableSetting + { + std::string value; + + PortApplicableSetting(StringView setting); + PortApplicableSetting(const PortApplicableSetting&); + PortApplicableSetting(PortApplicableSetting&&); + PortApplicableSetting& operator=(const PortApplicableSetting&); + PortApplicableSetting& operator=(PortApplicableSetting&&); + bool is_port_affected(StringView port_name) const noexcept; + + private: + std::vector affected_ports; + }; + struct VcpkgCmdArguments { static VcpkgCmdArguments create_from_command_line(const ILineReader& fs, @@ -161,6 +176,11 @@ namespace vcpkg constexpr static StringLiteral GITHUB_REPOSITORY_OWNER_ID = "GITHUB_REPOSITORY_OWNER_ID"; Optional github_repository_owner_id; + constexpr static StringLiteral CMAKE_DEBUGGING_ARG = "cmake-debug"; + Optional cmake_debug; + constexpr static StringLiteral CMAKE_CONFIGURE_DEBUGGING_ARG = "cmake-configure-debug"; + Optional cmake_configure_debug; + constexpr static StringLiteral CMAKE_SCRIPT_ARG = "cmake-args"; std::vector cmake_args; diff --git a/src/vcpkg-test/arguments.cpp b/src/vcpkg-test/arguments.cpp index fa5fd6095f..474eb631f8 100644 --- a/src/vcpkg-test/arguments.cpp +++ b/src/vcpkg-test/arguments.cpp @@ -160,3 +160,24 @@ TEST_CASE ("Feature flag off", "[arguments]") auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size()); CHECK(!v.versions_enabled()); } + +TEST_CASE ("CMake debugger flags", "[arguments]") +{ + std::vector t = {"--x-cmake-debug", + "\\\\.\\pipe\\tespipe;zlib;bar;baz", + "--x-cmake-configure-debug", + "\\\\.\\pipe\\configure-pipe"}; + auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size()); + auto& cmake_debug = v.cmake_debug.value_or_exit(VCPKG_LINE_INFO); + REQUIRE(cmake_debug.value == "\\\\.\\pipe\\tespipe"); + REQUIRE(!cmake_debug.is_port_affected("7zip")); + REQUIRE(cmake_debug.is_port_affected("zlib")); + REQUIRE(cmake_debug.is_port_affected("bar")); + REQUIRE(cmake_debug.is_port_affected("baz")); + REQUIRE(!cmake_debug.is_port_affected("bazz")); + + auto& cmake_configure_debug = v.cmake_configure_debug.value_or_exit(VCPKG_LINE_INFO); + REQUIRE(cmake_configure_debug.value == "\\\\.\\pipe\\configure-pipe"); + REQUIRE(cmake_configure_debug.is_port_affected("7zip")); + REQUIRE(cmake_configure_debug.is_port_affected("zlib")); +} diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 0e6c3d8529..a61e03ec60 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -778,6 +778,24 @@ namespace vcpkg variables.emplace_back("ARIA2", paths.get_tool_exe(Tools::ARIA2, stdout_sink)); } + if (auto cmake_debug = args.cmake_debug.get()) + { + if (cmake_debug->is_port_affected(scf.core_paragraph->name)) + { + variables.emplace_back("--debugger"); + variables.emplace_back(fmt::format("--debugger-pipe={}", cmake_debug->value)); + } + } + + if (auto cmake_configure_debug = args.cmake_configure_debug.get()) + { + if (cmake_configure_debug->is_port_affected(scf.core_paragraph->name)) + { + variables.emplace_back(fmt::format("-DVCPKG_CMAKE_CONFIGURE_OPTIONS=--debugger;--debugger-pipe={}", + cmake_configure_debug->value)); + } + } + for (const auto& cmake_arg : args.cmake_args) { variables.emplace_back(cmake_arg); diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 800a8e4f42..595394615e 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -10,6 +10,10 @@ #include #include +#include +#include +#include + namespace { using namespace vcpkg; @@ -231,6 +235,28 @@ namespace vcpkg } } + PortApplicableSetting::PortApplicableSetting(StringView setting) + { + auto split = Strings::split(setting, ';'); + if (!split.empty()) + { + value = std::move(split[0]); + split.erase(split.begin()); + Util::sort(split); + affected_ports = std::move(split); + } + } + + PortApplicableSetting::PortApplicableSetting(const PortApplicableSetting&) = default; + PortApplicableSetting::PortApplicableSetting(PortApplicableSetting&&) = default; + PortApplicableSetting& PortApplicableSetting::operator=(const PortApplicableSetting&) = default; + PortApplicableSetting& PortApplicableSetting::operator=(PortApplicableSetting&&) = default; + + bool PortApplicableSetting::is_port_affected(StringView port_name) const noexcept + { + return affected_ports.empty() || std::binary_search(affected_ports.begin(), affected_ports.end(), port_name); + } + VcpkgCmdArguments VcpkgCmdArguments::create_from_command_line(const ILineReader& fs, const int argc, const CommandLineCharType* const* const argv) @@ -290,6 +316,18 @@ namespace vcpkg StabilityTag::Experimental, args.asset_sources_template_arg, msg::format(msgAssetSourcesArg)); + { + std::string raw_cmake_debug; + if (args.parser.parse_option(CMAKE_DEBUGGING_ARG, StabilityTag::Experimental, raw_cmake_debug)) + { + args.cmake_debug.emplace(raw_cmake_debug); + } + + if (args.parser.parse_option(CMAKE_CONFIGURE_DEBUGGING_ARG, StabilityTag::Experimental, raw_cmake_debug)) + { + args.cmake_configure_debug.emplace(raw_cmake_debug); + } + } args.parser.parse_multi_option( OVERLAY_PORTS_ARG, @@ -804,5 +842,7 @@ namespace vcpkg constexpr StringLiteral VcpkgCmdArguments::VERSIONS_FEATURE; constexpr StringLiteral VcpkgCmdArguments::CMAKE_SCRIPT_ARG; + constexpr StringLiteral VcpkgCmdArguments::CMAKE_DEBUGGING_ARG; + constexpr StringLiteral VcpkgCmdArguments::CMAKE_CONFIGURE_DEBUGGING_ARG; constexpr StringLiteral VcpkgCmdArguments::EXACT_ABI_TOOLS_VERSIONS_SWITCH; }