Skip to content

Commit a20cf95

Browse files
mjcarrollBi0T1Nazeey
authored
Bazel updates for Garden build (#1239)
* 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]>
1 parent 24b6153 commit a20cf95

23 files changed

+607
-180
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ build
33
build_*
44
*.*.sw?
55
.vscode
6+
7+
__pycache__

BUILD.bazel

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
load(
2+
"@gz//bazel/skylark:build_defs.bzl",
3+
"GZ_FEATURES",
4+
"GZ_ROOT",
5+
"GZ_VISIBILITY",
6+
"add_lint_tests",
7+
"gz_configure_file",
8+
"gz_configure_header",
9+
"gz_export_header",
10+
"gz_include_header",
11+
"gz_py_binary",
12+
)
13+
14+
package(
15+
default_visibility = GZ_VISIBILITY,
16+
features = GZ_FEATURES,
17+
)
18+
19+
licenses(["notice"])
20+
21+
exports_files(["LICENSE"])
22+
23+
gz_configure_header(
24+
name = "config",
25+
src = "include/sdf/config.hh.in",
26+
cmakelists = ["CMakeLists.txt"],
27+
defines = {
28+
"CMAKE_INSTALL_FULL_DATAROOTDIR": "unused",
29+
},
30+
package = "sdformat",
31+
)
32+
33+
gz_py_binary(
34+
name = "embed_sdf",
35+
srcs = ["sdf/embedSdf.py"],
36+
main = "sdf/embedSdf.py",
37+
)
38+
39+
genrule(
40+
name = "embed_sdf_genrule",
41+
srcs = glob([
42+
"sdf/**/*.sdf",
43+
"sdf/**/*.convert",
44+
]),
45+
outs = ["EmbeddedSdf.cc"],
46+
cmd = "$(execpath :embed_sdf) --output-file $@ --sdf-root sdformat/sdf/ --input-files $(SRCS)", # noqa
47+
tools = [":embed_sdf"],
48+
)
49+
50+
public_headers_no_gen = glob([
51+
"include/sdf/*.h",
52+
"include/sdf/*.hh",
53+
])
54+
55+
private_headers = glob(["src/*.hh"])
56+
57+
sources = glob(
58+
["src/*.cc"],
59+
exclude = [
60+
"src/*_TEST.cc",
61+
"src/gz.cc",
62+
],
63+
)
64+
65+
gz_export_header(
66+
name = "include/sdf/Export.hh",
67+
export_base = "GZ_SDFORMAT",
68+
lib_name = "sdf",
69+
visibility = ["//visibility:private"],
70+
)
71+
72+
gz_include_header(
73+
name = "sdformat_hh_genrule",
74+
out = "include/sdformat.hh",
75+
hdrs = public_headers_no_gen + [
76+
"include/sdf/config.hh",
77+
"include/sdf/Export.hh",
78+
],
79+
)
80+
81+
public_headers = public_headers_no_gen + [
82+
"include/sdf/Export.hh",
83+
"include/sdf/config.hh",
84+
"include/sdformat.hh",
85+
]
86+
87+
cc_library(
88+
name = "urdf",
89+
srcs = [
90+
"src/urdf/urdf_parser/joint.cpp",
91+
"src/urdf/urdf_parser/link.cpp",
92+
"src/urdf/urdf_parser/model.cpp",
93+
"src/urdf/urdf_parser/pose.cpp",
94+
"src/urdf/urdf_parser/twist.cpp",
95+
"src/urdf/urdf_parser/urdf_model_state.cpp",
96+
"src/urdf/urdf_parser/urdf_sensor.cpp",
97+
"src/urdf/urdf_parser/world.cpp",
98+
],
99+
hdrs = glob(
100+
["src/urdf/**/*.h"],
101+
),
102+
copts = ["-Wno-unknown-pragmas"],
103+
includes = ["src/urdf"],
104+
deps = [
105+
"@tinyxml2",
106+
],
107+
)
108+
109+
cc_library(
110+
name = "sdformat",
111+
srcs = sources + private_headers + ["EmbeddedSdf.cc"],
112+
hdrs = public_headers,
113+
defines = [
114+
'SDF_SHARE_PATH=\\".\\"',
115+
'SDF_VERSION_PATH=\\"sdformat\\"',
116+
],
117+
includes = [
118+
"include",
119+
"src",
120+
],
121+
deps = [
122+
":urdf",
123+
GZ_ROOT + "math",
124+
GZ_ROOT + "utils",
125+
"@tinyxml2",
126+
],
127+
)
128+
129+
cc_library(
130+
name = "sdformat_internal",
131+
srcs = [
132+
"src/gz.cc",
133+
"src/gz.hh",
134+
],
135+
visibility = ["//visibility:private"],
136+
deps = [":sdformat"],
137+
)
138+
139+
test_sources = glob(
140+
["src/*_TEST.cc"],
141+
exclude = ["src/gz_TEST.cc"],
142+
)
143+
144+
[cc_test(
145+
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
146+
srcs = [src],
147+
data = [
148+
"sdf",
149+
GZ_ROOT + "sdformat/test:integration",
150+
GZ_ROOT + "sdformat/test:sdf",
151+
],
152+
env = {
153+
"GZ_BAZEL": "1",
154+
"GZ_BAZEL_PATH": "sdformat",
155+
},
156+
deps = [
157+
":sdformat",
158+
GZ_ROOT + "sdformat/test:test_utils",
159+
"@gtest",
160+
"@gtest//:gtest_main",
161+
],
162+
) for src in test_sources]
163+
164+
gz_configure_file(
165+
name = "sdformat.rb",
166+
src = "src/cmd/cmdsdformat.rb.in",
167+
out = "cmdsdformat.rb",
168+
cmakelists = ["CMakeLists.txt"],
169+
defines = [
170+
"library_location=libgz-sdformat.so",
171+
],
172+
package = "sdformat",
173+
visibility = [GZ_ROOT + "tools:__pkg__"],
174+
)
175+
176+
gz_configure_file(
177+
name = "sdformat_yaml",
178+
src = "conf/sdformat.yaml.in",
179+
out = "sdformat.yaml",
180+
cmakelists = ["CMakeLists.txt"],
181+
defines = [
182+
"gz_library_path=gz/sdformat/cmdsdformat.rb",
183+
],
184+
package = "sdformat",
185+
visibility = [GZ_ROOT + "tools:__pkg__"],
186+
)
187+
188+
cc_binary(
189+
name = "libgz-sdformat.so",
190+
srcs = [":sdformat_internal"],
191+
linkshared = True,
192+
visibility = [GZ_ROOT + "tools:__pkg__"],
193+
deps = [
194+
":sdformat",
195+
],
196+
)
197+
198+
exports_files(["sdf"])
199+
200+
add_lint_tests()

