Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building with Bazel #1033

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ jobs:
- name: Test
run: meson test -C build-meson

bazel-build:
name: Bazel build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build
run: bazel build //...

- name: Test
run: bazel test --test_output=errors //...

install:
name: install tests
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ a.out*
/html/*
!/meson.build
/CMakeUserPresets.json
/bazel-*
/MODULE.bazel.lock

/node_modules/*
/package.json
Expand Down
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_library(
name = "cli11",
srcs = glob(["src/**/*.cpp"]),
hdrs = glob(["include/**/*.hpp"]),
local_defines = ["CLI11_COMPILE"],
strip_include_prefix = "/include",
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module(name = "cli11")

bazel_dep(name = "catch2", version = "3.5.4", dev_dependency = True)
75 changes: 75 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
cc_binary(
name = "ensure_utf8",
srcs = ["applications/ensure_utf8.cpp"],
deps = ["//:cli11"],
)

cc_binary(
name = "ensure_utf8_twice",
srcs = ["applications/ensure_utf8_twice.cpp"],
deps = ["//:cli11"],
)

cc_library(
name = "catch_main",
srcs = ["main.cpp"],
hdrs = ["catch.hpp"],
defines = ["CLI11_CATCH3"],
deps = ["@catch2//:catch2_main"],
)

cc_test(
name = "AppTest",
srcs = [
"AppTest.cpp",
"app_helper.hpp",
],
data = [
"ensure_utf8",
"ensure_utf8_twice",
],
local_defines = [
'CLI11_ENSURE_UTF8_EXE=\\"$(rootpath ensure_utf8)\\"',
'CLI11_ENSURE_UTF8_TWICE_EXE=\\"$(rootpath ensure_utf8_twice)\\"',
],
deps = [
"catch_main",
"//:cli11",
"@catch2",
],
)

[
cc_test(
name = test,
srcs = [
test + ".cpp",
"app_helper.hpp",
],
deps = [
"catch_main",
"//:cli11",
"@catch2",
],
)
for test in [
"HelpersTest",
"ConfigFileTest",
"OptionTypeTest",
"SimpleTest",
"SetTest",
"TransformTest",
"CreationTest",
"SubcommandTest",
"HelpTest",
"FormatterTest",
"NewParseTest",
"OptionalTest",
"DeprecatedTest",
"StringParseTest",
"ComplexTypeTest",
"TrueFalseTest",
"OptionGroupTest",
"EncodingTest",
]
]
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ file(
GLOB_RECURSE DATA_FILES
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/data/*")
"${CMAKE_CURRENT_SOURCE_DIR}/data/*" "${CMAKE_CURRENT_SOURCE_DIR}/tests/.gitkeep")

foreach(DATA_FILE IN LISTS DATA_FILES)
add_custom_command(
Expand Down
6 changes: 3 additions & 3 deletions tests/HelpersTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ TEST_CASE("Validators: FileIsDir", "[helpers]") {
}

TEST_CASE("Validators: DirectoryExists", "[helpers]") {
std::string mydir{"../tests"};
std::string mydir{"tests"};
CHECK(CLI::ExistingDirectory(mydir).empty());
}

Expand All @@ -543,7 +543,7 @@ TEST_CASE("Validators: DirectoryIsFile", "[helpers]") {
}

TEST_CASE("Validators: PathExistsDir", "[helpers]") {
std::string mydir{"../tests"};
std::string mydir{"tests"};
CHECK(CLI::ExistingPath(mydir).empty());
}

Expand Down Expand Up @@ -665,7 +665,7 @@ TEST_CASE("Validators: CombinedPaths", "[helpers]") {
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
CHECK(ok);

std::string dir{"../tests"};
std::string dir{"tests"};
std::string notpath{"nondirectory"};

auto path_or_dir = CLI::ExistingPath | CLI::ExistingDirectory;
Expand Down
Empty file added tests/tests/.gitkeep
Empty file.
Loading