-
Notifications
You must be signed in to change notification settings - Fork 4
/
fix_hardcoded_paths.sh
executable file
·111 lines (87 loc) · 4.09 KB
/
fix_hardcoded_paths.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
read -p "Where did you extract ROS2 to (e.g. $HOME/usr/ros2)? " installDir
echo
read -p "Where is your virtual Python environment (e.g. $HOME/usr/ros2PythonEnv)? " localPythonEnvPath
echo
#pythonVersion=3.11
#read -p "Can you locate the path to libpython$pythonVersion.dylib (e.g. /Library/Frameworks/Python.framework/Versions/$pythonVersion/lib/python$pythonVersion/config-$pythonVersion-darwin/libpython$pythonVersion.dylib if you install Python using the official installer at python.org)? " localLibPythonPath
#echo
read -p "Confirm each replacement? [y/n] " confirmBeforeAction
echo
# Helper function to confirm before doing a command
#
# Main usage: confirm PROMPT && COMMAND
#
# The effect is to ask the user with the given PROMPT message [should be y/n] to confirm the action
# and then execute COMMAND if the user answers 'y'.
confirm() {
if [ "$confirmBeforeAction" == "n" ]; then
return 0
fi
local proceed="n"
read -p "$1" proceed
case $proceed in
"y")
return 0;;
*)
return -1;;
esac
}
fixHardCodedPythonEnvPath() {
local hardcodedPythonEnvPath=/Users/runner/work/ROS2-On-iOS/ROS2-On-iOS/ros2PythonEnv
local hardcodedFiles=($(grep -r -l --include="*.cmake" "$hardcodedPythonEnvPath" .))
echo "Replacing $hardcodedPythonEnvPath -> $localPythonEnvPath"
# Python scripts
hardcodedFiles+=($(find $installDir/base/bin -type f))
hardcodedFiles+=($installDir/moveit2/bin/generate_parameter_library_py $installDir/moveit2/bin/rqt_joint_trajectory_controller $installDir/moveit2/lib/controller_manager/spawner $installDir/moveit2/lib/controller_manager/unspawner)
hardcodedFiles+=($(find $installDir/tutorials/bin -type f))
hardcodedFiles+=($installDir/tutorials/lib/joint_state_publisher_gui/joint_state_publisher_gui $installDir/tutorials/lib/xacro/xacro)
for f in "${hardcodedFiles[@]}"; do
confirm "In $f [y/n]? " && sed -i '' "s,$hardcodedPythonEnvPath,$localPythonEnvPath,g" $f
done
}
fixHardCodedLibPythonPath() {
local hardcodedLibPythonPath=/usr/local/opt/python@$pythonVersion/Frameworks/Python.framework/Versions/$pythonVersion/lib/python$pythonVersion/config-$pythonVersion-darwin/libpython$pythonVersion.dylib
local hardcodedFiles=($(grep -r -l --include="*.cmake" "$hardcodedLibPythonPath" .))
echo "Replacing $hardcodedLibPythonPath -> $localLibPythonPath"
for f in "${hardcodedFiles[@]}"; do
confirm "In $f [y/n]? " && sed -i '' "s,$hardcodedLibPythonPath,$localLibPythonPath,g" $f
done
}
fixHardCodedInstallDir() {
local hardcodedInstallDir=/Users/runner/work/ROS2-On-iOS/ROS2-On-iOS/ros2_macOS
local hardcodedFiles=($(grep -r -l --include="*.cmake" --include="*.pc" --include="*.zsh" --include="*.sh" --include="*.bash" "$hardcodedInstallDir" .))
echo "Replace hardcoded path $hardcodedInstallDir -> $installDir"
for f in "${hardcodedFiles[@]}"; do
confirm "In $f [y/n]? " && sed -i '' "s,$hardcodedInstallDir,$installDir,g" $f
done
}
fixXcodeSDKPath() {
local hardcodedMacOSSdkDir=/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk
local macOSSdkDir=$(xcodebuild -version -sdk macosx Path) # /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
local hardcodedFiles=($(grep -r -l --include="*.cmake" --include="*.pc" "$hardcodedMacOSSdkDir" .))
echo "Replace hardcoded path $hardcodedMacOSSdkDir -> $macOSSdkDir"
for f in "${hardcodedFiles[@]}"; do
confirm "In $f [y/n]? " && sed -i '' "s,$hardcodedMacOSSdkDir,$macOSSdkDir,g" $f
done
}
cd $installDir
echo ""
echo "Fix hardcoded Python environment path ..."
echo ""
fixHardCodedPythonEnvPath
#echo ""
#echo "Fix hardcoded path to libpython*.dylib ..."
#echo ""
#fixHardCodedLibPythonPath
echo ""
echo "Fix hardcoded ROS2 and dependencies installation location ..."
echo ""
fixHardCodedInstallDir
echo ""
echo "Fix hardcoded MacOS SDK path ..."
echo ""
fixXcodeSDKPath
echo ""
echo "REMINDERS"
echo "You sometimes need to fix the python3 path in $installDir/base/bin/ros2."
echo ""