include/sdf/Param.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ namespace sdf
8585
: val(_val), precision(_precision) {}
8686
};
8787

88+
// Template deduction guide for ParamVariant
89+
template<typename ParamVariant>
90+
ParamStreamer(const ParamVariant &_val, int _precision)
91+
-> ParamStreamer<ParamVariant>;
92+
8893
template<class T>
8994
std::ostream& operator<<(std::ostream &os, ParamStreamer<T> s)
9095
{

include/sdf/config.hh.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@
4747

4848
#cmakedefine SDFORMAT_DISABLE_CONSOLE_LOGFILE 1
4949

50+
#ifndef SDF_SHARE_PATH
5051
#define SDF_SHARE_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/"
51-
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${SDF_MAJOR_VERSION}/${SDF_PKG_VERSION}"
52+
#endif
53+
54+
#ifndef SDF_VERSION_PATH
55+
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${PROJECT_VERSION_MAJOR}/${PROJECT_VERSION}"
56+
#endif
5257

5358
#endif // #ifndef SDF_CONFIG_HH_

sdf/embedSdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ def generate_map_content(paths: List[Path], relative_to: Optional[str] = None) -
160160
for path in paths:
161161
with open(path, "r", encoding="utf8") as input_sdf:
162162
file_content = input_sdf.read()
163-
164163
# Strip relative path if requested
165164
if relative_to is not None:
166-
path = path.relative_to(relative_to)
165+
_, relative_path = str(path).split(relative_to)
166+
path = relative_path
167167
content.append(embed_sdf_content(str(path), file_content))
168168
return ",".join(content)
169169

src/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ if (BUILD_TESTING)
6161
XmlUtils.cc)
6262
endif()
6363

