Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel updates for Garden build #1239

Merged
merged 31 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
07e9161
Cherry-pick the python3 embedSdf script and tests (#884)
Bi0T1N Feb 7, 2023
09d69f4
Improvements to embedSdf script
mjcarroll Feb 16, 2023
a82e65f
Update sdf/CMakeLists.txt
mjcarroll Feb 16, 2023
7553e0f
Update bazel files
mjcarroll Feb 15, 2023
607918f
Lint
mjcarroll Feb 16, 2023
f2b5eea
Merge branch 'sdf13' into mjcarroll/garden_bazel
mjcarroll Feb 17, 2023
9ceef66
Merge branch 'sdf13' into mjcarroll/garden_bazel
mjcarroll Jun 12, 2023
7b54dd3
Add utils back to parser
mjcarroll Jun 12, 2023
f43b38c
Merge branch 'sdf13' into mjcarroll/garden_bazel
mjcarroll Aug 9, 2023
0deefe3
Fix gz_TEST
mjcarroll Aug 9, 2023
51a49de
Ignore pycache folders
mjcarroll Aug 9, 2023
c5b5828
Fix parser_TEST
mjcarroll Aug 9, 2023
0f6044a
Bazel nits
mjcarroll Aug 10, 2023
c9a1b85
Fix path logic
mjcarroll Aug 10, 2023
cc8a96a
Fix visibility
mjcarroll Aug 10, 2023
119cabd
Fix strings
mjcarroll Aug 10, 2023
5c854ea
Use standard vars
mjcarroll Aug 10, 2023
a774176
Fix string conversions
mjcarroll Aug 10, 2023
17d12ec
Fix string conversions
mjcarroll Aug 10, 2023
1212060
Fix embedded sdf
mjcarroll Aug 10, 2023
b5148eb
Merge remote-tracking branch 'origin/mjcarroll/garden_bazel' into mjc…
mjcarroll Aug 10, 2023
d0062f5
Fix converter test
mjcarroll Aug 10, 2023
266520e
Merge branch 'sdf13' into mjcarroll/garden_bazel
mjcarroll Aug 24, 2023
f7a1fa3
Merge branch 'sdf13' into mjcarroll/garden_bazel
mjcarroll Sep 7, 2023
27c540c
Lint
mjcarroll Sep 7, 2023
3d4e590
Update bazel files
mjcarroll Dec 7, 2023
d143957
Merge branch 'sdf13' into mjcarroll/garden_bazel
mjcarroll Dec 7, 2023
53732ed
Add detail prefix
mjcarroll Dec 7, 2023
874d4a4
Fix test path
mjcarroll Dec 7, 2023
5c4e4e6
Set homepath on Windows
mjcarroll Dec 11, 2023
f998de1
Merge remote-tracking branch 'origin/mjcarroll/garden_bazel' into mjc…
mjcarroll Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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