forked from RIFTIO/RIFT.ware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rift-shell
executable file
·169 lines (141 loc) · 4.95 KB
/
rift-shell
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
#!/bin/bash
#
# (c) Copyright RIFT.io, 2013-2016, All Rights Reserved
#
set -e
__usage(){
cat <<USAGEDOC
NAME
rift-shell - Creates a complete environment for running RIFT software
SYNOPSIS
rift-shell [-c|--config <file>] [-e|--use-existing] [-h|--help] [--] <command>
DESCRIPTION
The rift-shell creates all of the environmental variables necessary to run
and develop RIFT software. Currently the environmental variables are
inferred from the codebase and written to,
${RIFT_ROOT}/.build/.rift-env
When you enter the rift-shell the first obvious difference is the prompt
on the command line. The name of the workspace associated with the
rift-shell is prepended to the prompt. As long as you are within the
associated workspace it will be there. If you leave the workspace, this
workspace name will be replaced by 'INVALID' to indicate that you are no
longer in the workspace associated with the rift-shell.
The rift-shell also provides several useful functions for development.
These functions are defined in rift-bashrc and everyone is encouraged to
add to the list. One import function there is 'rift-refresh-env'. This
function is used to create the .rift-env file that contains the current
RIFT environment. If you need to update the environment you can either
exit and restart the rift-shell or simply execute rift-refresh-env from
the terminal.
OPTIONS
-c,--config <file> The rift-shell will use the specified file instead
of constructing the .rift-env file.
-e,--use-existing This option instructs the rift-shell to skip
generating the .rift-env file, but only if one
already exists.
-h, --help Prints out this information
-r, --root cd to RIFT_ROOT
-w use test_wrapper.sh
-E set an environment var
-- The double-dash is used to indicate to the
rift-shell that it should stop parsing the
following command line arguments, and instead
invoke those arguments after entering and setting
up the rift environment.
USAGEDOC
}
# Hold on to current RIFT_ROOT and RIFT_SHELL env vars for use later on.
CURRENT_RIFT_ROOT=$RIFT_ROOT
CURRENT_RIFT_SHELL=$RIFT_SHELL
# Define defaults
RIFT_ROOT=$(realpath "$(dirname "$0")")
# Set the RIFT_SHELL to the ROOT to track which workspace the SHELL is set to.
RIFT_SHELL=1
RIFT_INCLUDE_BUILD_DIRS=${RIFT_INCLUDE_BUILD_DIRS}
RIFT_CONFIG=
CD_RIFT_ROOT=0
USE_TEST_WRAPPER=0
if [ -z ${RIFT_INCLUDE_BUILD_DIRS} ]; then
RIFT_INCLUDE_BUILD_DIRS=0
fi
# Parse command line arguments
while [ $# -gt 0 ]; do
case $1 in
-w)
USE_TEST_WRAPPER=1;;
-r|--root)
CD_RIFT_ROOT=1;;
-c|--config)
RIFT_CONFIG=$2
shift
;;
-e|--use-existing)
if [ -s "${RIFT_ROOT}"/.build/.rift-env ]; then
RIFT_CONFIG="${RIFT_ROOT}"/.build/.rift-env
[ -t 1 ] && echo " * Using existing configuration file" >&2
fi
;;
--include-build-dirs)
RIFT_INCLUDE_BUILD_DIRS=1
;;
-E)
export "$2"
shift
;;
-h|--help)
shift
__usage
;;
--)
shift
break
;;
*)
echo "Unrecognized option"
exit 1
;;
esac
shift
done
# At this point the commands have been parsed so it should be safe to export
# these variables.
export RIFT_ROOT RIFT_SHELL RIFT_CONFIG RIFT_INCLUDE_BUILD_DIRS
if [ -z "$CCACHE_DIR" ]; then
echo "WARNING CCACHE_DIR not set"
fi
# This check is used to determine whether the shell is in interactive mode or
# non-interactive mode.
if [ $CD_RIFT_ROOT == 1 ]; then
cd $RIFT_ROOT
fi
if [ $# -gt 0 ]; then
# Found solution to properly quote commands passed through 'bash -c'
# http://stackoverflow.com/questions/1668649/how-to-keep-quotes-in-args
args=''
for i in "$@"; do
args="$args \"${i//\"/\\\"}\""
done;
if [ $USE_TEST_WRAPPER == 1 ]; then
args="$RIFT_ROOT/scripts/env/test_wrapper2.sh $args"
fi
if [[ ! -z "${CURRENT_RIFT_SHELL}" ]]; then
# If we're already in a RIFT_SHELL then make sure it's the correct one.
if [[ "${CURRENT_RIFT_ROOT}" != "${RIFT_ROOT}" ]]; then
echo "You are already running a RIFT shell, you must exit this one first."
exit 1
else
# We're already in the correct RIFT_SHELL, just invoke the command.
exec /bin/bash -c "exec $args"
fi
else
exec /bin/bash -c "source ${RIFT_ROOT}/rift-bashrc; exec $args"
fi
else
# Check to see if we are current in a RIFT shell.
if [[ ! -z "${CURRENT_RIFT_SHELL}" ]]; then
echo "You are already running a RIFT shell, you must exit this one first."
exit 1
fi
export SHELL=/bin/bash
exec /bin/bash --rcfile ${RIFT_ROOT}/rift-bashrc
fi