diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..31c9166c1 --- /dev/null +++ b/BUILD.bazel @@ -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"]) diff --git a/include/sdf/config.hh.in b/include/sdf/config.hh.in index e39759336..7b128ebad 100644 --- a/include/sdf/config.hh.in +++ b/include/sdf/config.hh.in @@ -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_ diff --git a/src/SDF.cc b/src/SDF.cc index be4852ae8..1166c8855 100644 --- a/src/SDF.cc +++ b/src/SDF.cc @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -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 _cb) { @@ -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; diff --git a/test/BUILD.bazel b/test/BUILD.bazel new file mode 100644 index 000000000..2743e75f0 --- /dev/null +++ b/test/BUILD.bazel @@ -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", +])