forked from umrover/mrover-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis
executable file
·79 lines (66 loc) · 1.97 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
#!/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 "${JARVIS_VENV}"
# shellcheck source=/dev/null
source "${JARVIS_VENV}/bin/activate"
pip install --upgrade pip >/dev/null
pip install -r "${JARVIS_ROOT}/requirements.txt" >/dev/null
pip install "${JARVIS_ROOT}/jarvis_cmd" >/dev/null
}
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"
pip install -r "${JARVIS_ROOT}/requirements.txt" >/dev/null
pip install --upgrade "${JARVIS_ROOT}/jarvis_cmd" >/dev/null
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
# Convert project file path to executable name
remove_trail=${1%/}
arg_no_slash=${remove_trail//"/"/"_"}
clean_args=${@/$1/$arg_no_slash}
exec env LD_LIBRARY_PATH="${PRODUCT_ENV}/lib:${PRODUCT_ENV}/lib/x86_64-linux-gnu"\
$clean_args
else
echo "You must build something in order to be able to exec a command."
fi
exit 0
fi
run_jarvis "$@"