forked from vrdabomb5717/Tandem
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtandem
executable file
·303 lines (239 loc) · 6.05 KB
/
tandem
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/env bash
# Written by Donald Pomeroy and Varun Ravishankar
EXPECTED_ARGS=1
E_BADARGS=22
E_NOFILE=2
E_WRONGFILETYPE=79
E_MISSINGCMD=1
E_BADVERSION=75
TANDEM_VERSION=0.1
use_jruby=0
compile_only=0
run_only=0
_ruby=""
display_version()
{
echo "Tandem $TANDEM_VERSION"
}
display_usage()
{
echo "Usage: `basename $0` [options] [filename]"
}
display_help()
{
echo "Usage: `basename $0` [options] [filename]
options:
-b --ruby Attempt to use system Ruby. If not valid, use JRuby.
-c --compile Only compile Tandem file.
-d --deps Resolve dependencies and download needed files.
-h --help List Tandem usage and options.
-j --jruby Use downloaded JRuby.
-r --run Assume compiled Ruby file exists and try running file.
-v --version Print Tandem version.
-w --whole Compile and run Tandem file."
}
walk_test()
{
ant_out=$(ant walk -Dfile="$1")
ant_out=$(echo $ant_out | sed 's/\(.*\)\(walk: \)//1' | sed 's/BUILD SUCCESSFUL//g' | sed 's/Total.*//g' | sed "s/\[java\]/\\`echo -e '\n\r'`\[Tandem\]/g")
ant_out1=$ant_out
ant_out1=$(echo $ant_out1 | sed 's/\s+//g' | sed 's/ *$//g' | sed 's/^ *//g')
#echo $ant_out
#echo ${#ant_out1}
if [[ ${#ant_out1} == "0" ]]; then
: #echo "GOOD"
else
echo "$ant_out"
echo "ERROR" >&2
exit
fi
}
run_file()
{
ruby_file=${@%.*}.rb
#run a different version of ruby based on ant rubyexec
$_ruby "$ruby_file"
exit
}
check_ruby()
{
if [[ "$use_jruby" > 0 ]]; then
_ruby="java -jar lib/runtime/jruby-complete.jar --1.9"
return
fi
if type -p ruby &>/dev/null; then
: # echo "found ruby executable in PATH"
_ruby=ruby
elif [[ "/usr/bin/env ruby" ]]; then
: #echo "found ruby executable in ENV"
_ruby="/usr/bin/env ruby"
else
use_jruby=1
fi
if [[ "$_ruby" ]]; then
version=$("$_ruby" -v 2>&1 |grep -e "1\.9\.[2-9]" )
# if version if less than 1.9.2, use JRuby
if [[ "$?" > "0" ]]; then
use_jruby=1
else
: #echo "Passed Ruby Check"
fi
fi
if [[ "$use_jruby" > 0 ]]; then
_ruby="java -jar lib/runtime/jruby-complete.jar --1.9"
fi
}
resolve_deps()
{
echo "resolving dependencies..." >&2
init=$(ant init)
}
################################################################
# Check for options
#Check if a file is passed, if not fail
if [ $# -lt $EXPECTED_ARGS ]
then
echo "COMPILATION FAILED - filename expected" >&2
echo
display_usage $0
exit $E_BADARGS
fi
# check whether user had supplied -h or --help . If yes display usage
if [[ ( $1 == "--help") || $1 == "-h" ]]
then
display_help
exit 0
fi
# check whether user had supplied -v or --version . If yes display version
if [[ ( $1 == "--version") || $1 == "-v" ]]
then
display_version
exit 0
fi
# check whether user had supplied -d or --deps . If yes download all deps and exit
if [[ ( $1 == "--deps") || $1 == "-d" ]]
then
resolve_deps
exit 0
fi
# check whether user had supplied -c or --compile . If yes set to compile only mode
if [[ ( $1 == "--compile") || $1 == "-c" ]]
then
compile_only=1
shift
fi
# check whether user had supplied -r or --run . If yes set to run only mode
if [[ ( $1 == "--run") || $1 == "-r" ]]
then
shift
run_only=1
check_ruby
run_file $1
fi
# check whether user had supplied -w or --whole . If yes continue on
if [[ ( $1 == "--whole") || $1 == "-w" ]]
then
shift
fi
# check whether user had supplied -b or --ruby . If yes continue on
if [[ ( $1 == "--ruby") || $1 == "-b" ]]
then
shift
fi
# check whether user had supplied -b or --ruby . If yes continue on
if [[ ( $1 == "--ruby") || $1 == "-b" ]]
then
shift
fi
# check whether user had supplied -j or --jruby . If yes set jruby mode
if [[ ( $1 == "--jruby") || $1 == "-j" ]]
then
use_jruby=1
shift
fi
###################################################################
# Check for invalid arguments
FILE=$1
#Check if the filename is valid .td
if [[ "$FILE" == *.td ]]
then
: # echo "valid filename"
else
echo "COMPILATION FAILED - invalid filename" >&2
exit $E_WRONGFILETYPE
fi
if [ -f "$FILE" ]
then
: #echo "the file exists"
else
echo "COMPILATION FAILED - the file does not exist" >&2
exit $E_NOFILE
fi
###################################################################
# Check for dependencies
#check java
#check ant 1.8
#check ruby 1.9.2
if type -p java &>/dev/null; then
: #echo "found java executable in PATH"
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ "$JAVA_HOME/bin/java" ]]; then
: # echo "found java executable in JAVA_HOME"
_java="$JAVA_HOME/bin/java"
else
echo "COMPILATION FAILED - no java" >&2
exit $E_MISSINGCMD
fi
if [[ "$_java" ]]; then
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
: #echo version "$version"
if [[ "$version" > "1.5" ]]; then
: # echo "version is more than 1.5"
else
echo "COMPILATION FAILED - version is less than 1.5" >&2
exit $E_BADVERSION
fi
fi
if type -p ant&>/dev/null; then
: #echo found ant executable in PATH
_ant=ant
elif [[ "/usr/bin/env ant" ]]; then
: #echo "found ant executable in ENV_ANT"
_ant="usr/bin/env ant"
else
echo "COMPILATION FAILED - no ant" >&2
exit $E_MISSINGCMD
fi
if [[ "$_ant" ]]; then
version=$("$_ant" -version 2>&1 | grep -e "1\.8\.[0-9]")
: #echo version "$version"
if [[ "$?" == "0" ]]; then
: #echo "version is more than 1.8"
else
echo "COMPILATION FAILED - version is less than 1.8" >&2
exit $E_BADVERSION
fi
fi
#Make JRuby use Ruby 1.9
JRUBY_OPTS=--1.9
check_ruby
DIR=$(pwd)
#$(echo $IN | tr ";" "\n")
###################################################################
# Begin compilation process
resolve_deps
echo "compiling..." >&2
a=$($_ruby src/dependency.rb "$FILE" | sed 's/DELIM/\'$'\n/g' | sed 's/^ *//g')
OIFS="$IFS"
IFS=$'\n'
for x in $a
do
x=$(echo $x | sed 's/^ *//g' | sed 's/ *$//g')
walk_test "$x"
done
IFS="$OIFS"
walk_test "$FILE"
if [ $compile_only = 1 ]; then
exit
fi
run_file $FILE