Skip to content

Commit

Permalink
Support for bazel on garden
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 10, 2023
1 parent 725841d commit d5ac757
Show file tree
Hide file tree
Showing 16 changed files with 502 additions and 237 deletions.
128 changes: 128 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"]) # Apache-2.0

exports_files(["LICENSE"])

gz_configure_header(
name = "transport_config_hh",
src = "include/gz/transport/config.hh.in",
cmakelists = ["CMakeLists.txt"],
package = "transport",
)

gz_export_header(
name = "include/gz/transport/Export.hh",
export_base = "GZ_TRANSPORT",
lib_name = "gz-transport",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/transport/*.h",
"include/gz/transport/*.hh",
"include/gz/transport/detail/*.hh",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
],
)

gz_include_header(
name = "transport_hh_genrule",
out = "include/gz/transport.hh",
hdrs = public_headers_no_gen + [
"include/gz/transport/config.hh",
"include/gz/transport/Export.hh",
],
)

public_headers = public_headers_no_gen + [
"include/gz/transport/config.hh",
"include/gz/transport/Export.hh",
"include/gz/transport.hh",
]

cc_library(
name = "transport",
srcs = sources + private_headers,
hdrs = public_headers,
includes = ["include"],
deps = [
GZ_ROOT + "msgs",
"@uuid",
"@zmq",
],
)

cc_binary(
name = "topic",
srcs = [
"src/cmd/gz.cc",
"src/cmd/gz.hh",
"src/cmd/topic_main.cc",
],
includes = ["src/cmd"],
deps = [
":transport",
GZ_ROOT + "utils/cli",
],
)

cc_binary(
name = "service",
srcs = [
"src/cmd/gz.cc",
"src/cmd/gz.hh",
"src/cmd/service_main.cc",
],
includes = ["src/cmd"],
deps = [
":transport",
GZ_ROOT + "utils/cli",
],
)

test_sources = glob(
include = ["src/*_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "transport",
},
deps = [
":transport",
GZ_ROOT + "common/testing",
GZ_ROOT + "transport/test:utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

add_lint_tests()
90 changes: 90 additions & 0 deletions log/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"cmake_configure_file",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)

cmake_configure_file(
name = "build_config",
src = "src/build_config.hh.in",
out = "include/build_config.hh",
cmakelists = ["src/CMakeLists.txt"],
defines = [
"SCHEMA_INSTALL_PATH=transport/log/sql",
],
)

gz_export_header(
name = "include/gz/transport/log/Export.hh",
export_base = "GZ_TRANSPORT_LOG",
lib_name = "gz-transport-log",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/transport/log/*.hh",
"include/gz/transport/log/detail/*.hh",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
],
)

public_headers = public_headers_no_gen + [
"include/gz/transport/log/Export.hh",
]

cc_library(
name = "log",
srcs = sources + private_headers + ["include/build_config.hh"],
hdrs = public_headers,
data = ["sql/0.1.0.sql"],
includes = ["include"],
deps = [
GZ_ROOT + "transport",
"@sqlite3",
],
)

test_sources = glob(
include = ["src/*_TEST.cc"],
exclude = ["src/LogCommandAPI_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
data = [
"test/data/state.tlog",
],
defines = [
'GZ_TRANSPORT_LOG_TEST_PATH=\\"transport/log/test\\"',
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "transport",
},
deps = [
":log",
GZ_ROOT + "common/testing",
GZ_ROOT + "transport/test:utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

add_lint_tests()
7 changes: 5 additions & 2 deletions log/src/Log_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
#include <unordered_set>

#include "gz/transport/log/Log.hh"
#include "test_config.hh"
#include "log/test_config.hh"
#include "gtest/gtest.h"

#include "test_utils.hh"

using namespace gz;
using namespace gz::transport;
using namespace std::chrono_literals;
Expand Down Expand Up @@ -254,6 +254,9 @@ TEST(Log, OpenCorruptDatabase)
std::string path =
testing::portablePathUnion(GZ_TRANSPORT_LOG_TEST_PATH, "data");
path = testing::portablePathUnion(path, "state.tlog");

std::cout << path << std::endl;

logFile.Open(path);
EXPECT_GT(logFile.EndTime(), 0ns) << "logFile.EndTime() == "
<< logFile.EndTime().count() << "ns";;
Expand Down
71 changes: 71 additions & 0 deletions parameters/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"cmake_configure_file",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)

gz_export_header(
name = "include/gz/transport/parameters/Export.hh",
export_base = "GZ_TRANSPORT_PARAMETERS",
lib_name = "gz-transport-parameters",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/transport/parameters/*.hh",
"include/gz/transport/parameters/detail/*.hh",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
],
)

public_headers = public_headers_no_gen + [
"include/gz/transport/parameters/Export.hh",
]

cc_library(
name = "parameters",
srcs = sources + private_headers,
hdrs = public_headers,
includes = ["include"],
deps = [
GZ_ROOT + "transport",
"@sqlite3",
],
)

test_sources = glob(
include = ["src/*_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "transport",
},
deps = [
":parameters",
GZ_ROOT + "transport/test:utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

add_lint_tests()
3 changes: 2 additions & 1 deletion src/CIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#include "gtest/gtest.h"
#include "gz/transport/CIface.h"
#include "test_config.hh"

#include "test_utils.hh"

static int count;

Expand Down
1 change: 0 additions & 1 deletion src/Clock_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "gz/transport/Clock.hh"
#include "gz/transport/Node.hh"
#include "gz/transport/TransportTypes.hh"
#include "test_config.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
14 changes: 1 addition & 13 deletions src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,8 @@
#include "gz/transport/Publisher.hh"
#include "gz/transport/TransportTypes.hh"
#include "gz/transport/Uuid.hh"
#include "test_config.hh"

// Temporarily introduce a "DISABLED_ON_LINUX" macro.
// It currently does not exist upstream.
// This can be removed when it is in upstream gz-utils
// or the discovery WrongGzIp test passes on linux
#include <gz/utils/detail/ExtraTestMacros.hh>
#if defined __linux__
#define GZ_UTILS_TEST_DISABLED_ON_LINUX(TestName) \
DETAIL_GZ_UTILS_ADD_DISABLED_PREFIX(TestName)
#else
#define GZ_UTILS_TEST_DISABLED_ON_LINUX(TestName) \
TestName
#endif // defined __linux__
#include "test_utils.hh"

using namespace gz;
using namespace transport;
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "gz/transport/Helpers.hh"
#include "test_config.hh"
#include "test_utils.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
1 change: 0 additions & 1 deletion src/NodeOptions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "gz/transport/NetUtils.hh"
#include "gz/transport/NodeOptions.hh"
#include "test_config.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
3 changes: 2 additions & 1 deletion src/Node_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include "gz/transport/TopicStatistics.hh"
#include "gz/transport/TopicUtils.hh"
#include "gz/transport/TransportTypes.hh"
#include "test_config.hh"

#include "test_utils.hh"

using namespace gz;

Expand Down
1 change: 0 additions & 1 deletion src/SubscribeOptions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "gz/transport/Helpers.hh"
#include "gz/transport/SubscribeOptions.hh"
#include "test_config.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
1 change: 0 additions & 1 deletion src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "gtest/gtest.h"
#include "gz/transport/Node.hh"
#include "test_config.hh"

#ifdef _MSC_VER
# define popen _popen
Expand Down
Loading

0 comments on commit d5ac757

Please sign in to comment.