Skip to content

Commit

Permalink
Bazel updates for Garden build (#1239)
Browse files Browse the repository at this point in the history
* Cherry-pick the python3 embedSdf script and tests (#884)

These won't be used as part of the cmake build on this branch, but are
useful for generating the same file from bazel.

Co-authored-by: Bi0T1N <[email protected]>
Co-authored-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>

* Improvements to embedSdf script

Signed-off-by: Michael Carroll <[email protected]>

* Update sdf/CMakeLists.txt

Signed-off-by: Michael Carroll <[email protected]>

Co-authored-by: Addisu Z. Taddese <[email protected]>

* Update bazel files

Signed-off-by: Michael Carroll <[email protected]>

* Lint

Signed-off-by: Michael Carroll <[email protected]>

* Add utils back to parser

Signed-off-by: Michael Carroll <[email protected]>

* Fix gz_TEST

Signed-off-by: Michael Carroll <[email protected]>

* Ignore pycache folders

Signed-off-by: Michael Carroll <[email protected]>

* Fix parser_TEST

Signed-off-by: Michael Carroll <[email protected]>

* Bazel nits

Signed-off-by: Michael Carroll <[email protected]>

* Fix path logic

Signed-off-by: Michael Carroll <[email protected]>

* Fix visibility

Signed-off-by: Michael Carroll <[email protected]>

* Fix strings

Signed-off-by: Michael Carroll <[email protected]>

* Use standard vars

Signed-off-by: Michael Carroll <[email protected]>

* Fix string conversions

Signed-off-by: Michael Carroll <[email protected]>

* Fix string conversions

Signed-off-by: Michael Carroll <[email protected]>

* Fix embedded sdf

Signed-off-by: Michael Carroll <[email protected]>

* Fix converter test

Signed-off-by: Michael Carroll <[email protected]>

* Lint

Signed-off-by: Michael Carroll <[email protected]>

* Update bazel files

Signed-off-by: Michael Carroll <[email protected]>

* Add detail prefix

Signed-off-by: Michael Carroll <[email protected]>

* Fix test path

Signed-off-by: Michael Carroll <[email protected]>

* Set homepath on Windows

Signed-off-by: Michael Carroll <[email protected]>

---------

Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Co-authored-by: Bi0T1N <[email protected]>
Co-authored-by: Bi0T1N <[email protected]>
Co-authored-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
4 people committed Dec 13, 2023
1 parent 24b6153 commit a20cf95
Show file tree
Hide file tree
Showing 23 changed files with 607 additions and 180 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build
build_*
*.*.sw?
.vscode

__pycache__
200 changes: 200 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
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",
)

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"])

exports_files(["LICENSE"])

gz_configure_header(
name = "config",
src = "include/sdf/config.hh.in",
cmakelists = ["CMakeLists.txt"],
defines = {
"CMAKE_INSTALL_FULL_DATAROOTDIR": "unused",
},
package = "sdformat",
)

gz_py_binary(
name = "embed_sdf",
srcs = ["sdf/embedSdf.py"],
main = "sdf/embedSdf.py",
)

genrule(
name = "embed_sdf_genrule",
srcs = glob([
"sdf/**/*.sdf",
"sdf/**/*.convert",
]),
outs = ["EmbeddedSdf.cc"],
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdformat/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",
srcs = [
"src/urdf/urdf_parser/joint.cpp",
"src/urdf/urdf_parser/link.cpp",
"src/urdf/urdf_parser/model.cpp",
"src/urdf/urdf_parser/pose.cpp",
"src/urdf/urdf_parser/twist.cpp",
"src/urdf/urdf_parser/urdf_model_state.cpp",
"src/urdf/urdf_parser/urdf_sensor.cpp",
"src/urdf/urdf_parser/world.cpp",
],
hdrs = glob(
["src/urdf/**/*.h"],
),
copts = ["-Wno-unknown-pragmas"],
includes = ["src/urdf"],
deps = [
"@tinyxml2",
],
)

cc_library(
name = "sdformat",
srcs = sources + private_headers + ["EmbeddedSdf.cc"],
hdrs = public_headers,
defines = [
'SDF_SHARE_PATH=\\".\\"',
'SDF_VERSION_PATH=\\"sdformat\\"',
],
includes = [
"include",
"src",
],
deps = [
":urdf",
GZ_ROOT + "math",
GZ_ROOT + "utils",
"@tinyxml2",
],
)

cc_library(
name = "sdformat_internal",
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",
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "sdformat",
},
deps = [
":sdformat",
GZ_ROOT + "sdformat/test:test_utils",
"@gtest",
"@gtest//: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",
],
package = "sdformat",
visibility = [GZ_ROOT + "tools:__pkg__"],
)

cc_binary(
name = "libgz-sdformat.so",
srcs = [":sdformat_internal"],
linkshared = True,
visibility = [GZ_ROOT + "tools:__pkg__"],
deps = [
":sdformat",
],
)

exports_files(["sdf"])

add_lint_tests()
5 changes: 5 additions & 0 deletions include/sdf/Param.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ namespace sdf
: val(_val), precision(_precision) {}
};