64-
if(TARGET UNIT_gz_TEST)
65-
target_compile_definitions(UNIT_gz_TEST PUBLIC "-DDETAIL_GZ_CONFIG_PATH=\"${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>\"")
64+
if (TARGET UNIT_gz_TEST)
65+
target_compile_definitions(UNIT_gz_TEST PRIVATE
66+
-DGZ_PATH="${GZ_PROGRAM}"
67+
-DDETAIL_GZ_CONFIG_PATH="${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>"
68+
-DGZ_TEST_LIBRARY_PATH="${PROJECT_BINARY_DIR}/src")
6669
endif()
6770

6871
if (TARGET UNIT_FrameSemantics_TEST)

src/Capsule_TEST.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ TEST(DOMCapsule, Load)
154154
// Add a radius element
155155
sdf::ElementPtr radiusDesc(new sdf::Element());
156156
radiusDesc->SetName("radius");
157-
radiusDesc->AddValue("double", "1.0", "1", "radius");
157+
radiusDesc->AddValue("double", "1.0", true, "radius");
158158
sdf->AddElementDescription(radiusDesc);
159159
sdf::ElementPtr radiusElem = sdf->AddElement("radius");
160160
radiusElem->Set<double>(2.0);

src/Cylinder_TEST.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ TEST(DOMCylinder, Load)
150150
// Add a radius element
151151
sdf::ElementPtr radiusDesc(new sdf::Element());
152152
radiusDesc->SetName("radius");
153-
radiusDesc->AddValue("double", "1.0", "1", "radius");
153+
radiusDesc->AddValue("double", "1.0", true, "radius");
154154
sdf->AddElementDescription(radiusDesc);
155155
sdf::ElementPtr radiusElem = sdf->AddElement("radius");
156156
radiusElem->Set<double>(2.0);

src/Plane_TEST.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ TEST(DOMPlane, Load)
145145
// Add a normal element
146146
sdf::ElementPtr normalDesc(new sdf::Element());
147147
normalDesc->SetName("normal");
148-
normalDesc->AddValue("vector3", "0 0 1", "1", "normal");
148+
normalDesc->AddValue("vector3", "0 0 1", true, "normal");
149149
sdf->AddElementDescription(normalDesc);
150150
sdf::ElementPtr normalElem = sdf->AddElement("normal");
151151
normalElem->Set<gz::math::Vector3d>({1, 0, 0});

src/SDF.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ inline namespace SDF_VERSION_NAMESPACE
4343
// returns the version string when possible.
4444
std::string SDF::version = SDF_VERSION; // NOLINT(runtime/string)
4545

46+
std::string sdfSharePath()
47+
{
48+
#ifdef SDF_SHARE_PATH
49+
if (std::string(SDF_SHARE_PATH) != "/")
50+
return SDF_SHARE_PATH;
51+
#endif
52+
return "";
53+
}
54+
4655
/////////////////////////////////////////////////
4756
void setFindCallback(std::function<std::string(const std::string &)> _cb)
4857
{
@@ -109,16 +118,17 @@ std::string findFile(const std::string &_filename, bool _searchLocalPath,
109118
}
110119

111120
// Next check the install path.
112-
std::string path = sdf::filesystem::append(SDF_SHARE_PATH, filename);
121+
std::string path = sdf::filesystem::append(sdfSharePath(), filename);
113122
if (sdf::filesystem::exists(path))
114123
{
115124
return path;
116125
}
117126

118127
// Next check the versioned install path.
119-
path = sdf::filesystem::append(SDF_SHARE_PATH,
120-
"sdformat" SDF_MAJOR_VERSION_STR,
121-
sdf::SDF::Version(), filename);
128+
path = sdf::filesystem::append(sdfSharePath(),
129+
"sdformat" + std::string(SDF_MAJOR_VERSION_STR),
130+
sdf::SDF::Version(), filename);
131+
122132
if (sdf::filesystem::exists(path))
123133
{
124134
return path;

0 commit comments

Comments
 (0)