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

Merge sdf14 ➡️ main #1470

Merged
merged 5 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ if (BUILD_SDF)
# Find tinyxml2.
gz_find_package(TINYXML2 REQUIRED)

#################################################
# Find DL if doing relocatable installation
if (GZ_ENABLE_RELOCATABLE_INSTALL)
gz_find_package(DL REQUIRED)
endif()


################################################
# Find urdfdom parser. Logic:
#
Expand Down
20 changes: 20 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

## libsdformat 14.X

### libsdformat 14.5.0 (2024-08-05)

1. Adding Errors structure to XmlUtils
* [Pull request #1296](https://github.com/gazebosim/sdformat/pull/1296)

1. Disable latex and class hierarchy generation
* [Pull request #1447](https://github.com/gazebosim/sdformat/pull/1447)

1. Added SetHeightMap and Heighmap to Geometry Python binding
* [Pull request #1440](https://github.com/gazebosim/sdformat/pull/1440)

1. workflows/ci.yml fix push branch regex
* [Pull request #1445](https://github.com/gazebosim/sdformat/pull/1445)

1. SDF.cc update calls to use sdf::Errors output
* [Pull request #1295](https://github.com/gazebosim/sdformat/pull/1295)

1. Added World::ActorByName
* [Pull request #1436](https://github.com/gazebosim/sdformat/pull/1436)

### libsdformat 14.4.0 (2024-06-20)

1. Add Cone as a primitive parametric shape.
Expand Down
40 changes: 40 additions & 0 deletions include/sdf/InstallationDirectories.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef SDF_INSTALLATION_DIRECTORIES_HH_
#define SDF_INSTALLATION_DIRECTORIES_HH_

#include <string>

#include <sdf/sdf_config.h>
#include <sdf/system_util.hh>

namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE {

/// \brief getInstallPrefix return the install prefix of the library
/// i.e. CMAKE_INSTALL_PREFIX unless the library has been moved
SDFORMAT_VISIBLE std::string getInstallPrefix();

/// \brief getSharePath return the share directory used by sdformat
SDFORMAT_VISIBLE std::string getSharePath();

}
}

#endif
4 changes: 2 additions & 2 deletions include/sdf/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
#cmakedefine SDFORMAT_DISABLE_CONSOLE_LOGFILE 1

#ifndef SDF_SHARE_PATH
#define SDF_SHARE_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/"
#define SDF_SHARE_PATH _Pragma ("GCC warning \"'SDF_SHARE_PATH' macro is deprecated, use sdf::getSharePath() function instead. \"") "${CMAKE_INSTALL_FULL_DATAROOTDIR}/"
#endif

#ifndef SDF_VERSION_PATH
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${PROJECT_VERSION_MAJOR}/${PROJECT_VERSION}"
#define SDF_VERSION_PATH _Pragma ("GCC warning \"'SDF_VERSION_PATH' macro is deprecated and should not be used. \"") "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${PROJECT_VERSION_MAJOR}/${PROJECT_VERSION}"
#endif

#endif // #ifndef SDF_CONFIG_HH_
20 changes: 20 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ gz_create_core_library(SOURCES ${sources}
CXX_STANDARD 17
LEGACY_PROJECT_PREFIX SDFormat
)
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION sdf::getInstallPrefix
GET_INSTALL_PREFIX_HEADER sdf/InstallationDirectories.hh
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE SDF_INSTALL_PREFIX)

# CMAKE_INSTALL_DATAROOTDIR may be an absolute path, let's make sure to use the
# relative version
if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
file(RELATIVE_PATH CMAKE_INSTALL_RELATIVE_DATAROOTDIR "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_DATAROOTDIR}")
else()
set(CMAKE_INSTALL_RELATIVE_DATAROOTDIR "${CMAKE_INSTALL_DATAROOTDIR}")
endif()

set_property(
SOURCE InstallationDirectories.cc
PROPERTY COMPILE_DEFINITIONS
CMAKE_INSTALL_RELATIVE_DATAROOTDIR="${CMAKE_INSTALL_RELATIVE_DATAROOTDIR}"
)


target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
Expand Down Expand Up @@ -99,6 +117,8 @@ if (BUILD_TESTING)
${PROJECT_SOURCE_DIR}/test
LIB_DEPS
library_for_tests
ENVIRONMENT
SDF_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

if (TARGET UNIT_gz_TEST)
Expand Down
130 changes: 130 additions & 0 deletions src/InstallationDirectories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (C) 2024 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <filesystem>
#include <regex>

#include <sdf/sdf_config.h>
#include <sdf/InstallationDirectories.hh>

namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE {

// We locally import the gz::common::joinPaths function
// See https://github.com/gazebosim/gz-physics/pull/507#discussion_r1186919267
// for more details

// Function imported from
// https://github.com/gazebosim/gz-common/blob/ignition-common4_4.6.2/src/FilesystemBoost.cc#L507
#ifndef WIN32
static const char preferred_separator = '/';
#else // Windows
static const char preferred_separator = '\\';
#endif
const std::string separator(const std::string &_p)
{
return _p + preferred_separator;
}

// Function imported from
// https://github.com/gazebosim/gz-common/blob/ignition-common4_4.6.2/src/Filesystem.cc#L227
std::string checkWindowsPath(const std::string _path)
{
if (_path.empty())
return _path;

// Check if this is a http or https, if so change backslashes generated by
// jointPaths to '/'
if ((_path.size() > 7 && 0 == _path.compare(0, 7, "http://")) ||
(_path.size() > 8 && 0 == _path.compare(0, 8, "https://")))
{
return std::regex_replace(_path, std::regex(R"(\\)"), "/");
}

// This is a Windows path, convert all '/' into backslashes
std::string result = std::regex_replace(_path, std::regex(R"(/)"), "\\");
std::string drive_letters;

// only Windows contains absolute paths starting with drive letters
if (result.length() > 3 && 0 == result.compare(1, 2, ":\\"))
{
drive_letters = result.substr(0, 3);
result = result.substr(3);
}
result = drive_letters + std::regex_replace(
result, std::regex("[<>:\"|?*]"), "");
return result;
}

// Function imported from
// https://github.com/gazebosim/gz-common/blob/gz-common5_5.6.0/src/Filesystem.cc#L142
std::string joinPaths(const std::string &_path1,
const std::string &_path2)
{
namespace fs = std::filesystem;
fs::path p1{_path1};
fs::path p2{_path2};

if (p1.empty())
{
p1 = std::string{fs::path::preferred_separator};
}

bool is_url = false;

if (_path1.find("://") == std::string::npos)
p1 = p1.lexically_normal();
else
is_url = true;

// TODO(mjcarroll) Address the case that path2 is also a URI.
// It's likely not a valid scenario, but not currently covered by our test
// suite and doesn't return an error.
if (_path2.find("://") == std::string::npos)
p2 = p2.lexically_normal();
else
is_url = true;

if (p2.string()[0] == fs::path::preferred_separator)
{
p2 = fs::path{p2.string().substr(1)};
}

auto ret = (p1 / p2);

if (is_url)
{
std::string path = ret.string();
std::replace(path.begin(), path.end(),
static_cast<char>(fs::path::preferred_separator), '/');
return path;
}
else
{
return ret.lexically_normal().string();
}
}

std::string getSharePath()
{
return sdf::joinPaths(
getInstallPrefix(), CMAKE_INSTALL_RELATIVE_DATAROOTDIR);
}

}
}
15 changes: 10 additions & 5 deletions src/SDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "sdf/Console.hh"
#include "sdf/Error.hh"
#include "sdf/Filesystem.hh"
#include "sdf/InstallationDirectories.hh"
#include "sdf/SDFImpl.hh"
#include "SDFImplPrivate.hh"
#include "sdf/sdf_config.h"
Expand All @@ -47,11 +48,15 @@ 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 "";
std::string sharePath = sdf::getSharePath();
if (sharePath != "/")
{
return sharePath;
}
else
{
return "";
}
}

/////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ endif()
gz_build_tests(TYPE ${TEST_TYPE}
SOURCES ${tests}
INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/test
ENVIRONMENT SDF_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)


Expand Down
5 changes: 4 additions & 1 deletion test/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ set(tests
parser_urdf.cc
)

gz_build_tests(TYPE ${TEST_TYPE} SOURCES ${tests} INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/test)
gz_build_tests(TYPE ${TEST_TYPE}
SOURCES ${tests}
INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/test
ENVIRONMENT SDF_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
Loading