Skip to content

Commit 8d107ae

Browse files
committed
[Docker] Updated command-line parsing of docker/bash.sh
- Maintained previous behavior, any unrecognized flags after the docker/bash.sh are part of the command, no -- is needed. (e.g. docker/bash.sh ci_gpu make -j2) - Reverted changes to Jenskinsfile to add a --, no longer needed.
1 parent 039b38c commit 8d107ae

File tree

2 files changed

+97
-76
lines changed

2 files changed

+97
-76
lines changed

Jenkinsfile

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ stage("Sanity Check") {
112112
node('CPU') {
113113
ws(per_exec_ws("tvm/sanity")) {
114114
init_git()
115-
sh "${docker_run} ${ci_lint} -- ./tests/scripts/task_lint.sh"
115+
sh "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh"
116116
}
117117
}
118118
}
@@ -124,18 +124,18 @@ stage("Sanity Check") {
124124
def make(docker_type, path, make_flag) {
125125
timeout(time: max_time, unit: 'MINUTES') {
126126
try {
127-
sh "${docker_run} ${docker_type} -- ./tests/scripts/task_build.sh ${path} ${make_flag}"
127+
sh "${docker_run} ${docker_type} ./tests/scripts/task_build.sh ${path} ${make_flag}"
128128
// always run cpp test when build
129-
sh "${docker_run} ${docker_type} -- ./tests/scripts/task_cpp_unittest.sh"
129+
sh "${docker_run} ${docker_type} ./tests/scripts/task_cpp_unittest.sh"
130130
} catch (hudson.AbortException ae) {
131131
// script exited due to user abort, directly throw instead of retry
132132
if (ae.getMessage().contains('script returned exit code 143')) {
133133
throw ae
134134
}
135135
echo 'Incremental compilation failed. Fall back to build from scratch'
136-
sh "${docker_run} ${docker_type} -- ./tests/scripts/task_clean.sh ${path}"
137-
sh "${docker_run} ${docker_type} -- ./tests/scripts/task_build.sh ${path} ${make_flag}"
138-
sh "${docker_run} ${docker_type} -- ./tests/scripts/task_cpp_unittest.sh"
136+
sh "${docker_run} ${docker_type} ./tests/scripts/task_clean.sh ${path}"
137+
sh "${docker_run} ${docker_type} ./tests/scripts/task_build.sh ${path} ${make_flag}"
138+
sh "${docker_run} ${docker_type} ./tests/scripts/task_cpp_unittest.sh"
139139
}
140140
}
141141
}
@@ -164,11 +164,11 @@ stage('Build') {
164164
node('GPUBUILD') {
165165
ws(per_exec_ws("tvm/build-gpu")) {
166166
init_git()
167-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_config_build_gpu.sh"
167+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_config_build_gpu.sh"
168168
make(ci_gpu, 'build', '-j2')
169169
pack_lib('gpu', tvm_multilib)
170170
// compiler test
171-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_config_build_gpu_vulkan.sh"
171+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_config_build_gpu_vulkan.sh"
172172
make(ci_gpu, 'build2', '-j2')
173173
}
174174
}
@@ -177,18 +177,18 @@ stage('Build') {
177177
node('CPU') {
178178
ws(per_exec_ws("tvm/build-cpu")) {
179179
init_git()
180-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_config_build_cpu.sh"
180+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_config_build_cpu.sh"
181181
make(ci_cpu, 'build', '-j2')
182182
pack_lib('cpu', tvm_multilib)
183183
timeout(time: max_time, unit: 'MINUTES') {
184-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_ci_setup.sh"
185-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_python_unittest.sh"
186-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_python_integration.sh"
187-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_python_vta_fsim.sh"
188-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_python_vta_tsim.sh"
189-
// sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_golang.sh"
184+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_ci_setup.sh"
185+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_unittest.sh"
186+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_integration.sh"
187+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_vta_fsim.sh"
188+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_vta_tsim.sh"
189+
// sh "${docker_run} ${ci_cpu} ./tests/scripts/task_golang.sh"
190190
// TODO(@jroesch): need to resolve CI issue will turn back on in follow up patch
191-
// sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_rust.sh"
191+
// sh "${docker_run} ${ci_cpu} ./tests/scripts/task_rust.sh"
192192
junit "build/pytest-results/*.xml"
193193
}
194194
}
@@ -198,11 +198,11 @@ stage('Build') {
198198
node('CPU') {
199199
ws(per_exec_ws("tvm/build-wasm")) {
200200
init_git()
201-
sh "${docker_run} ${ci_wasm} -- ./tests/scripts/task_config_build_wasm.sh"
201+
sh "${docker_run} ${ci_wasm} ./tests/scripts/task_config_build_wasm.sh"
202202
make(ci_wasm, 'build', '-j2')
203203
timeout(time: max_time, unit: 'MINUTES') {
204-
sh "${docker_run} ${ci_wasm} -- ./tests/scripts/task_ci_setup.sh"
205-
sh "${docker_run} ${ci_wasm} -- ./tests/scripts/task_web_wasm.sh"
204+
sh "${docker_run} ${ci_wasm} ./tests/scripts/task_ci_setup.sh"
205+
sh "${docker_run} ${ci_wasm} ./tests/scripts/task_web_wasm.sh"
206206
}
207207
}
208208
}
@@ -211,7 +211,7 @@ stage('Build') {
211211
node('CPU') {
212212
ws(per_exec_ws("tvm/build-i386")) {
213213
init_git()
214-
sh "${docker_run} ${ci_i386} -- ./tests/scripts/task_config_build_i386.sh"
214+
sh "${docker_run} ${ci_i386} ./tests/scripts/task_config_build_i386.sh"
215215
make(ci_i386, 'build', '-j2')
216216
pack_lib('i386', tvm_multilib)
217217
}
@@ -221,7 +221,7 @@ stage('Build') {
221221
node('ARM') {
222222
ws(per_exec_ws("tvm/build-arm")) {
223223
init_git()
224-
sh "${docker_run} ${ci_arm} -- ./tests/scripts/task_config_build_arm.sh"
224+
sh "${docker_run} ${ci_arm} ./tests/scripts/task_config_build_arm.sh"
225225
make(ci_arm, 'build', '-j4')
226226
pack_lib('arm', tvm_multilib)
227227
}
@@ -231,11 +231,11 @@ stage('Build') {
231231
node('CPU') {
232232
ws(per_exec_ws("tvm/build-qemu")) {
233233
init_git()
234-
sh "${docker_run} ${ci_qemu} -- ./tests/scripts/task_config_build_qemu.sh"
234+
sh "${docker_run} ${ci_qemu} ./tests/scripts/task_config_build_qemu.sh"
235235
make(ci_qemu, 'build', '-j2')
236236
timeout(time: max_time, unit: 'MINUTES') {
237-
sh "${docker_run} ${ci_qemu} -- ./tests/scripts/task_ci_setup.sh"
238-
sh "${docker_run} ${ci_qemu} -- ./tests/scripts/task_python_microtvm.sh"
237+
sh "${docker_run} ${ci_qemu} ./tests/scripts/task_ci_setup.sh"
238+
sh "${docker_run} ${ci_qemu} ./tests/scripts/task_python_microtvm.sh"
239239
junit "build/pytest-results/*.xml"
240240
}
241241
}
@@ -250,10 +250,10 @@ stage('Unit Test') {
250250
init_git()
251251
unpack_lib('gpu', tvm_multilib)
252252
timeout(time: max_time, unit: 'MINUTES') {
253-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_ci_setup.sh"
254-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_sphinx_precheck.sh"
255-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_python_unittest_gpuonly.sh"
256-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_python_integration_gpuonly.sh"
253+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_ci_setup.sh"
254+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_sphinx_precheck.sh"
255+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_unittest_gpuonly.sh"
256+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_integration_gpuonly.sh"
257257
junit "build/pytest-results/*.xml"
258258
}
259259
}
@@ -265,10 +265,10 @@ stage('Unit Test') {
265265
init_git()
266266
unpack_lib('i386', tvm_multilib)
267267
timeout(time: max_time, unit: 'MINUTES') {
268-
sh "${docker_run} ${ci_i386} -- ./tests/scripts/task_ci_setup.sh"
269-
sh "${docker_run} ${ci_i386} -- ./tests/scripts/task_python_unittest.sh"
270-
sh "${docker_run} ${ci_i386} -- ./tests/scripts/task_python_integration.sh"
271-
sh "${docker_run} ${ci_i386} -- ./tests/scripts/task_python_vta_fsim.sh"
268+
sh "${docker_run} ${ci_i386} ./tests/scripts/task_ci_setup.sh"
269+
sh "${docker_run} ${ci_i386} ./tests/scripts/task_python_unittest.sh"
270+
sh "${docker_run} ${ci_i386} ./tests/scripts/task_python_integration.sh"
271+
sh "${docker_run} ${ci_i386} ./tests/scripts/task_python_vta_fsim.sh"
272272
junit "build/pytest-results/*.xml"
273273
}
274274
}
@@ -280,8 +280,8 @@ stage('Unit Test') {
280280
init_git()
281281
unpack_lib('arm', tvm_multilib)
282282
timeout(time: max_time, unit: 'MINUTES') {
283-
sh "${docker_run} ${ci_arm} -- ./tests/scripts/task_ci_setup.sh"
284-
sh "${docker_run} ${ci_arm} -- ./tests/scripts/task_python_unittest.sh"
283+
sh "${docker_run} ${ci_arm} ./tests/scripts/task_ci_setup.sh"
284+
sh "${docker_run} ${ci_arm} ./tests/scripts/task_python_unittest.sh"
285285
junit "build/pytest-results/*.xml"
286286
// sh "${docker_run} ${ci_arm} ./tests/scripts/task_python_integration.sh"
287287
}
@@ -294,8 +294,8 @@ stage('Unit Test') {
294294
init_git()
295295
unpack_lib('gpu', tvm_multilib)
296296
timeout(time: max_time, unit: 'MINUTES') {
297-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_ci_setup.sh"
298-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_java_unittest.sh"
297+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_ci_setup.sh"
298+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_java_unittest.sh"
299299
}
300300
}
301301
}
@@ -309,8 +309,8 @@ stage('Integration Test') {
309309
init_git()
310310
unpack_lib('gpu', tvm_multilib)
311311
timeout(time: max_time, unit: 'MINUTES') {
312-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_ci_setup.sh"
313-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_python_topi.sh"
312+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_ci_setup.sh"
313+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_topi.sh"
314314
junit "build/pytest-results/*.xml"
315315
}
316316
}
@@ -322,8 +322,8 @@ stage('Integration Test') {
322322
init_git()
323323
unpack_lib('gpu', tvm_multilib)
324324
timeout(time: max_time, unit: 'MINUTES') {
325-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_ci_setup.sh"
326-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_python_frontend.sh"
325+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_ci_setup.sh"
326+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_frontend.sh"
327327
junit "build/pytest-results/*.xml"
328328
}
329329
}
@@ -335,8 +335,8 @@ stage('Integration Test') {
335335
init_git()
336336
unpack_lib('cpu', tvm_multilib)
337337
timeout(time: max_time, unit: 'MINUTES') {
338-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_ci_setup.sh"
339-
sh "${docker_run} ${ci_cpu} -- ./tests/scripts/task_python_frontend_cpu.sh"
338+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_ci_setup.sh"
339+
sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_frontend_cpu.sh"
340340
junit "build/pytest-results/*.xml"
341341
}
342342
}
@@ -348,8 +348,8 @@ stage('Integration Test') {
348348
init_git()
349349
unpack_lib('gpu', tvm_multilib)
350350
timeout(time: max_time, unit: 'MINUTES') {
351-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_ci_setup.sh"
352-
sh "${docker_run} ${ci_gpu} -- ./tests/scripts/task_python_docs.sh"
351+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_ci_setup.sh"
352+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_docs.sh"
353353
}
354354
pack_lib('mydocs', 'docs.tgz')
355355
}
@@ -361,13 +361,13 @@ stage('Integration Test') {
361361
stage('Build packages') {
362362
parallel 'conda CPU': {
363363
node('CPU') {
364-
sh "${docker_run} tlcpack/conda-cpu -- ./conda/build_cpu.sh
364+
sh "${docker_run} tlcpack/conda-cpu ./conda/build_cpu.sh
365365
}
366366
},
367367
'conda cuda': {
368368
node('CPU') {
369-
sh "${docker_run} tlcpack/conda-cuda90 -- ./conda/build_cuda.sh
370-
sh "${docker_run} tlcpack/conda-cuda100 -- ./conda/build_cuda.sh
369+
sh "${docker_run} tlcpack/conda-cuda90 ./conda/build_cuda.sh
370+
sh "${docker_run} tlcpack/conda-cuda100 ./conda/build_cuda.sh
371371
}
372372
}
373373
// Here we could upload the packages to anaconda for releases

docker/bash.sh

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#
2121
# Start a bash, mount REPO_MOUNT_POINT to be current directory.
2222
#
23-
# Usage: bash.sh <CONTAINER_TYPE> [-i] [--net=host] [--mount path] <CONTAINER_NAME> <COMMAND>
23+
# Usage: docker/bash.sh [-i|--interactive] [--net=host]
24+
# [--mount MOUNT_DIR] [--repo-mount-point REPO_MOUNT_POINT]
25+
# [--dry-run]
26+
# <DOCKER_IMAGE_NAME> [--] [COMMAND]
2427
#
2528
# Usage: docker/bash.sh <CONTAINER_NAME>
2629
# Starts an interactive session
@@ -107,17 +110,20 @@ COMMAND=bash
107110
REPO_MOUNT_POINT="${WORKSPACE}"
108111
MOUNT_DIRS=( )
109112

110-
trap "show_usage >&2" ERR
111-
args=$(getopt \
112-
--name bash.sh \
113-
--options "ih" \
114-
--longoptions "interactive,net=host,mount:,dry-run" \
115-
--longoptions "repo-mount-point:" \
116-
--longoptions "help" \
117-
--unquoted \
118-
-- "$@")
119-
trap - ERR
120-
set -- $args
113+
function parse_error() {
114+
echo "$@" >&2
115+
show_usage >&2
116+
exit 1
117+
}
118+
119+
120+
# Handle joined flags, such as interpreting -ih as -i -h. Either rewrites
121+
# the current argument if it is a joined argument, or shifts all arguments
122+
# otherwise. Should be called as "eval $break_joined_flag" where joined
123+
# flags are possible. Can't use a function definition, because it needs
124+
# to overwrite the parent scope's behavior.
125+
break_joined_flag='if (( ${#1} == 2 )); then shift; else set -- -"${1#-i}" "${@:2}"; fi'
126+
121127

122128
while (( $# )); do
123129
case "$1" in
@@ -126,9 +132,9 @@ while (( $# )); do
126132
exit 0
127133
;;
128134

129-
-i|--interactive)
135+
-i*|--interactive)
130136
INTERACTIVE=true
131-
shift
137+
eval $break_joined_flag
132138
;;
133139

134140
--net=host)
@@ -137,8 +143,16 @@ while (( $# )); do
137143
;;
138144

139145
--mount)
140-
MOUNT_DIRS+=("$2")
141-
shift
146+
if [[ -n "$2" ]]; then
147+
MOUNT_DIRS+=("$2")
148+
shift 2
149+
else
150+
parse_error 'ERROR: --mount requires a non-empty argument'
151+
fi
152+
;;
153+
154+
--mount=?*)
155+
MOUNT_DIRS+=("${1#*=}")
142156
shift
143157
;;
144158

@@ -148,8 +162,16 @@ while (( $# )); do
148162
;;
149163

150164
--repo-mount-point)
151-
REPO_MOUNT_POINT="$2"
152-
shift
165+
if [[ -n "$2" ]]; then
166+
REPO_MOUNT_POINT="$2"
167+
shift 2
168+
else
169+
parse_error 'ERROR: --repo-mount-point requires a non-empty argument'
170+
fi
171+
;;
172+
173+
--repo-mount-point=?*)
174+
REPO_MOUNT_POINT="${1#*=}"
153175
shift
154176
;;
155177

@@ -168,25 +190,24 @@ while (( $# )); do
168190
;;
169191

170192
*)
171-
echo "Internal Error: getopt should output -- before positional" >&2
172-
exit 2
193+
# First positional argument is the image name, all
194+
# remaining below to the COMMAND.
195+
if [[ -z "${DOCKER_IMAGE_NAME}" ]]; then
196+
DOCKER_IMAGE_NAME=$1
197+
shift
198+
else
199+
COMMAND="$@"
200+
break
201+
fi
173202
;;
174203
esac
175204
done
176205

177-
if (( $# )); then
178-
DOCKER_IMAGE_NAME=$1
179-
shift
180-
else
206+
if [[ -z "${DOCKER_IMAGE_NAME}" ]]; then
181207
echo "Error: Missing DOCKER_IMAGE_NAME" >&2
182208
show_usage >&2
183209
fi
184210

185-
if (( $# )); then
186-
COMMAND="$@"
187-
fi
188-
189-
190211
if [[ "${COMMAND}" = bash ]]; then
191212
INTERACTIVE=true
192213
USE_NET_HOST=true

0 commit comments

Comments
 (0)