diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..f2d06137d --- /dev/null +++ b/.bazelrc @@ -0,0 +1,12 @@ +common --enable_bzlmod +common --lockfile_mode=off + +# 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 diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 000000000..643916c03 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.3.1 diff --git a/.gitignore b/.gitignore index fe7c191e7..962b6a180 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build_* *.*.sw? .vscode __pycache__ +bazel-* diff --git a/BUILD.bazel b/BUILD.bazel index 0e26e2c84..8d936611f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,36 +1,42 @@ -load( - "@gz//bazel/skylark:build_defs.bzl", - "GZ_FEATURES", - "GZ_ROOT", - "GZ_VISIBILITY", - "add_lint_tests", - "gz_configure_file", - "gz_configure_header", - "gz_export_header", - "gz_include_header", - "gz_py_binary", -) +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( - default_visibility = GZ_VISIBILITY, - features = GZ_FEATURES, + default_applicable_licenses = [":license"], +) + +license( + name = "license", + package_name = "sdformat", ) licenses(["notice"]) -exports_files(["LICENSE"]) +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", + "SDF_PROTOCOL_VERSION": "11111", }, - package = "sdformat", + package_xml = "package.xml", ) -gz_py_binary( +py_binary( name = "embed_sdf", srcs = ["sdf/embedSdf.py"], main = "sdf/embedSdf.py", @@ -43,49 +49,12 @@ genrule( "sdf/**/*.convert", ]), outs = ["EmbeddedSdf.cc"], - cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdformat/sdf/ --input-files $(SRCS)", # noqa + cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdf/ --input-files $(SRCS)", # noqa tools = [":embed_sdf"], ) -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/gz.cc", - ], -) - -gz_export_header( - name = "include/sdf/Export.hh", - export_base = "GZ_SDFORMAT", - lib_name = "sdf", - visibility = ["//visibility:private"], -) - -gz_include_header( - name = "sdformat_hh_genrule", - out = "include/sdformat.hh", - hdrs = public_headers_no_gen + [ - "include/sdf/config.hh", - "include/sdf/Export.hh", - ], -) - -public_headers = public_headers_no_gen + [ - "include/sdf/Export.hh", - "include/sdf/config.hh", - "include/sdformat.hh", -] - cc_library( - name = "urdf", + name = "urdf_parser", srcs = [ "src/urdf/urdf_parser/joint.cpp", "src/urdf/urdf_parser/link.cpp", @@ -108,9 +77,25 @@ cc_library( cc_library( name = "sdformat", - srcs = sources + private_headers + ["EmbeddedSdf.cc"], - hdrs = public_headers, + 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\\"', ], @@ -118,36 +103,37 @@ cc_library( "include", "src", ], + data = [ + "sdf" + ], deps = [ - ":urdf", - GZ_ROOT + "math", - GZ_ROOT + "utils", - "@tinyxml2", + ":Config", + ":Export", + ":urdf_parser", + "@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_library( - name = "sdformat_internal", +cc_test( + name = "Actor_TEST", srcs = [ - "src/gz.cc", - "src/gz.hh", - ], - visibility = ["//visibility:private"], - deps = [":sdformat"], -) - -test_sources = glob( - ["src/*_TEST.cc"], - exclude = ["src/gz_TEST.cc"], -) - -[cc_test( - name = src.replace("/", "_").replace(".cc", "").replace("src_", ""), - srcs = [src], - data = [ - "sdf", - GZ_ROOT + "sdformat/test:integration", - GZ_ROOT + "sdformat/test:sdf", + "src/Actor_TEST.cc", ], env = { "GZ_BAZEL": "1", @@ -155,46 +141,46 @@ test_sources = glob( }, deps = [ ":sdformat", - GZ_ROOT + "sdformat/test:test_utils", - "@gtest", - "@gtest//:gtest_main", + "@googletest//:gtest_main", ], -) for src in test_sources] - -gz_configure_file( - name = "sdformat.rb", - src = "src/cmd/cmdsdformat.rb.in", - out = "cmdsdformat.rb", - cmakelists = ["CMakeLists.txt"], - defines = [ - "library_location=libgz-sdformat.so", - ], - package = "sdformat", - visibility = [GZ_ROOT + "tools:__pkg__"], ) -gz_configure_file( - name = "sdformat_yaml", - src = "conf/sdformat.yaml.in", - out = "sdformat.yaml", - cmakelists = ["CMakeLists.txt"], - defines = [ - "gz_library_path=gz/sdformat/cmdsdformat.rb", +cc_test( + name = "Console_TEST", + srcs = [ + "src/Console_TEST.cc", + ], + deps = [ + ":sdformat", + "@googletest//:gtest_main", ], - package = "sdformat", - visibility = [GZ_ROOT + "tools:__pkg__"], ) -cc_binary( - name = "libgz-sdformat.so", - srcs = [":sdformat_internal"], - linkshared = True, - visibility = [GZ_ROOT + "tools:__pkg__"], +cc_test( + name = "Element_TEST", + srcs = [ + "src/Element_TEST.cc", + ], deps = [ ":sdformat", + "//test:test_utils", + "@googletest//:gtest_main", ], ) -exports_files(["sdf"]) +# Bazel linting +buildifier( + name = "buildifier.fix", + exclude_patterns = ["./.git/*"], + lint_mode = "fix", + mode = "fix", +) -add_lint_tests() +buildifier_test( + name = "buildifier.test", + exclude_patterns = ["./.git/*"], + lint_mode = "warn", + mode = "diff", + no_sandbox = True, + workspace = "//:MODULE.bazel", +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..5fa4ee358 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,27 @@ +## MODULE.bazel +module( + name = "sdformat", + repo_name = "org_gazebosim_sdformat", +) + +bazel_dep(name = "buildifier_prebuilt", version = "6.1.2") +bazel_dep(name = "googletest", version = "1.14.0") +bazel_dep(name = "rules_license", version = "0.0.8") +bazel_dep(name = "tinyxml2", version = "10.0.0") + +# Gazebo Dependencies +bazel_dep(name = "rules_gazebo", version = "0.0.2") +bazel_dep(name = "gz-utils") +bazel_dep(name = "gz-math") + +archive_override( + module_name = "gz-utils", + strip_prefix = "gz-utils-gz-utils3", + urls = ["https://github.com/gazebosim/gz-utils/archive/refs/heads/gz-utils3.tar.gz"], +) + +archive_override( + module_name = "gz-math", + strip_prefix = "gz-math-gz-math8", + urls = ["https://github.com/gazebosim/gz-math/archive/refs/heads/gz-math8.tar.gz"], +) diff --git a/src/Actor_TEST.cc b/src/Actor_TEST.cc index 5698bf5bc..6c800f098 100644 --- a/src/Actor_TEST.cc +++ b/src/Actor_TEST.cc @@ -20,6 +20,8 @@ #include "sdf/Actor.hh" #include "sdf/Plugin.hh" +#include + ///////////////////////////////////////////////// sdf::Animation CreateDummyAnimation() { @@ -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"); diff --git a/src/SDF.cc b/src/SDF.cc index 04fc53748..23b62ca49 100644 --- a/src/SDF.cc +++ b/src/SDF.cc @@ -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 &) diff --git a/src/parser_urdf.cc b/src/parser_urdf.cc index d8d2b2352..fac4ea5bd 100644 --- a/src/parser_urdf.cc +++ b/src/parser_urdf.cc @@ -35,8 +35,8 @@ #include #include "sdf/Error.hh" -#include "sdf/sdf.hh" #include "sdf/Types.hh" +#include "sdf/Frame.hh" #include "XmlUtils.hh" #include "SDFExtension.hh" diff --git a/test/BUILD.bazel b/test/BUILD.bazel deleted file mode 100644 index bb1baa410..000000000 --- a/test/BUILD.bazel +++ /dev/null @@ -1,72 +0,0 @@ -load( - "@gz//bazel/skylark:build_defs.bzl", - "GZ_FEATURES", - "GZ_ROOT", - "GZ_VISIBILITY", - "cmake_configure_file", -) - -package( - default_visibility = GZ_VISIBILITY, - features = GZ_FEATURES, -) - -licenses(["notice"]) - -cmake_configure_file( - name = "config", - src = "test_config.hh.in", - out = "test_config.hh", - cmakelists = ["CMakeLists.txt"], - defines = [], -) - -cc_library( - name = "test_utils", - hdrs = [ - "test_config.hh", - "test_utils.hh", - ], - includes = ["."], - deps = [ - GZ_ROOT + "utils:utils", - GZ_ROOT + "sdformat:sdformat", - ], -) - -integration_test_sources = glob( - ["integration/*.cc"], - exclude = [ - "integration/schema_test.cc", - "integration/element_memory_leak.cc", - ], -) - -[cc_test( - name = src.replace("/", "_").replace(".cc", "").replace("integration_", "INTEGRATION_"), - srcs = [ - src, - "integration/toml_parser.hh", - ], - data = [ - GZ_ROOT + "sdformat:sdf", - "integration", - "sdf", - ], - env = { - "GZ_BAZEL": "1", - "GZ_BAZEL_PATH": "sdformat", - }, - includes = ["integration"], - deps = [ - GZ_ROOT + "sdformat:sdformat", - ":test_utils", - "@gtest", - "@gtest//:gtest_main", - ], -) for src in integration_test_sources] - -exports_files([ - "sdf", - "integration", -])