Skip to content

Commit

Permalink
Introduce --x-cmake-debug and --x-cmake-configure-debug (#1173)
Browse files Browse the repository at this point in the history
Co-authored-by: Billy Robert O'Neal III <[email protected]>
  • Loading branch information
Neumann-A and BillyONeal authored Sep 4, 2023
1 parent 2b3f100 commit efcf58d
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/vcpkg/fwd/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ namespace vcpkg
struct HelpTableFormatter;
struct VcpkgCmdArguments;
struct FeatureFlagSettings;
struct PortApplicableSetting;
}
20 changes: 20 additions & 0 deletions include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> affected_ports;
};

struct VcpkgCmdArguments
{
static VcpkgCmdArguments create_from_command_line(const ILineReader& fs,
Expand Down Expand Up @@ -161,6 +176,11 @@ namespace vcpkg
constexpr static StringLiteral GITHUB_REPOSITORY_OWNER_ID = "GITHUB_REPOSITORY_OWNER_ID";
Optional<std::string> github_repository_owner_id;

constexpr static StringLiteral CMAKE_DEBUGGING_ARG = "cmake-debug";
Optional<PortApplicableSetting> cmake_debug;
constexpr static StringLiteral CMAKE_CONFIGURE_DEBUGGING_ARG = "cmake-configure-debug";
Optional<PortApplicableSetting> cmake_configure_debug;

constexpr static StringLiteral CMAKE_SCRIPT_ARG = "cmake-args";
std::vector<std::string> cmake_args;

Expand Down
21 changes: 21 additions & 0 deletions src/vcpkg-test/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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"));
}
18 changes: 18 additions & 0 deletions src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions src/vcpkg/vcpkgcmdarguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <vcpkg/metrics.h>
#include <vcpkg/vcpkgcmdarguments.h>

#include <algorithm>
#include <string>
#include <utility>

namespace
{
using namespace vcpkg;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

0 comments on commit efcf58d

Please sign in to comment.