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

Add libassert library #135

Merged
merged 7 commits into from
Oct 17, 2023
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
22 changes: 21 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
workspace(name = "robot")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
Expand Down Expand Up @@ -199,6 +198,26 @@ http_archive(
sha256 = "1ccaabbfe870f60af3d6a519c53e09f3dcf630207321dffa553564a8e75c4fc8",
)

http_archive(
name = "cpptrace",
url = "https://github.com/jeremy-rifkin/cpptrace/archive/refs/tags/v0.2.1.zip",
strip_prefix = "cpptrace-0.2.1",
build_file = "@//third_party:BUILD.cpptrace",
patches = [
"@//third_party:cpptrace-0001-config.patch",
],
patch_args=["-p1"],
sha256 = "d274b672286825aba5ba11f4a87e3c1995ac43a5c4fd57f319fb77eb574cfcfd"
)

http_archive(
name = "assert",
url = "https://github.com/jeremy-rifkin/libassert/archive/f81df0aae6915fdbf7d5ea2ac24f77cb2e0e7ee1.zip",
build_file = "@//third_party:BUILD.assert",
strip_prefix = "libassert-f81df0aae6915fdbf7d5ea2ac24f77cb2e0e7ee1",
sha256 = "b1da53cbb265b2d943ed9063696567751c62c3e2836b6bfa04d1cf0b8eb5a971",
)

http_archive(
name = "sophus_lie",
urls = ["https://github.com/strasdat/Sophus/archive/refs/tags/1.22.4.zip"],
Expand Down Expand Up @@ -268,6 +287,7 @@ http_archive(
build_file_content="#",
sha256="bc7259271c058d4ad68a898b9f2aeec44cbaa6e25a45eb0bfd57387905bdfca5",
)

load("@drake_lib//:share/drake/repo.bzl", "drake_repository")
drake_repository(name="drake", excludes=["eigen", "fmt"])

Expand Down
18 changes: 18 additions & 0 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,21 @@ cc_library(
],
visibility = ["//visibility:public"],
)

cc_library(
name = "check",
hdrs = ["check.hh"],
deps = [
"@assert",
],
visibility = ["//visibility:public"],
)

cc_test(
name = "check_test",
srcs = ["check_test.cc"],
deps = [
":check",
"@com_google_googletest//:gtest_main",
]
)
8 changes: 8 additions & 0 deletions common/check.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#include "assert/assert.hpp"

#define CHECK(expr, ...) ASSERT_INVOKE(expr, false, true, "CHECK", verification, , __VA_ARGS__)

namespace robot {
using check_failure = libassert::verification_failure;
}
6 changes: 6 additions & 0 deletions common/check_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#include "common/check.hh"

#include "gtest/gtest.h"

TEST(AssertTest, assert_test) { EXPECT_THROW(CHECK(false), robot::check_failure); }
14 changes: 14 additions & 0 deletions third_party/BUILD.assert
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

cc_library(
name = "assert",
hdrs = ["include/assert.hpp"],
srcs = [
"src/assert.cpp",
"third_party/magic_enum.hpp",
],
copts = ["-I external/assert/include"],
include_prefix = "assert",
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = ["@cpptrace"],
)
34 changes: 34 additions & 0 deletions third_party/BUILD.cpptrace
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

cc_library(
name = "dwarf",
hdrs = [
"bundled/libdwarf/libdwarf.h",
"bundled/libdwarf/dwarf.h"
],
srcs = [
"bundled/libdwarf/config.h",
"bundled/libdwarf/libdwarf_private.h"] +
glob([
"bundled/libdwarf/dwarf_*.h",
"bundled/libdwarf/dwarf_*.c"]),
strip_include_prefix="bundled/libdwarf",
deps = [
"@zlib",
]
)

cc_library(
name = "cpptrace",
hdrs = ["include/cpptrace/cpptrace.hpp"],
srcs = glob(["src/**/*"]),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
local_defines=[
"CPPTRACE_UNWIND_WITH_UNWIND",
"CPPTRACE_DEMANGLE_WITH_CXXABI",
"CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF",
],
deps = [
":dwarf",
],
)
Loading