-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathplk
executable file
·217 lines (205 loc) · 4.97 KB
/
plk
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
#!/usr/bin/env bash
set -e
function join { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
# Extract opts
print_classpath=false
describe=false
verbose=false
force=false
repro=false
tree=false
pom=false
resolve_tags=false
help=false
resolve_aliases=()
classpath_aliases=()
main_aliases=()
all_aliases=()
while [ $# -gt 0 ]
do
case "$1" in
-J*)
shift
;;
-R*)
resolve_aliases+=("${1:2}")
shift
;;
-C*)
classpath_aliases+=("${1:2}")
shift
;;
-O*)
shift
;;
-M*)
main_aliases+=("${1:2}")
shift
;;
-A*)
all_aliases+=("${1:2}")
shift
;;
-Sdeps)
shift
deps_data="${1}"
shift
;;
-Scp)
shift
force_cp="${1}"
shift
;;
-Spath)
print_classpath=true
shift
;;
-Sverbose)
verbose=true
shift
;;
-Sdescribe)
describe=true
shift
;;
-Sforce)
force=true
shift
;;
-Srepro)
repro=true
shift
;;
-Stree)
tree=true
shift
;;
-Spom)
pom=true
shift
;;
-Sresolve-tags)
resolve_tags=true
shift
;;
-S*)
echo "Invalid option: $1"
exit 1
;;
-h|--help|"-?")
if [[ ${#main_aliases[@]} -gt 0 ]] || [[ ${#all_aliases[@]} -gt 0 ]]; then
break
else
help=true
shift
fi
;;
*)
break
;;
esac
done
# Find clojure executable
set +e
CLOJURE_CMD=$(type -p clojure)
set -e
if [[ ! -n "$CLOJURE_CMD" ]]; then
>&2 echo "Couldn't find 'clojure'."
>&2 echo "You can launch Planck directly using 'planck'."
>&2 echo "To use 'plk', please ensure 'clojure' is installed and on"
>&2 echo "your path. See https://clojure.org/guides/getting_started"
exit 1
fi
if "$help"; then
cat <<-END
Usage: plk [dep-opt*] [init-opt*] [main-opt] [arg*]
The plk script is a runner for Planck which ultimately constructs and
invokes a command-line of the form:
planck --classpath classpath [init-opt*] [main-opt] [arg*]
The dep-opts are used to build the classpath using the clojure tool:
-Ralias... Concatenated resolve-deps aliases, ex: -R:bench:1.9
-Calias... Concatenated make-classpath aliases, ex: -C:dev
-Malias... Concatenated main option aliases, ex: -M:test
-Aalias... Concatenated aliases of any kind, ex: -A:dev:mem
-Sdeps EDN Deps data to use as the final deps file
-Spath Compute classpath and echo to stdout only
-Scp CP Do NOT compute or cache classpath, use this one instead
-Srepro Ignore the ~/.clojure/deps.edn config file
-Sforce Force recomputation of the classpath (don't use the cache)
-Spom Generate (or update existing) pom.xml with deps and paths
-Stree Print dependency tree
-Sresolve-tags Resolve git coordinate tags to shas and update deps.edn
-Sverbose Print important path info to console
-Sdescribe Print environment and command parsing info as data
Additionally, for compatibility with clojure, -Jopt and -Oalias... dep-opts
are accepted but ignored.
END
planck -h | tail -n +6
exit 0
fi
# Execute resolve-tags command
if "$resolve_tags"; then
"$CLOJURE_CMD" -Sresolve-tags
exit
fi
clojure_args=()
if [[ -n "$deps_data" ]]; then
clojure_args+=("-Sdeps" "$deps_data")
fi
if [[ ${#resolve_aliases[@]} -gt 0 ]]; then
clojure_args+=("-R$(join '' ${resolve_aliases[@]})")
fi
if [[ ${#classpath_aliases[@]} -gt 0 ]]; then
clojure_args+=("-C$(join '' ${classpath_aliases[@]})")
fi
if [[ ${#main_aliases[@]} -gt 0 ]]; then
clojure_args+=("-M$(join '' ${main_aliases[@]})")
fi
if [[ ${#all_aliases[@]} -gt 0 ]]; then
clojure_args+=("-A$(join '' ${all_aliases[@]})")
fi
if "$repro"; then
clojure_args+=("-Srepro")
fi
if "$force"; then
clojure_args+=("-Sforce")
fi
if "$pom"; then
if "$verbose"; then
clojure_args+=("-Sverbose")
fi
"$CLOJURE_CMD" "${clojure_args[@]}" -Spom
elif "$describe"; then
if "$verbose"; then
clojure_args+=("-Sverbose")
fi
"$CLOJURE_CMD" "${clojure_args[@]}" -Sdescribe
elif "$tree"; then
if "$verbose"; then
clojure_args+=("-Sverbose")
fi
"$CLOJURE_CMD" "${clojure_args[@]}" -Stree
else
set -f
if [[ -n "$force_cp" ]]; then
cp="$force_cp"
else
if "$verbose"; then
"$CLOJURE_CMD" "${clojure_args[@]}" -Sverbose -e nil
fi
cp=`"$CLOJURE_CMD" "${clojure_args[@]}" -Spath`
fi
if "$print_classpath"; then
echo $cp
else
if [[ ${#main_aliases[@]} -gt 0 ]] || [[ ${#all_aliases[@]} -gt 0 ]]; then
# Attempt to extract the main cache filename by parsing the output of -Sverbose
cp_file=`"$CLOJURE_CMD" "${clojure_args[@]}" -Sverbose -Spath | grep cp_file | cut -d = -f 2 | sed 's/^ *//g'`
main_file="${cp_file%.cp}.main"
fi
if [[ -e "$main_file" ]]; then
main_cache_opts=($(cat "$main_file"))
fi
exec planck --classpath "$cp" "${main_cache_opts[@]}" "$@"
fi
fi