Skip to content

Commit

Permalink
Add script and instruction to fix up hardcoded paths in release archive
Browse files Browse the repository at this point in the history
  • Loading branch information
light-tech committed Oct 2, 2022
1 parent d8adabc commit b8a0688
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions MACOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ source PATH_TO_EXTRACTED_ROS2/setup.zsh
```
and then you can use ROS2 [as usual](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries.html).

### Fixing up paths

Unfortunately, `colcon` hardcoded a lot of paths (mostly concerning Python-based stuffs) in generated CMake files so you need to fix it to match YOUR system.
To do that, `cd` to `share` folder inside the extracted `ros2/` and run our script
```shell
fix_hardcoded_paths.sh PATH_TO_YOUR_PYTHON_ENV PATH_TO_LIBPYTHON_DYLIB
```
where

* `PATH_TO_YOUR_PYTHON_ENV` should be where you create the Python environment on your local machine such as `$HOME/usr/ros2PythonEnv`; and
* `PATH_TO_LIBPYTHON_DYLIB` should be the path to `libpython3.10.dylib` on your local machine, it should be `/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin/libpython3.10.dylib` if you installed Python from [its official site](https://www.python.org). There is probably no need to fix this if you installed Python using Homebrew.

The other place to fix the path is the executable script `bin/ros2` (fix it so you can run `ros2` command line such as `ros2 launch` and `ros2 topic list`).

### Note about building and using overlaid workspace

1. You might want to add `-DCMAKE_PREFIX_PATH` such as
Expand Down
47 changes: 47 additions & 0 deletions fix_hardcoded_paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
localPythonEnvPath=$1 # e.g. $HOME/usr/ros2PythonEnv
localLibPythonPath=$2 # e.g. /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin/libpython3.10.dylib

fixHardCodedPythonEnvPath() {
hardcodedPythonEnvPath=/Users/runner/work/ROS2-On-iOS/ROS2-On-iOS/ros2PythonEnv

echo "Replacing $hardcodedPythonEnvPath with $localPythonEnvPath"

# List down files which hard-coded the python environment paths on GitHub Action
hardcodedFiles=$(grep -r -l "$hardcodedPythonEnvPath" .)

# Replace the hardcoded path in those files
for f in $hardcodedFiles; do
echo "In file $f"
sed -i.bak "s,$hardcodedPythonEnvPath,$localPythonEnvPath,g" $f
done
}

fixHardCodedLibPythonPath() {
local hardcodedLibPythonPath=/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/python3.10/config-3.10-darwin/libpython3.10.dylib

local hardcodedFiles=$(grep -r -l "$hardcodedLibPythonPath" .)

echo $hardcodedFiles

# Replace the hardcoded path in those files
for f in $hardcodedFiles; do
echo "In file $f"
sed -i.bak "s,$hardcodedLibPythonPath,$localLibPythonPath,g" $f
done
}

echo ""
echo "Fix hardcoded Python environment path ..."
echo ""
fixHardCodedPythonEnvPath

echo ""
echo "Fix hardcoded path to libpython*.dylib ..."
echo ""
fixHardCodedLibPythonPath

# Delete the backup files generated
echo ""
echo "Delete backup files generated (make sure they are safe to delete, skip if not sure) ..."
echo ""
find . -name \*.bak -ok rm {} \;

0 comments on commit b8a0688

Please sign in to comment.