From 0bda566c9ff8f9647d273e8d6cafd530381878e2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:44:08 +0200 Subject: [PATCH 1/3] Introduce --x-cmake-debug and --x-cmake-configure-debug --- include/vcpkg/vcpkgcmdarguments.h | 5 +++++ src/vcpkg/commands.build.cpp | 25 +++++++++++++++++++++++++ src/vcpkg/vcpkgcmdarguments.cpp | 5 +++++ 3 files changed, 35 insertions(+) diff --git a/include/vcpkg/vcpkgcmdarguments.h b/include/vcpkg/vcpkgcmdarguments.h index f804051c24..aefa9bb067 100644 --- a/include/vcpkg/vcpkgcmdarguments.h +++ b/include/vcpkg/vcpkgcmdarguments.h @@ -164,6 +164,11 @@ namespace vcpkg constexpr static StringLiteral CMAKE_SCRIPT_ARG = "cmake-args"; std::vector cmake_args; + constexpr static StringLiteral CMAKE_DEBUGGING_ARG = "cmake-debug"; + std::vector cmake_debug; + constexpr static StringLiteral CMAKE_CONFIGURE_DEBUGGING_ARG = "cmake-configure-debug"; + std::vector cmake_configure_debug; + constexpr static StringLiteral EXACT_ABI_TOOLS_VERSIONS_SWITCH = "abi-tools-use-exact-versions"; Optional exact_abi_tools_versions; diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 0e6c3d8529..7db0f4ae62 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -37,6 +37,8 @@ #include #include +#include + using namespace vcpkg; namespace @@ -778,6 +780,29 @@ namespace vcpkg variables.emplace_back("ARIA2", paths.get_tool_exe(Tools::ARIA2, stdout_sink)); } + if (!args.cmake_debug.empty()) + { + if (args.cmake_debug.size() == 1 || + std::find(args.cmake_debug.begin(), args.cmake_debug.end(), scf.core_paragraph->name) != + args.cmake_debug.end()) + { + variables.emplace_back("--debugger"); + variables.emplace_back(fmt::format("--debugger-pipe={}", *args.cmake_debug.begin())); + } + } + + if (!args.cmake_configure_debug.empty()) + { + if (args.cmake_configure_debug.size() == 1 || + std::find(args.cmake_configure_debug.begin(), + args.cmake_configure_debug.end(), + scf.core_paragraph->name) != args.cmake_configure_debug.end()) + { + variables.emplace_back(fmt::format("-DVCPKG_CMAKE_CONFIGURE_OPTIONS=--debugger;--debugger-pipe={}", + *args.cmake_configure_debug.begin())); + } + } + 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..977bb0d383 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -304,6 +304,9 @@ namespace vcpkg args.parser.parse_multi_option( BINARY_SOURCES_ARG, StabilityTag::Standard, args.cli_binary_sources, msg::format(msgBinarySourcesArg)); args.parser.parse_multi_option(CMAKE_SCRIPT_ARG, StabilityTag::Standard, args.cmake_args); + args.parser.parse_multi_option(CMAKE_DEBUGGING_ARG, StabilityTag::Experimental, args.cmake_debug); + args.parser.parse_multi_option( + CMAKE_CONFIGURE_DEBUGGING_ARG, StabilityTag::Experimental, args.cmake_configure_debug); std::vector feature_flags; args.parser.parse_multi_option(FEATURE_FLAGS_ARG, StabilityTag::Standard, feature_flags); @@ -804,5 +807,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; } From 7dcd7924f7f46d414e54215b8a8ea6fc722745c8 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 28 Aug 2023 17:29:34 -0700 Subject: [PATCH 2/3] * Make multiple uses of the new switches an error * Deduplicate the logic of "no entries means no filter, one or more entries means port filter" * Add unit test --- include/vcpkg/fwd/vcpkgcmdarguments.h | 1 + include/vcpkg/vcpkgcmdarguments.h | 25 ++++++++++++---- src/vcpkg-test/arguments.cpp | 19 +++++++++++++ src/vcpkg/commands.build.cpp | 19 ++++--------- src/vcpkg/vcpkgcmdarguments.cpp | 41 +++++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 21 deletions(-) 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 aefa9bb067..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,13 +176,13 @@ namespace vcpkg constexpr static StringLiteral GITHUB_REPOSITORY_OWNER_ID = "GITHUB_REPOSITORY_OWNER_ID"; Optional github_repository_owner_id; - constexpr static StringLiteral CMAKE_SCRIPT_ARG = "cmake-args"; - std::vector cmake_args; - constexpr static StringLiteral CMAKE_DEBUGGING_ARG = "cmake-debug"; - std::vector cmake_debug; + Optional cmake_debug; constexpr static StringLiteral CMAKE_CONFIGURE_DEBUGGING_ARG = "cmake-configure-debug"; - std::vector cmake_configure_debug; + Optional cmake_configure_debug; + + constexpr static StringLiteral CMAKE_SCRIPT_ARG = "cmake-args"; + std::vector cmake_args; constexpr static StringLiteral EXACT_ABI_TOOLS_VERSIONS_SWITCH = "abi-tools-use-exact-versions"; Optional exact_abi_tools_versions; diff --git a/src/vcpkg-test/arguments.cpp b/src/vcpkg-test/arguments.cpp index fa5fd6095f..3e79763727 100644 --- a/src/vcpkg-test/arguments.cpp +++ b/src/vcpkg-test/arguments.cpp @@ -160,3 +160,22 @@ 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 7db0f4ae62..a61e03ec60 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -37,8 +37,6 @@ #include #include -#include - using namespace vcpkg; namespace @@ -780,26 +778,21 @@ namespace vcpkg variables.emplace_back("ARIA2", paths.get_tool_exe(Tools::ARIA2, stdout_sink)); } - if (!args.cmake_debug.empty()) + if (auto cmake_debug = args.cmake_debug.get()) { - if (args.cmake_debug.size() == 1 || - std::find(args.cmake_debug.begin(), args.cmake_debug.end(), scf.core_paragraph->name) != - args.cmake_debug.end()) + if (cmake_debug->is_port_affected(scf.core_paragraph->name)) { variables.emplace_back("--debugger"); - variables.emplace_back(fmt::format("--debugger-pipe={}", *args.cmake_debug.begin())); + variables.emplace_back(fmt::format("--debugger-pipe={}", cmake_debug->value)); } } - if (!args.cmake_configure_debug.empty()) + if (auto cmake_configure_debug = args.cmake_configure_debug.get()) { - if (args.cmake_configure_debug.size() == 1 || - std::find(args.cmake_configure_debug.begin(), - args.cmake_configure_debug.end(), - scf.core_paragraph->name) != args.cmake_configure_debug.end()) + if (cmake_configure_debug->is_port_affected(scf.core_paragraph->name)) { variables.emplace_back(fmt::format("-DVCPKG_CMAKE_CONFIGURE_OPTIONS=--debugger;--debugger-pipe={}", - *args.cmake_configure_debug.begin())); + cmake_configure_debug->value)); } } diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 977bb0d383..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, @@ -304,9 +342,6 @@ namespace vcpkg args.parser.parse_multi_option( BINARY_SOURCES_ARG, StabilityTag::Standard, args.cli_binary_sources, msg::format(msgBinarySourcesArg)); args.parser.parse_multi_option(CMAKE_SCRIPT_ARG, StabilityTag::Standard, args.cmake_args); - args.parser.parse_multi_option(CMAKE_DEBUGGING_ARG, StabilityTag::Experimental, args.cmake_debug); - args.parser.parse_multi_option( - CMAKE_CONFIGURE_DEBUGGING_ARG, StabilityTag::Experimental, args.cmake_configure_debug); std::vector feature_flags; args.parser.parse_multi_option(FEATURE_FLAGS_ARG, StabilityTag::Standard, feature_flags); From 71895096bf584c22c2342c0b3a9a1283e5479cd1 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 28 Aug 2023 17:47:29 -0700 Subject: [PATCH 3/3] clang-format --- src/vcpkg-test/arguments.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vcpkg-test/arguments.cpp b/src/vcpkg-test/arguments.cpp index 3e79763727..474eb631f8 100644 --- a/src/vcpkg-test/arguments.cpp +++ b/src/vcpkg-test/arguments.cpp @@ -163,8 +163,10 @@ TEST_CASE ("Feature flag off", "[arguments]") TEST_CASE ("CMake debugger flags", "[arguments]") { - std::vector t = { - "--x-cmake-debug", "\\\\.\\pipe\\tespipe;zlib;bar;baz", "--x-cmake-configure-debug", "\\\\.\\pipe\\configure-pipe"}; + 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");