Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Oct 29, 2024
1 parent b1e4eac commit 8d8a62b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 82 deletions.
11 changes: 10 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
common --enable_bzlmod
common --lockfile_mode=off
build --cxxopt='-std=c++20'

# Add C++17 compiler flags.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17

build --force_pic
build --strip=never
build --strict_system_includes
build --fission=dbg
build --features=per_object_debug_info
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
USE_BAZEL_VERSION=latest
7.3.1
167 changes: 103 additions & 64 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_gz//gz:headers.bzl", "gz_configure_header", "gz_export_header")
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@rules_gazebo//gazebo:headers.bzl", "gz_configure_header", "gz_export_header")
load("@rules_license//rules:license.bzl", "license")

package(
Expand All @@ -14,69 +14,43 @@ license(
licenses(["notice"])

exports_files([
"package.xml",
"LICENSE",
"MODULE.bazel",
])

gz_export_header(
name = "Export",
out = "include/sdf/Export.hh",
export_base = "GZ_SDFORMAT",
lib_name = "sdformat",
)

gz_configure_header(
name = "config",
name = "Config",
src = "include/sdf/config.hh.in",
cmakelists = ["CMakeLists.txt"],
defines = {
"CMAKE_INSTALL_FULL_DATAROOTDIR": "unused",
"PROJECT_NAME": "sdformat",
"PROJECT_VERSION": "15.0.0",
"PROJECT_VERSION_FULL": "15.0.0",
"PROJECT_VERSION_MAJOR": "15",
"PROJECT_VERSION_MINOR": "0",
"PROJECT_VERSION_PATCH": "0",
"SDF_PROTOCOL_VERSION": "1.12",
"SDF_PROTOCOL_VERSION": "11111",
},
package = "sdformat",
package_xml = "package.xml",
)

gz_export_header(
name = "include/sdf/Export.hh",
export_base = "GZ_SDFORMAT",
lib_name = "sdformat",
visibility = ["//visibility:private"],
py_binary(
name = "embed_sdf",
srcs = ["sdf/embedSdf.py"],
main = "sdf/embedSdf.py",
)

public_headers_no_gen = glob([
"include/sdf/*.h",
"include/sdf/*.hh",
])

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

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

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

cc_library(
name = "installation_directories",
srcs = ["src/InstallationDirectories.cc"],
hdrs = [
"include/sdf/Export.hh",
"include/sdf/InstallationDirectories.hh",
"include/sdf/config.hh",
"include/sdf/sdf_config.h",
"include/sdf/system_util.hh",
],
defines = [
'CMAKE_INSTALL_RELATIVE_DATAROOTDIR=\\"unused\\"',
],
includes = ["include"],
visibility = ["//visibility:private"],
genrule(
name = "embed_sdf_genrule",
srcs = glob([
"sdf/**/*.sdf",
"sdf/**/*.convert",
]),
outs = ["EmbeddedSdf.cc"],
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdf/ --input-files $(SRCS)", # noqa
tools = [":embed_sdf"],
)

cc_library(
Expand All @@ -103,31 +77,96 @@ cc_library(

cc_library(
name = "sdformat",
srcs = sources + private_headers,
hdrs = public_headers,
includes = ["include"],
visibility = ["//visibility:public"],
srcs = glob(
include = [
"src/*.cc",
"src/*.hh",
"src/bazel/*.cc",
],
exclude = [
"src/*_TEST.cc",
],
) + ["EmbeddedSdf.cc"],
hdrs = glob(
include = [
"include/sdf/*.hh",
],
exclude = [
],
),
defines = [
"CMAKE_INSTALL_RELATIVE_DATAROOTDIR=\\\"\\\"",
'SDF_SHARE_PATH=\\".\\"',
'SDF_VERSION_PATH=\\"sdformat\\"',
],
includes = [
"include",
"src",
],
data = [
"sdf"
],
deps = [
":installation_directories",
":Config",
":Export",
":urdf_parser",
"@gz-math",
"@gz-utils",
"@gz-math//:Angle",
"@gz-math//:Box",
"@gz-math//:Capsule",
"@gz-math//:Color",
"@gz-math//:Cone",
"@gz-math//:Cylinder",
"@gz-math//:Ellipsoid",
"@gz-math//:Graph",
"@gz-math//:Inertial",
"@gz-math//:Pose3",
"@gz-math//:SemanticVersion",
"@gz-math//:Sphere",
"@gz-math//:SphericalCoordinates",
"@gz-math//:Temperature",
"@gz-math//:Vector2",
"@gz-utils//:Environment",
"@gz-utils//:ImplPtr",
],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
cc_test(
name = "Actor_TEST",
srcs = [
"src/Actor_TEST.cc",
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "sdformat",
},
deps = [
":sdformat",
"@gtest",
"@gtest//:gtest_main",
"@googletest//:gtest_main",
],
) for src in test_sources]
)

cc_test(
name = "Console_TEST",
srcs = [
"src/Console_TEST.cc",
],
deps = [
":sdformat",
"@googletest//:gtest_main",
],
)

cc_test(
name = "Element_TEST",
srcs = [
"src/Element_TEST.cc",
],
deps = [
":sdformat",
"//test:test_utils",
"@googletest//:gtest_main",
],
)

# Bazel linting
buildifier(
Expand Down
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ bazel_dep(name = "rules_license", version = "0.0.8")
bazel_dep(name = "tinyxml2", version = "10.0.0")

# Gazebo Dependencies
bazel_dep(name = "rules_gz")
bazel_dep(name = "rules_gazebo")
bazel_dep(name = "gz-utils")
bazel_dep(name = "gz-math")

local_path_override(
module_name = "rules_gz",
path = "/usr/local/google/home/mjcarroll/workspaces/gz_ionic_bazel/rules_gz",
module_name = "rules_gazebo",
path = "/usr/local/google/home/mjcarroll/workspaces/gz_ionic_bazel/rules_gazebo",
)

local_path_override(
Expand Down
13 changes: 0 additions & 13 deletions include/sdf/Console.hh
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,6 @@ namespace sdf
return *this;
}
} // namespace SDF_VERSION_NAMESPACE

/// \brief Internal namespace. Functions and classes defined in this namespace
/// are for internal use only and maybe removed without a deprecation cycle.
namespace internal
{
/// \brief Prints the error to _out or throw using SDF_ASSERT depending on the
/// ErrorCode in _error.
/// \param[out] _out ostream to use for printing errors.
/// \param[in] _error _error The error object to be printed
void SDFORMAT_VISIBLE throwOrPrintError(sdf::Console::ConsoleStream &_out,
const sdf::Error &_error);
} // namespace internal
/// \}
} // namepsace sdf

#ifdef _WIN32
Expand Down
5 changes: 5 additions & 0 deletions src/Actor_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "sdf/Actor.hh"
#include "sdf/Plugin.hh"

#include <filesystem>

/////////////////////////////////////////////////
sdf::Animation CreateDummyAnimation()
{
Expand Down Expand Up @@ -509,6 +511,9 @@ TEST(DOMActor, ToElement)
{
sdf::Actor actor;

// Output the current working directory
std::cout << std::filesystem::current_path() << std::endl;

actor.SetName("my-actor");
actor.SetRawPose(gz::math::Pose3d(1, 2, 3, 0.1, 0.2, 0.3));
actor.SetSkinFilename("my-skinfilename");
Expand Down
4 changes: 4 additions & 0 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,13 @@ const std::string &SDF::EmbeddedSpec(
const std::string &SDF::EmbeddedSpec(
sdf::Errors &_errors, const std::string &_filename)
{

try
{
const std::string pathname = SDF::Version() + "/" + _filename;

std::cout << "Reading: " << pathname << std::endl;

return GetEmbeddedSdf().at(pathname);
}
catch(const std::out_of_range &)
Expand Down

0 comments on commit 8d8a62b

Please sign in to comment.