Skip to content

Commit

Permalink
Support for bazel on garden (#399)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
  • Loading branch information
mjcarroll and caguero authored Dec 8, 2023
1 parent 290055f commit 1db0afe
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 65 deletions.
131 changes: 131 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
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,
copts = [
"-Wno-deprecated-declarations",
],
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()
91 changes: 91 additions & 0 deletions log/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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\\"',
'CORRUPT_DB_TEST_PATH=\\"transport/log/test/data/state.tlog\\"',
],
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()
2 changes: 1 addition & 1 deletion log/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif()
gz_build_tests(
TYPE "UNIT"
SOURCES ${gtest_sources}
LIB_DEPS ${log_lib_target} ${EXTRA_TEST_LIB_DEPS}
LIB_DEPS ${log_lib_target} ${EXTRA_TEST_LIB_DEPS} test_config
TEST_LIST logging_tests
)

Expand Down
5 changes: 3 additions & 2 deletions log/src/Log_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*
*/
#include "gtest/gtest.h"

#include <chrono>
#include <ios>
#include <string>
#include <unordered_set>

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

#include "test_utils.hh"

using namespace gz;
using namespace gz::transport;
Expand Down
1 change: 1 addition & 0 deletions log/test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gz_build_tests(
ChirpParams
${PROJECT_LIBRARY_TARGET_NAME}-log
${EXTRA_TEST_LIB_DEPS}
test_config
INCLUDE_DIRS
${CMAKE_BINARY_DIR}/test/
)
Expand Down
72 changes: 72 additions & 0 deletions parameters/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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"],
visibility = GZ_VISIBILITY,
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()
6 changes: 3 additions & 3 deletions src/CIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*
*/
#include "gtest/gtest.h"

#include <gz/msgs/stringmsg.pb.h>

#include "gz/transport/CIface.h"

#include "test_utils.hh"
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"

static int count;

//////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ endif()
# Build the unit tests.
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}
TEST_LIST test_list
LIB_DEPS ${EXTRA_TEST_LIB_DEPS})
LIB_DEPS ${EXTRA_TEST_LIB_DEPS} test_config)

foreach(test ${test_list})

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
4 changes: 2 additions & 2 deletions src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
* limitations under the License.
*
*/
#include "gtest/gtest.h"

#include <chrono>
#include <cstdlib>
#include <memory>
#include <string>
#include <thread>

#include "gtest/gtest.h"
#include "gz/transport/AdvertiseOptions.hh"
#include "gz/transport/Discovery.hh"
#include "gz/transport/Publisher.hh"
#include "gz/transport/TransportTypes.hh"
#include "gz/transport/Uuid.hh"

#include "test_utils.hh"
#include "gz/utils/Environment.hh"
#include "gz/utils/ExtraTestMacros.hh"

#include "test_config.hh"

using namespace gz;
using namespace transport;
Expand Down
Loading

0 comments on commit 1db0afe

Please sign in to comment.