-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdevelop.sh
executable file
·277 lines (248 loc) · 6.32 KB
/
develop.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/sh
USER_SHELLS="bash zsh"
PACKAGES_DIR="packages"
PACKAGE_XML_FILE="package.xml"
CONTRIBUTING_FILE="docs/CONTRIBUTING.rst"
USAGE_STRING="Usage: sh develop.sh <mode> [arguments...]\n"
# If the EZRASSOR_WORKSPACE_DIR is set, use this as the WORKSPACE_DIR, else
# use a default.
if [ ! -z "$EZRASSOR_WORKSPACE_DIR" ]; then
WORKSPACE_DIR="$EZRASSOR_WORKSPACE_DIR"
else
WORKSPACE_DIR="$HOME/ezrassor_ws"
fi
WORKSPACE_SOURCE_DIR="$WORKSPACE_DIR/src"
WORKSPACE_DEVEL_DIR="$WORKSPACE_DIR/devel"
# Source setup files within a given directory in the user's RC files.
source_setups_in_directory() {
must_restart=false
partial_source_file="$1/setup"
for user_shell in $USER_SHELLS; do
shellrc_file="$HOME/.${user_shell}rc"
if [ -f "$shellrc_file" ]; then
source_file="$partial_source_file.$user_shell"
source_line=". \"$source_file\""
printf "Attempting to source setup script for %s: " "$user_shell"
if cat "$shellrc_file" | grep -Fq "$source_line"; then
printf "Previously sourced.\n"
else
printf "%s\n" \
"" \
"# Source the ROS setup file for the EZRASSOR, if it exists." \
"if [ -f \"$source_file\" ]; then" \
" $source_line" \
"fi" >> "$shellrc_file"
printf "Successfully sourced.\n"
must_restart=true
fi
fi
done
if [ "$must_restart" = "true" ]; then
printf "\n\n******** %s ********\n" \
"Restart your terminal for changes to take effect."
fi
}
# Set up the development environment.
setup_environment() {
# Setup will run fresh every time.
rm -r -f "$WORKSPACE_DIR"
mkdir -p "$WORKSPACE_SOURCE_DIR"
cd "$WORKSPACE_SOURCE_DIR"
catkin_init_workspace
cd - > /dev/null 2>&1
source_setups_in_directory "$WORKSPACE_DEVEL_DIR"
mkdir -p ~/.gazebo/models
cp -r extra_worlds/* ~/.gazebo/models/
cp -r extra_models/* ~/.gazebo/models/
}
# Create a new ROS package in source control.
new_package() {
superpackage="$1"
mkdir -p "$PACKAGES_DIR/$superpackage"
cd "$PACKAGES_DIR/$superpackage"
# Create a new catkin package with all the arguments
# passed to this function (after the first argument).
shift
catkin_create_pkg "$@"
cd - > /dev/null 2>&1
}
# Link packages into your workspace.
link_packages() {
link_only_in_list=false
link_except_in_list=false
if [ $# -ne 0 ]; then
case "$1" in
"-o"|"--only")
link_only_in_list=true
shift
;;
"-e"|"--except")
link_except_in_list=true
shift
;;
*)
echo "$USAGE_STRING"
exit 1
;;
esac
fi
for collection_dir in "$PWD/$PACKAGES_DIR"; do
for superpackage_dir in "$collection_dir"/*; do
for package_dir in "$superpackage_dir"/*; do
if [ ! -d "$package_dir" ]; then
:
elif [ "$link_only_in_list" = "true" ]; then
if argument_in_list "$(basename "$package_dir")" "$@"; then
link_package "$package_dir"
fi
elif [ "$link_except_in_list" = "true" ]; then
if ! argument_in_list "$(basename "$package_dir")" "$@"; then
link_package "$package_dir"
fi
else
link_package "$package_dir"
fi
done
done
done
}
# Helper function that links a single package.
link_package() {
package_path="$1"
package_name="$(basename "$package_path")"
if [ -L "$WORKSPACE_SOURCE_DIR/$package_name" ]; then
rm -f "$WORKSPACE_SOURCE_DIR/$package_name"
printf "Relinking %s...\n" "$package_path"
else
printf "Linking %s...\n" "$package_path"
fi
ln -s "$package_path" "$WORKSPACE_SOURCE_DIR/$package_name"
}
# Check if the first argument exists in the remaining list of arguments.
argument_in_list() {
argument="$1"
shift
for item in "$@"; do
case "$argument" in
$item)
return 0
;;
esac
done
return 1
}
# Purge packages in the ROS workspace.
purge_packages() {
cd "$WORKSPACE_SOURCE_DIR"
printf "Purging all packages in /src...\n"
find . ! -name "CMakeLists.txt" -type l -exec rm -f {} +
cd - > /dev/null 2>&1
}
# Install dependencies for all linked packages.
resolve_packages() {
rosdep install --from-paths "$WORKSPACE_SOURCE_DIR" --ignore-src -y
}
# Build all packages.
build_packages() {
cd "$WORKSPACE_DIR"
catkin_make
cd - > /dev/null 2>&1
}
# Install all packages that have been built.
install_packages() {
cd "$WORKSPACE_DIR"
catkin_make install
cd - > /dev/null 2>&1
}
# Kill all running ROS nodes.
kill_ros() {
rosnode kill --all
killall -SIGTERM roscore
printf "\nROS has been shut down.\n"
}
# Test all packages in the workspace.
test_packages() {
cd "$WORKSPACE_DIR"
# This command will run the tests but return a status of 0.
catkin_make run_tests
# This command will return a status code of 0 or 1 depending on if the
# previous tests succeeded.
(catkin_test_results)
local result=$?
# After we return to the main directory, return the status code from the test
# results.
cd - > /dev/null 2>&1
[ $result -eq 0 ]
}
# Change the version number of all the packages.
reversion_packages() {
sed_command="s|<version>.*</version>|<version>$1</version>|g"
for superpackage_dir in "$PWD/$PACKAGES_DIR"/*; do
for package_dir in "$superpackage_dir"/*; do
for item in "$package_dir"/*; do
if [ "$(basename "$item")" = "$PACKAGE_XML_FILE" ]; then
sed -i "$sed_command" "$item"
fi
done
done
done
}
# Show a help menu. This menu is parsed from pre-existing documentation.
throw_help() {
printf "$USAGE_STRING"
cat "$CONTRIBUTING_FILE" \
| grep '^``' -A 1 \
| sed 's/ //g' \
| sed 's/^``/#/g' \
| fold -s -w 75 \
| sed '/^#/! s/^/ /g' \
| sed '/``/ s/``/"/g' \
| sed '/^#/ s/"//g' \
| tr '#' '\n'
}
# Main entry point of the script.
case "$1" in
"setup")
setup_environment
;;
"new")
shift
new_package "$@"
;;
"link")
shift
link_packages "$@"
;;
"purge")
purge_packages
;;
"relink")
shift
purge_packages
link_packages "$@"
;;
"resolve")
resolve_packages
;;
"build")
build_packages
;;
"install")
install_packages
;;
"kill")
kill_ros
;;
"test")
test_packages
;;
"reversion")
reversion_packages "$2"
;;
"help")
throw_help
;;
*)
printf "$USAGE_STRING"
;;
esac