-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlein
executable file
·281 lines (248 loc) · 9.35 KB
/
lein
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
#!/usr/bin/env bash
# Ensure this file is executable via chmod a+x lein, then place it
# somewhere on your $PATH, like ~/bin. The rest of Leiningen will be
# installed upon first run into the ~/.lein/self-installs directory.
export LEIN_VERSION="2.0.0-preview10"
case $LEIN_VERSION in
*SNAPSHOT) SNAPSHOT="YES" ;;
*) SNAPSHOT="NO" ;;
esac
if [ `id -u` -eq 0 ] && [ "$LEIN_ROOT" = "" ]; then
echo "WARNING: You're currently running as root; probably by accident."
echo "Press control-C to abort or Enter to continue as root."
echo "Set LEIN_ROOT to disable this warning."
read _
fi
NOT_FOUND=1
ORIGINAL_PWD="$PWD"
while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ]
do
cd ..
if [ "$(dirname "$PWD")" = "/" ]; then
NOT_FOUND=0
cd "$ORIGINAL_PWD"
fi
done
export LEIN_HOME=${LEIN_HOME:-"$HOME/.lein"}
for f in "$LEIN_HOME/leinrc" ".leinrc"; do
if [ -e $f ]; then
source $f
fi
done
if [ "$OSTYPE" = "cygwin" ]; then
export LEIN_HOME=`cygpath -w $LEIN_HOME`
fi
LEIN_JAR="$LEIN_HOME/self-installs/leiningen-$LEIN_VERSION-standalone.jar"
# normalize $0 on certain BSDs
if [ "$(dirname "$0")" = "." ]; then
SCRIPT="$(which $(basename "$0"))"
else
SCRIPT="$0"
fi
# resolve symlinks to the script itself portably
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT="$(dirname "$SCRIPT"$)/$link"
fi
done
BIN_DIR="$(dirname "$SCRIPT")"
# Try to make the default more sane for :eval-in :classloader.lein
grep -E -q '^\s*:eval-in\s+:classloader\s*$' project.clj 2> /dev/null &&
LEIN_JVM_OPTS=${LEIN_JVM_OPTS:-'-Xms64m -Xmx512m'}
if [ -r "$BIN_DIR/../src/leiningen/version.clj" ]; then
# Running from source checkout
LEIN_DIR="$(dirname "$BIN_DIR")"
# Need to use lein 1.x to bootstrap the leiningen-core library (for aether)
if [ "$(ls $LEIN_DIR/leiningen-core/lib/*)" = "" ]; then
echo "Leiningen is missing its dependencies."
echo "Please see \"Building\" in the README."
exit 1
fi
# If project.clj for lein or leiningen-core changes, we must recalculate
LAST_PROJECT_CHECKSUM=$(cat "$LEIN_DIR/.lein-project-checksum" 2> /dev/null)
PROJECT_CHECKSUM=$(sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj")
if [ "$PROJECT_CHECKSUM" != "$LAST_PROJECT_CHECKSUM" ]; then
if [ -r "$LEIN_DIR/.lein-classpath" ]; then
rm "$LEIN_DIR/.lein-classpath"
fi
fi
# Use bin/lein to calculate its own classpath since src/ and
# leiningen-core/lib/*jar suffices to run the classpath task.
if [ ! -r "$LEIN_DIR/.lein-classpath" ] && [ "$1" != "classpath" ]; then
echo "Recalculating Leiningen's classpath."
ORIG_PWD="$PWD"
cd "$LEIN_DIR"
$0 classpath .lein-classpath
sum $LEIN_DIR/project.clj $LEIN_DIR/leiningen-core/project.clj > \
.lein-project-checksum
cd "$ORIG_PWD"
fi
mkdir -p "$LEIN_DIR/target/classes"
export LEIN_JVM_OPTS="${LEIN_JVM_OPTS:--Xms64m -Xmx256m} -Dclojure.compile.path=$LEIN_DIR/target/classes"
CLASSPATH="$LEIN_DIR/leiningen-core/src/"
CLASSPATH="$CLASSPATH:$LEIN_DIR/leiningen-core/resources/"
if [ -r "$LEIN_DIR/.lein-classpath" ]; then
CLASSPATH="$CLASSPATH:$(cat $LEIN_DIR/.lein-classpath 2> /dev/null)"
else
CLASSPATH="$CLASSPATH:$LEIN_DIR/leiningen-core/lib/*"
fi
CLASSPATH="$CLASSPATH:$LEIN_DIR/test:$LEIN_DIR/target/classes"
CLASSPATH="$CLASSPATH:$LEIN_DIR/src:$LEIN_DIR/resources:$LEIN_JAR"
if [ -f .lein-classpath ]; then
CLASSPATH="`cat .lein-classpath`:$CLASSPATH"
fi
else # Not running from a checkout
# apply context specific CLASSPATH entries
if [ -f .lein-classpath ]; then
CLASSPATH="`cat .lein-classpath`:$LEIN_JAR"
else
CLASSPATH="$LEIN_JAR"
fi
export LEIN_JVM_OPTS=${LEIN_JVM_OPTS:-"-Xbootclasspath/a:$LEIN_JAR"}
if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then
"$0" self-install
fi
fi
if [ "$HTTP_CLIENT" = "" ]; then
if type -p curl >/dev/null 2>&1; then
if [ "$https_proxy" != "" ]; then
CURL_PROXY="-x $https_proxy"
fi
HTTP_CLIENT="curl $CURL_PROXY -f -L -o"
else
HTTP_CLIENT="wget -O"
fi
fi
function download_failed_message {
echo "Failed to download $1"
echo "It's possible your HTTP client's certificate store does not have the"
echo "correct certificate authority needed. This is often caused by an"
echo "out-of-date version of libssl. Either upgrade it or set HTTP_CLIENT"
echo "to turn off certificate checks:"
echo " export HTTP_CLIENT=\"wget --no-check-certificate -O\" # or"
echo " export HTTP_CLIENT=\"curl --insecure -f -L -o\""
}
# TODO: explain what to do when Java is missing
export JAVA_CMD=${JAVA_CMD:-"java"}
export LEIN_JAVA_CMD=${LEIN_JAVA_CMD:-$JAVA_CMD}
# Support $JAVA_OPTS for backwards-compatibility.
export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}"
# TODO: investigate http://skife.org/java/unix/2011/06/20/really_executable_jars.html
# If you're packaging this for a package manager (.deb, homebrew, etc)
# you need to remove the self-install and upgrade functionality or see lein-pkg.
if [ "$1" = "self-install" ]; then
if [ -r "$LEIN_JAR" ]; then
echo "The self-install jar already exists at $LEIN_JAR."
echo "If you wish to re-download, delete it and rerun \"$0 self-install\"."
exit 1
fi
echo "Downloading Leiningen now..."
LEIN_DIR=`dirname "$LEIN_JAR"`
mkdir -p "$LEIN_DIR"
LEIN_URL="https://github.com/downloads/technomancy/leiningen/leiningen-$LEIN_VERSION-standalone.jar"
$HTTP_CLIENT "$LEIN_JAR.pending" "$LEIN_URL"
if [ $? == 0 ]; then
# TODO: checksum
mv -f "$LEIN_JAR.pending" "$LEIN_JAR"
else
rm "$LEIN_JAR.pending" 2> /dev/null
download_failed_message "$LEIN_URL"
if [ $SNAPSHOT = "YES" ]; then
echo "See README.md for SNAPSHOT-specific build instructions."
fi
exit 1
fi
elif [ "$1" = "upgrade" ]; then
if [ "$LEIN_DIR" != "" ]; then
echo "The upgrade task is not meant to be run from a checkout."
exit 1
fi
if [ $SNAPSHOT = "YES" ]; then
echo "The upgrade task is only meant for stable releases."
echo "See the \"Hacking\" section of the README."
exit 1
fi
if [ ! -w "$SCRIPT" ]; then
echo "You do not have permission to upgrade the installation in $SCRIPT"
exit 1
else
TARGET_VERSION="${2:-"preview"}"
echo "The script at $SCRIPT will be upgraded to the latest $TARGET_VERSION version."
echo -n "Do you want to continue [Y/n]? "
read RESP
case "$RESP" in
y|Y|"")
echo
echo "Upgrading..."
TARGET="/tmp/lein-$$-upgrade"
if [ "$OSTYPE" = "cygwin" ]; then
TARGET=`cygpath -w $TARGET`
fi
LEIN_SCRIPT_URL="https://github.com/technomancy/leiningen/raw/$TARGET_VERSION/bin/lein"
$HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL"
if [ $? == 0 ]; then
mv "$TARGET" "$SCRIPT" \
&& chmod +x "$SCRIPT" \
&& echo && "$SCRIPT" self-install \
&& echo && echo "Now running" `$SCRIPT version`
exit $?
else
download_failed_message "$LEIN_SCRIPT_URL"
fi;;
*)
echo "Aborted."
exit 1;;
esac
fi
else
if [ "$OSTYPE" = "cygwin" ]; then
# When running on Cygwin, use Windows-style paths for java
ORIGINAL_PWD=`cygpath -w "$ORIGINAL_PWD"`
CLASSPATH=`cygpath -wp "$CLASSPATH"`
fi
if [ $DEBUG ]; then
echo "Leiningen's classpath: $CLASSPATH"
fi
if [ "$LEIN_FAST_TRAMPOLINE" = "" ] && [ ! -r .lein-fast-trampoline ]; then
TRAMPOLINE_FILE="/tmp/lein-trampoline-$$"
trap "rm -f $TRAMPOLINE_FILE" EXIT
else
INPUTS="$@ $(cat project.clj) $(cat $LEIN_HOME/profiles.clj)"
INPUT_CHECKSUM=$(echo $INPUTS | shasum - | cut -f 1 -d " ")
# Just don't change :target-path in project.clj, mkay?
TRAMPOLINE_FILE="target/trampolines/$INPUT_CHECKSUM"
fi
if [ "$OSTYPE" = "cygwin" ]; then
TRAMPOLINE_FILE=`cygpath -w $TRAMPOLINE_FILE`
fi
if [ "$INPUT_CHECKSUM" != "" ] && [ -r "$TRAMPOLINE_FILE" ]; then
if [ $DEBUG ]; then
echo "Fast trampoline with $TRAMPOLINE_FILE."
fi
exec sh -c "exec $(cat $TRAMPOLINE_FILE)"
else
$LEIN_JAVA_CMD \
-client -XX:+TieredCompilation \
$LEIN_JVM_OPTS \
-Dfile.encoding=UTF-8 \
-Dmaven.wagon.http.ssl.easy=false \
-Dleiningen.original.pwd="$ORIGINAL_PWD" \
-Dleiningen.trampoline-file="$TRAMPOLINE_FILE" \
-cp "$CLASSPATH" \
clojure.main -m leiningen.core.main "$@"
EXIT_CODE=$?
if [ -r "$TRAMPOLINE_FILE" ]; then
TRAMPOLINE="$(cat $TRAMPOLINE_FILE)"
if [ "$INPUT_CHECKSUM" = "" ]; then
rm $TRAMPOLINE_FILE
fi
exec sh -c "exec $TRAMPOLINE"
else
exit $EXIT_CODE
fi
fi
fi