// Template deduction guide for ParamVariant
template<typename ParamVariant>
ParamStreamer(const ParamVariant &_val, int _precision)
-> ParamStreamer<ParamVariant>;

template<class T>
std::ostream& operator<<(std::ostream &os, ParamStreamer<T> s)
{
Expand Down
7 changes: 6 additions & 1 deletion include/sdf/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@

#cmakedefine SDFORMAT_DISABLE_CONSOLE_LOGFILE 1

#ifndef SDF_SHARE_PATH
#define SDF_SHARE_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/"
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${SDF_MAJOR_VERSION}/${SDF_PKG_VERSION}"
#endif

#ifndef SDF_VERSION_PATH
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${PROJECT_VERSION_MAJOR}/${PROJECT_VERSION}"
#endif

#endif // #ifndef SDF_CONFIG_HH_
4 changes: 2 additions & 2 deletions sdf/embedSdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def generate_map_content(paths: List[Path], relative_to: Optional[str] = None) -
for path in paths:
with open(path, "r", encoding="utf8") as input_sdf:
file_content = input_sdf.read()

# Strip relative path if requested
if relative_to is not None:
path = path.relative_to(relative_to)
_, relative_path = str(path).split(relative_to)
path = relative_path
content.append(embed_sdf_content(str(path), file_content))
return ",".join(content)

Expand Down
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ if (BUILD_TESTING)
XmlUtils.cc)
endif()

if(TARGET UNIT_gz_TEST)
target_compile_definitions(UNIT_gz_TEST PUBLIC "-DDETAIL_GZ_CONFIG_PATH=\"${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>\"")
if (TARGET UNIT_gz_TEST)
target_compile_definitions(UNIT_gz_TEST PRIVATE
-DGZ_PATH="${GZ_PROGRAM}"
-DDETAIL_GZ_CONFIG_PATH="${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>"
-DGZ_TEST_LIBRARY_PATH="${PROJECT_BINARY_DIR}/src")
endif()

if (TARGET UNIT_FrameSemantics_TEST)
Expand Down
2 changes: 1 addition & 1 deletion src/Capsule_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST(DOMCapsule, Load)
// Add a radius element
sdf::ElementPtr radiusDesc(new sdf::Element());
radiusDesc->SetName("radius");
radiusDesc->AddValue("double", "1.0", "1", "radius");
radiusDesc->AddValue("double", "1.0", true, "radius");
sdf->AddElementDescription(radiusDesc);
sdf::ElementPtr radiusElem = sdf->AddElement("radius");
radiusElem->Set<double>(2.0);
Expand Down
2 changes: 1 addition & 1 deletion src/Cylinder_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ TEST(DOMCylinder, Load)
// Add a radius element
sdf::ElementPtr radiusDesc(new sdf::Element());
radiusDesc->SetName("radius");
radiusDesc->AddValue("double", "1.0", "1", "radius");
radiusDesc->AddValue("double", "1.0", true, "radius");
sdf->AddElementDescription(radiusDesc);
sdf::ElementPtr radiusElem = sdf->AddElement("radius");
radiusElem->Set<double>(2.0);
Expand Down
2 changes: 1 addition & 1 deletion src/Plane_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ TEST(DOMPlane, Load)
// Add a normal element
sdf::ElementPtr normalDesc(new sdf::Element());
normalDesc->SetName("normal");
normalDesc->AddValue("vector3", "0 0 1", "1", "normal");
normalDesc->AddValue("vector3", "0 0 1", true, "normal");
sdf->AddElementDescription(normalDesc);
sdf::ElementPtr normalElem = sdf->AddElement("normal");
normalElem->Set<gz::math::Vector3d>({1, 0, 0});
Expand Down
18 changes: 14 additions & 4 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ inline namespace SDF_VERSION_NAMESPACE
// returns the version string when possible.
std::string SDF::version = SDF_VERSION; // NOLINT(runtime/string)

std::string sdfSharePath()
{
#ifdef SDF_SHARE_PATH
if (std::string(SDF_SHARE_PATH) != "/")
return SDF_SHARE_PATH;
#endif
return "";
}

/////////////////////////////////////////////////
void setFindCallback(std::function<std::string(const std::string &)> _cb)
{
Expand Down Expand Up @@ -109,16 +118,17 @@ std::string findFile(const std::string &_filename, bool _searchLocalPath,
}

// Next check the install path.
std::string path = sdf::filesystem::append(SDF_SHARE_PATH, filename);
std::string path = sdf::filesystem::append(sdfSharePath(), filename);
if (sdf::filesystem::exists(path))
{
return path;
}

// Next check the versioned install path.
path = sdf::filesystem::append(SDF_SHARE_PATH,
"sdformat" SDF_MAJOR_VERSION_STR,
sdf::SDF::Version(), filename);
path = sdf::filesystem::append(sdfSharePath(),
"sdformat" + std::string(SDF_MAJOR_VERSION_STR),
sdf::SDF::Version(), filename);

if (sdf::filesystem::exists(path))
{
return path;
Expand Down
Loading

0 comments on commit a20cf95

Please sign in to comment.