-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add optional binary relocatability #507
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
63dcd14
Add optional binary relocatability
traversaro 2355925
Address reviews
traversaro 39b1d44
Use char type in the lowercase version
j-rivero 1a82909
Merge branch 'gz-physics6' into relocbin2
mjcarroll 7f0fb36
Merge branch 'gz-physics6' into relocbin2
mjcarroll 37286bb
Merge branch 'gz-physics6' into relocbin2
mjcarroll a4d57c4
Merge branch 'gz-physics6' into relocbin2
mjcarroll b631687
Merge branch 'gz-physics6' into relocbin2
mjcarroll 2e1a99f
Fix windows compilation
traversaro 62f2a32
Fix Windows linking
traversaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2023 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 GZ_PHYSICS_INSTALLATION_DIRECTORIES_HH_ | ||
#define GZ_PHYSICS_INSTALLATION_DIRECTORIES_HH_ | ||
|
||
#include <string> | ||
|
||
#include <gz/physics/config.hh> | ||
#include <gz/physics/Export.hh> | ||
|
||
namespace gz | ||
{ | ||
namespace physics | ||
{ | ||
inline namespace GZ_PHYSICS_VERSION_NAMESPACE { | ||
|
||
/// \brief getInstallPrefix return the install prefix of the library | ||
/// i.e. CMAKE_INSTALL_PREFIX unless the library has been moved | ||
GZ_PHYSICS_VISIBLE std::string getInstallPrefix(); | ||
|
||
/// \brief getEngineInstallDir return the install directory of the engines | ||
GZ_PHYSICS_VISIBLE std::string getEngineInstallDir(); | ||
|
||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (C) 2023 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 <regex> | ||
|
||
#include <gz/physics/config.hh> | ||
#include <gz/physics/InstallationDirectories.hh> | ||
|
||
namespace gz | ||
{ | ||
namespace physics | ||
{ | ||
inline namespace GZ_PHYSICS_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/ignition-common4_4.6.2/src/Filesystem.cc#L256 | ||
std::string joinPaths(const std::string &_path1, | ||
const std::string &_path2) | ||
{ | ||
|
||
/// This function is used to avoid duplicated path separators at the | ||
/// beginning/end of the string, and between the two paths being joined. | ||
/// \param[in] _path This is the string to sanitize. | ||
/// \param[in] _stripLeading True if the leading separator should be | ||
/// removed. | ||
auto sanitizeSlashes = [](const std::string &_path, | ||
bool _stripLeading = false) | ||
{ | ||
// Shortcut | ||
if (_path.empty()) | ||
return _path; | ||
|
||
std::string result = _path; | ||
|
||
// Use the appropriate character for each platform. | ||
#ifndef _WIN32 | ||
char replacement = '/'; | ||
#else | ||
char replacement = '\\'; | ||
#endif | ||
|
||
// Sanitize the start of the path. | ||
size_t index = 0; | ||
size_t leadingIndex = _stripLeading ? 0 : 1; | ||
for (; index < result.length() && result[index] == replacement; ++index) | ||
{ | ||
} | ||
if (index > leadingIndex) | ||
result.erase(leadingIndex, index-leadingIndex); | ||
|
||
// Sanitize the end of the path. | ||
index = result.length()-1; | ||
for (; index < result.length() && result[index] == replacement; --index) | ||
{ | ||
} | ||
index += 1; | ||
if (index < result.length()-1) | ||
result.erase(index+1); | ||
return result; | ||
}; | ||
|
||
std::string path; | ||
#ifndef _WIN32 | ||
path = sanitizeSlashes(sanitizeSlashes(separator(_path1)) + | ||
sanitizeSlashes(_path2, true)); | ||
#else // _WIN32 | ||
std::string path1 = sanitizeSlashes(checkWindowsPath(_path1)); | ||
std::string path2 = sanitizeSlashes(checkWindowsPath(_path2), true); | ||
std::vector<char> combined(path1.length() + path2.length() + 2); | ||
if (::PathCombineA(combined.data(), path1.c_str(), path2.c_str()) != NULL) | ||
{ | ||
path = sanitizeSlashes(checkWindowsPath(std::string(combined.data()))); | ||
} | ||
else | ||
{ | ||
path = sanitizeSlashes(checkWindowsPath(separator(path1) + path2)); | ||
} | ||
#endif // _WIN32 | ||
return path; | ||
} | ||
|
||
|
||
std::string getEngineInstallDir() | ||
{ | ||
return gz::physics::joinPaths( | ||
getInstallPrefix(), GZ_PHYSICS_ENGINE_RELATIVE_INSTALL_DIR); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in https://build.osrfoundation.org/job/ign_physics-pr-win/2336/console
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we need to include
Shlwapi.h
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just getting back to these, I believe that is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this is what I did in conda-forge: conda-forge/gz-physics-feedstock@d548779 . Probably I forgot to report it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 2e1a99f .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something may need to be linked as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously yes, see last commit of https://github.com/conda-forge/gz-physics-feedstock/pull/11/commits , my bad. -_-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully fixed by 62f2a32 .