forked from umrover/mrover-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis
executable file
·89 lines (75 loc) · 2.3 KB
/
jarvis
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
#!/bin/bash
set -eo pipefail
FILEPATH=$(realpath "${0}")
DIR=$(dirname "${FILEPATH}")
MROVER_BUILD_ROOT="${HOME}/.mrover"
JARVIS_ROOT=${DIR}/jarvis_files
JARVIS_VENV=${MROVER_BUILD_ROOT}/jarvis_env
PRODUCT_ENV=${MROVER_BUILD_ROOT}/build_env
run_jarvis() {
# Runs a Jarvis command using PyInvoke
# shellcheck source=/dev/null
source "${JARVIS_VENV}/bin/activate"
jarvis "--root=${DIR}" "$@"
return $?
}
make_jarvis_env() {
# Make virtualenv for Jarvis
python3 -m venv --copies --clear --prompt "jarvis boot venv" "${JARVIS_VENV}"
source "${JARVIS_VENV}/bin/activate"
pip3 install --upgrade pip
pip3 install --quiet -r "${JARVIS_ROOT}/requirements.txt"
pip3 install --quiet "${JARVIS_ROOT}/jarvis_cmd"
}
if [ ! -d "${MROVER_BUILD_ROOT}" ]; then
echo -n "Bootstrapping..."
# Make MRover Build Root
mkdir -p "${MROVER_BUILD_ROOT}"
make_jarvis_env
echo "Done!"
fi
if [ "$#" -lt 1 ]; then
run_jarvis --help
exit 0
fi
if [ "$1" = "implode" ]; then
# Delete mrover build space
rm -rf "${MROVER_BUILD_ROOT}"
exit 0
fi
if [ "$1" = "upgrade" ]; then
# Delete Jarvis env and rebuild it
# shellcheck source=/dev/null
source "${JARVIS_VENV}/bin/activate"
pip3 install -r "${JARVIS_ROOT}/requirements.txt"
pip3 install --upgrade "${JARVIS_ROOT}/jarvis_cmd"
exit 0
fi
if [ "$1" = "exec" ]; then
if [ -d "${PRODUCT_ENV}" ]; then
# shellcheck source=/dev/null
source "${PRODUCT_ENV}/bin/activate"
export MROVER_CONFIG="${PRODUCT_ENV}/config"
shift
gdb=false
if [[ $@ == *"-gdb"* ]]; then
gdb=true
fi
# Convert project file path to executable name
remove_trail=${1%/}
arg_no_slash=${remove_trail/"/"/"_"} # substitute / for _
clean_args=${@/$1/$arg_no_slash}
clean_args=${clean_args/"-gdb"/""} # remove -gdb if necessary
if [ $gdb = true ]; then
export LD_LIBRARY_PATH="${PRODUCT_ENV}/lib:${PRODUCT_ENV}/lib/x86_64-linux-gnu"
gdb $clean_args
else
exec env LD_LIBRARY_PATH="${PRODUCT_ENV}/lib:${PRODUCT_ENV}/lib/x86_64-linux-gnu"\
$clean_args
fi
else
echo "You must build something in order to be able to exec a command."
fi
exit 0
fi
run_jarvis "$@"