Skip to content

Commit

Permalink
Update bazel files
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 16, 2023
1 parent 41b7cf1 commit 8702bcd
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 32 deletions.
151 changes: 151 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load("@gz//bazel/skylark:gz_py.bzl", "gz_py_binary")

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"]) # Apache-2.0

exports_files(["LICENSE"])

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

gz_py_binary(
name = "embed_sdf",
srcs = ["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/ --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,
includes = [
"include",
"src",
],
defines = [
'SDF_SHARE_PATH=\\".\\"',
'SDF_VERSION_PATH=\\"sdformat\\"',
],
deps = [
":urdf",
GZ_ROOT + "math",
GZ_ROOT + "utils",
"@tinyxml2",
],
)

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]

exports_files(["sdf"])
5 changes: 1 addition & 4 deletions include/sdf/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@

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

static constexpr const char * kSdfSharePath = SDF_SHARE_PATH;
static constexpr const char * kSdfVersionPath = SDF_VERSION_PATH;
#endif

#endif // #ifndef SDF_CONFIG_HH_
54 changes: 26 additions & 28 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
Expand Down Expand Up @@ -43,18 +44,6 @@ 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;
else
return "";
#endif
return "";
}


/////////////////////////////////////////////////
void setFindCallback(std::function<std::string(const std::string &)> _cb)
{
Expand Down Expand Up @@ -109,27 +98,36 @@ std::string findFile(const std::string &_filename, bool _searchLocalPath,
filename = filename.substr(idx + sep.length());
}

if (sdfSharePath() != "")
if (filename[0] == '/' && sdf::filesystem::exists(filename))
{
// Next check the install path.
std::string path = sdf::filesystem::append(sdfSharePath(), filename);
if (sdf::filesystem::exists(path))
{
return path;
}
return filename;
}

// Next check the versioned install path.
path = sdf::filesystem::append(sdfSharePath(),
"sdformat" SDF_MAJOR_VERSION_STR,
sdf::SDF::Version(), filename);
if (sdf::filesystem::exists(path))
{
return path;
}

// Next check the install path.
std::string path = sdf::filesystem::append(SDF_SHARE_PATH, filename);

std::cout << SDF_SHARE_PATH << std::endl;
std::cout << "Checking: " << path << std::endl;

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);
std::cout << "Checking: " << path << std::endl;
if (sdf::filesystem::exists(path))
{
return path;
}

// Next check to see if the given file exists.
std::string path = filename;
path = filename;
if (sdf::filesystem::exists(path))
{
return path;
Expand Down
57 changes: 57 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_ROOT",
"cmake_configure_file",
)

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_utils.hh", "test_config.hh"],
includes = ["."],
visibility = ["//visibility:public"],
)

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",
])

0 comments on commit 8702bcd

Please sign in to comment.