forked from apache/yetus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-patch.sh
executable file
·2840 lines (2456 loc) · 76.1 KB
/
test-patch.sh
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Make sure that bash version meets the pre-requisite
if [[ -z "${BASH_VERSINFO}" ]] \
|| [[ "${BASH_VERSINFO[0]}" -lt 3 ]] \
|| [[ "${BASH_VERSINFO[0]}" -eq 3 && "${BASH_VERSINFO[1]}" -lt 2 ]]; then
echo "bash v3.2+ is required. Sorry."
exit 1
fi
this="${BASH_SOURCE-$0}"
BINDIR=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
STARTINGDIR=$(pwd)
USER_PARAMS=("$@")
GLOBALTIMER=$(date +"%s")
#shellcheck disable=SC2034
QATESTMODE=false
# global arrays
declare -a TP_HEADER
declare -a TP_VOTE_TABLE
declare -a TP_TEST_TABLE
declare -a TP_FOOTER_TABLE
declare -a MODULE_STATUS
declare -a MODULE_STATUS_TIMER
declare -a MODULE_STATUS_MSG
declare -a MODULE_STATUS_LOG
declare -a MODULE_COMPILE_LOG
declare -a MODULE
TP_HEADER_COUNTER=0
TP_VOTE_COUNTER=0
TP_TEST_COUNTER=0
TP_FOOTER_COUNTER=0
## @description Setup the default global variables
## @audience public
## @stability stable
## @replaceable no
function setup_defaults
{
declare version="in-progress"
common_defaults
if [[ -f "${BINDIR}/../VERSION" ]]; then
version=$(cat "${BINDIR}/../VERSION")
elif [[ -f "${BINDIR}/VERSION" ]]; then
version=$(cat "${BINDIR}/VERSION")
fi
if [[ ${version} =~ SNAPSHOT$ ]]; then
version="in-progress"
fi
PATCH_NAMING_RULE="https://yetus.apache.org/documentation/${version}/precommit-patchnames"
INSTANCE=${RANDOM}
RELOCATE_PATCH_DIR=false
ALLOWSUMMARIES=true
DOCKERMODE=false
DOCKERSUPPORT=false
DOCKER_ENABLE_PRIVILEGED=true
BUILD_NATIVE=${BUILD_NATIVE:-true}
BUILDTOOLCWD=true
# shellcheck disable=SC2034
CHANGED_MODULES=""
# shellcheck disable=SC2034
CHANGED_UNION_MODULES=""
USER_MODULE_LIST=""
CHANGED_FILES=""
REEXECED=false
RESETREPO=false
ISSUE=""
TIMER=$(date +"%s")
BUILDTOOL=maven
JDK_TEST_LIST="compile javadoc unit"
}
## @description Convert the given module name to a file fragment
## @audience public
## @stability stable
## @replaceable no
## @param module
function module_file_fragment
{
local mod=$1
if [[ ${mod} == . ]]; then
echo root
else
echo "$1" | tr '/' '_' | tr '\\' '_'
fi
}
## @description Convert time in seconds to m + s
## @audience public
## @stability stable
## @replaceable no
## @param seconds
function clock_display
{
local -r elapsed=$1
if [[ ${elapsed} -lt 0 ]]; then
echo "N/A"
else
printf "%3sm %02ss" $((elapsed/60)) $((elapsed%60))
fi
}
## @description Activate the local timer
## @audience public
## @stability stable
## @replaceable no
function start_clock
{
yetus_debug "Start clock"
TIMER=$(date +"%s")
}
## @description Print the elapsed time in seconds since the start of the local timer
## @audience public
## @stability stable
## @replaceable no
function stop_clock
{
local -r stoptime=$(date +"%s")
local -r elapsed=$((stoptime-TIMER))
yetus_debug "Stop clock"
echo ${elapsed}
}
## @description Print the elapsed time in seconds since the start of the global timer
## @audience private
## @stability stable
## @replaceable no
function stop_global_clock
{
local -r stoptime=$(date +"%s")
local -r elapsed=$((stoptime-GLOBALTIMER))
yetus_debug "Stop global clock"
echo ${elapsed}
}
## @description Add time to the local timer
## @audience public
## @stability stable
## @replaceable no
## @param seconds
function offset_clock
{
declare off=$1
yetus_debug "offset clock by ${off}"
if [[ -n ${off} ]]; then
((TIMER=TIMER-off))
else
yetus_error "ASSERT: no offset passed to offset_clock: ${index}"
generate_stack
fi
}
## @description generate a stack trace when in debug mode
## @audience public
## @stability stable
## @replaceable no
## @return exits
function generate_stack
{
declare frame
if [[ "${YETUS_SHELL_SCRIPT_DEBUG}" = true ]]; then
while caller "${frame}"; do
((frame++));
done
fi
exit 1
}
## @description Add to the header of the display
## @audience public
## @stability stable
## @replaceable no
## @param string
function add_header_line
{
# shellcheck disable=SC2034
TP_HEADER[${TP_HEADER_COUNTER}]="$*"
((TP_HEADER_COUNTER=TP_HEADER_COUNTER+1 ))
}
## @description Add to the output table. If the first parameter is a number
## @description that is the vote for that column and calculates the elapsed time
## @description based upon the last start_clock(). If it the string null, then it is
## @description a special entry that signifies extra
## @description content for the final column. The second parameter is the reporting
## @description subsystem (or test) that is providing the vote. The second parameter
## @description is always required. The third parameter is any extra verbage that goes
## @description with that subsystem.
## @audience public
## @stability stable
## @replaceable no
## @param +1/0/-1/null
## @param subsystem
## @param string
## @return Elapsed time display
function add_vote_table
{
local value=$1
local subsystem=$2
shift 2
local calctime
local -r elapsed=$(stop_clock)
yetus_debug "add_vote_table ${value} ${subsystem} ${*}"
calctime=$(clock_display "${elapsed}")
if [[ ${value} == "1" ]]; then
value="+1"
fi
if [[ -z ${value} ]]; then
# shellcheck disable=SC2034
TP_VOTE_TABLE[${TP_VOTE_COUNTER}]="| | ${subsystem} | | ${*:-} |"
else
# shellcheck disable=SC2034
TP_VOTE_TABLE[${TP_VOTE_COUNTER}]="| ${value} | ${subsystem} | ${calctime} | $* |"
fi
((TP_VOTE_COUNTER=TP_VOTE_COUNTER+1))
}
## @description Report the JVM version of the given directory
## @stability stable
## @audience private
## @replaceable yes
## @param directory
## @return version
function report_jvm_version
{
#shellcheck disable=SC2016
"${1}/bin/java" -version 2>&1 | head -1 | ${AWK} '{print $NF}' | tr -d \"
}
## @description Verify if a given test is multijdk
## @audience public
## @stability stable
## @replaceable yes
## @param test
## @return 1 = yes
## @return 0 = no
function verify_multijdk_test
{
local i=$1
if [[ "${JDK_DIR_LIST}" == "${JAVA_HOME}" ]]; then
yetus_debug "MultiJDK not configured."
return 0
fi
if [[ ${JDK_TEST_LIST} =~ $i ]]; then
yetus_debug "${i} is in ${JDK_TEST_LIST} and MultiJDK configured."
return 1
fi
return 0
}
## @description Put the opening environment information at the bottom
## @description of the footer table
## @stability stable
## @audience private
## @replaceable yes
function prepopulate_footer
{
# shellcheck disable=SC2155
declare -r unamea=$(uname -a)
add_footer_table "uname" "${unamea}"
add_footer_table "Build tool" "${BUILDTOOL}"
if [[ -n ${REEXECPERSONALITY} ]]; then
add_footer_table "Personality" "${REEXECPERSONALITY}"
elif [[ -n ${PERSONALITY} ]]; then
add_footer_table "Personality" "${PERSONALITY}"
fi
gitrev=$(${GIT} rev-parse --verify --short HEAD)
add_footer_table "git revision" "${PATCH_BRANCH} / ${gitrev}"
}
## @description Put the max memory consumed by maven at the bottom of the table.
## @audience private
## @stability stable
## @replaceable no
function finish_footer_table
{
local maxmem
add_footer_table "modules" "C: ${CHANGED_MODULES} U: ${CHANGED_UNION_MODULES}"
# `sort | head` can cause a broken pipe error, but we can ignore it just like compute_gitdiff.
# shellcheck disable=SC2016,SC2086
maxmem=$(find "${PATCH_DIR}" -type f -exec ${AWK} 'match($0, /^\[INFO\] Final Memory: [0-9]+/)
{ print substr($0, 22, RLENGTH-21) }' {} \; | sort -nr 2>/dev/null | head -n 1)
if [[ -n ${maxmem} ]]; then
add_footer_table "Max memory used" "${maxmem}MB"
fi
}
## @description Put the final elapsed time at the bottom of the table.
## @audience private
## @stability stable
## @replaceable no
function finish_vote_table
{
local -r elapsed=$(stop_global_clock)
local calctime
calctime=$(clock_display "${elapsed}")
echo ""
echo "Total Elapsed time: ${calctime}"
echo ""
# shellcheck disable=SC2034
TP_VOTE_TABLE[${TP_VOTE_COUNTER}]="| | | ${calctime} | |"
((TP_VOTE_COUNTER=TP_VOTE_COUNTER+1 ))
}
## @description Add to the footer of the display. @@BASE@@ will get replaced with the
## @description correct location for the local filesystem in dev mode or the URL for
## @description Jenkins mode.
## @audience public
## @stability stable
## @replaceable no
## @param subsystem
## @param string
function add_footer_table
{
local subsystem=$1
shift 1
# shellcheck disable=SC2034
TP_FOOTER_TABLE[${TP_FOOTER_COUNTER}]="| ${subsystem} | $* |"
((TP_FOOTER_COUNTER=TP_FOOTER_COUNTER+1 ))
}
## @description Special table just for unit test failures
## @audience public
## @stability stable
## @replaceable no
## @param failurereason
## @param testlist
function add_test_table
{
local failure=$1
shift 1
# shellcheck disable=SC2034
TP_TEST_TABLE[${TP_TEST_COUNTER}]="| ${failure} | $* |"
((TP_TEST_COUNTER=TP_TEST_COUNTER+1 ))
}
## @description Large display for the user console
## @audience public
## @stability stable
## @replaceable no
## @param string
## @return large chunk of text
function big_console_header
{
local text="$*"
local spacing=$(( (75+${#text}) /2 ))
printf "\n\n"
echo "============================================================================"
echo "============================================================================"
printf "%*s\n" ${spacing} "${text}"
echo "============================================================================"
echo "============================================================================"
printf "\n\n"
}
## @description Find the largest size of a column of an array
## @audience private
## @stability evolving
## @replaceable no
## @return size
function findlargest
{
local column=$1
shift
local a=("$@")
local sizeofa=${#a[@]}
local i=0
local string
local maxlen=0
until [[ ${i} -eq ${sizeofa} ]]; do
# shellcheck disable=SC2086
string=$( echo ${a[$i]} | cut -f$((column + 1)) -d\| )
if [[ ${#string} -gt ${maxlen} ]]; then
maxlen=${#string}
fi
i=$((i+1))
done
echo "${maxlen}"
}
## @description Write the contents of a file to all of the bug systems
## @description (so content should avoid special formatting)
## @param filename
## @stability stable
## @audience public
function write_comment
{
local -r commentfile=${1}
declare bug
for bug in ${BUGCOMMENTS}; do
if declare -f ${bug}_write_comment >/dev/null; then
"${bug}_write_comment" "${commentfile}"
fi
done
}
## @description Verify that the patch directory is still in working order
## @description since bad actors on some systems wipe it out. If not,
## @description recreate it and then exit
## @audience private
## @stability evolving
## @replaceable yes
## @return may exit on failure
function verify_patchdir_still_exists
{
local -r commentfile=/tmp/testpatch.$$.${RANDOM}
local extra=""
if [[ ! -d ${PATCH_DIR} ]]; then
rm "${commentfile}" 2>/dev/null
echo "(!) The patch artifact directory has been removed! " > "${commentfile}"
echo "This is a fatal error for test-patch.sh. Aborting. " >> "${commentfile}"
echo
cat ${commentfile}
echo
if [[ ${JENKINS} == true ]]; then
if [[ -n ${NODE_NAME} ]]; then
extra=" (node ${NODE_NAME})"
fi
echo "Jenkins${extra} information at ${BUILD_URL} may provide some hints. " >> "${commentfile}"
write_comment ${commentfile}
fi
rm "${commentfile}"
cleanup_and_exit "${RESULT}"
fi
}
## @description generate a list of all files and line numbers in $GITDIFFLINES that
## @description that were added/changed in the source repo. $GITDIFFCONTENT
## @description is same file, but also includes the content of those lines
## @audience private
## @stability stable
## @replaceable no
function compute_gitdiff
{
local file
local line
local startline
local counter
local numlines
local actual
local content
local outfile="${PATCH_DIR}/computegitdiff.${RANDOM}"
pushd "${BASEDIR}" >/dev/null
${GIT} add --all --intent-to-add
while read -r line; do
if [[ ${line} =~ ^\+\+\+ ]]; then
file="./"$(echo "${line}" | cut -f2- -d/)
continue
elif [[ ${line} =~ ^@@ ]]; then
startline=$(echo "${line}" | cut -f3 -d' ' | cut -f1 -d, | tr -d + )
numlines=$(echo "${line}" | cut -f3 -d' ' | cut -s -f2 -d, )
# if this is empty, then just this line
# if it is 0, then no lines were added and this part of the patch
# is strictly a delete
if [[ ${numlines} == 0 ]]; then
continue
elif [[ -z ${numlines} ]]; then
numlines=1
fi
counter=0
# it isn't obvious, but on MOST platforms under MOST use cases,
# this is faster than using sed, and definitely faster than using
# awk.
# http://unix.stackexchange.com/questions/47407/cat-line-x-to-line-y-on-a-huge-file
# has a good discussion w/benchmarks
#
# note that if tail is still sending data through the pipe, but head gets enough
# to do what was requested, head will exit, leaving tail with a broken pipe.
# we're going to send stderr to /dev/null and ignore the error since head's
# output is really what we're looking for
tail -n "+${startline}" "${file}" 2>/dev/null | head -n ${numlines} > "${outfile}"
oldifs=${IFS}
IFS=''
while read -r content; do
((actual=counter+startline))
echo "${file}:${actual}:" >> "${GITDIFFLINES}"
printf "%s:%s:%s\n" "${file}" "${actual}" "${content}" >> "${GITDIFFCONTENT}"
((counter=counter+1))
done < "${outfile}"
rm "${outfile}"
IFS=${oldifs}
fi
done < <("${GIT}" diff --unified=0 --no-color)
if [[ ! -f "${GITDIFFLINES}" ]]; then
touch "${GITDIFFLINES}"
fi
if [[ ! -f "${GITDIFFCONTENT}" ]]; then
touch "${GITDIFFCONTENT}"
fi
if [[ -s "${GITDIFFLINES}" ]]; then
compute_unidiff
else
touch "${GITUNIDIFFLINES}"
fi
popd >/dev/null
}
## @description generate an index of unified diff lines vs. modified/added lines
## @description ${GITDIFFLINES} must exist.
## @audience private
## @stability stable
## @replaceable no
function compute_unidiff
{
declare fn
declare filen
declare tmpfile="${PATCH_DIR}/tmp.$$.${RANDOM}"
# now that we know what lines are where, we can deal
# with github's pain-in-the-butt API. It requires
# that the client provides the line number of the
# unified diff on a per file basis.
# First, build a per-file unified diff, pulling
# out the 'extra' lines, grabbing the adds with
# the line number in the diff file along the way,
# finally rewriting the line so that it is in
# './filename:diff line:content' format
for fn in ${CHANGED_FILES}; do
filen=${fn##./}
if [[ -f "${filen}" ]]; then
${GIT} diff ${filen} \
| tail -n +6 \
| ${GREP} -n '^+' \
| ${GREP} -vE '^[0-9]*:\+\+\+' \
| ${SED} -e 's,^\([0-9]*:\)\+,\1,g' \
-e s,^,./${filen}:,g \
>> "${tmpfile}"
fi
done
# at this point, tmpfile should be in the same format
# as gitdiffcontent, just with different line numbers.
# let's do a merge (using gitdifflines because it's easier)
# ./filename:real number:diff number
# shellcheck disable=SC2016
paste -d: "${GITDIFFLINES}" "${tmpfile}" \
| ${AWK} -F: '{print $1":"$2":"$5":"$6}' \
>> "${GITUNIDIFFLINES}"
rm "${tmpfile}"
}
## @description Print the command to be executing to the screen. Then
## @description run the command, sending stdout and stderr to the given filename
## @description This will also ensure that any directories in ${BASEDIR} have
## @description the exec bit set as a pre-exec step.
## @audience public
## @stability stable
## @param filename
## @param command
## @param [..]
## @replaceable no
## @return $?
function echo_and_redirect
{
local logfile=$1
shift
verify_patchdir_still_exists
find "${BASEDIR}" -type d -exec chmod +x {} \;
# to the screen
echo "cd $(pwd)"
echo "${*} > ${logfile} 2>&1"
yetus_run_and_redirect "${logfile}" "${@}"
}
## @description is a given directory relative to BASEDIR?
## @audience public
## @stability stable
## @replaceable yes
## @param path
## @return 1 - no, path
## @return 0 - yes, path - BASEDIR
function relative_dir
{
local p=${1#${BASEDIR}}
if [[ ${#p} -eq ${#1} ]]; then
echo "${p}"
return 1
fi
p=${p#/}
echo "${p}"
return 0
}
## @description Print the usage information
## @audience public
## @stability stable
## @replaceable no
function yetus_usage
{
declare bugsys
importplugins
bugsys=$(echo ${BUGSYSTEMS})
bugsys=${bugsys// /,}
echo "test-patch.sh [OPTIONS] patch"
echo ""
echo "Where:"
echo " patch is a file, URL, or bugsystem-compatible location of the patch file"
echo ""
echo "Options:"
echo ""
yetus_add_option "--basedir=<dir>" "The directory to apply the patch to (default current directory)"
yetus_add_option "--branch=<ref>" "Forcibly set the branch"
yetus_add_option "--branch-default=<ref>" "If the branch isn't forced and we don't detect one in the patch name, use this branch (default 'master')"
yetus_add_option "--build-native=<bool>" "If true, then build native components (default 'true')"
# shellcheck disable=SC2153
yetus_add_option "--build-tool=<tool>" "Pick which build tool to focus around (one of ${BUILDTOOLS})"
yetus_add_option "--bugcomments=<bug>" "Only write comments to the screen and this comma delimited list (default: ${bugsys})"
yetus_add_option "--contrib-guide=<url>" "URL to point new users towards project conventions. (default: ${PATCH_NAMING_RULE} )"
yetus_add_option "--debug" "If set, then output some extra stuff to stderr"
yetus_add_option "--dirty-workspace" "Allow the local git workspace to have uncommitted changes"
yetus_add_option "--docker" "Spawn a docker container"
yetus_add_option "--dockercmd=<file>" "Command to use as docker executable (default: docker from path)"
yetus_add_option "--dockerfile=<file>" "Dockerfile fragment to use as the base"
yetus_add_option "--dockeronfail=<list>" "If Docker fails, determine fallback method order (default: ${DOCKERFAIL})"
yetus_add_option "--dockerprivd=<bool>" "Run docker in privileged mode (default: '${DOCKER_ENABLE_PRIVILEGED}')"
yetus_add_option "--java-home=<path>" "Set JAVA_HOME (In Docker mode, this should be local to the image)"
yetus_add_option "--linecomments=<bug>" "Only write line comments to this comma delimited list (defaults to bugcomments)"
yetus_add_option "--list-plugins" "List all installed plug-ins and then exit"
yetus_add_option "--multijdkdirs=<paths>" "Comma delimited lists of JDK paths to use for multi-JDK tests"
yetus_add_option "--multijdktests=<list>" "Comma delimited tests to use when multijdkdirs is used. (default: javac,javadoc,unit)"
yetus_add_option "--modulelist=<list>" "Specify additional modules to test (comma delimited)"
yetus_add_option "--offline" "Avoid connecting to the Internet"
yetus_add_option "--patch-dir=<dir>" "The directory for working and output files (default '/tmp/test-patch-${PROJECT_NAME}/pid')"
yetus_add_option "--personality=<file>" "The personality file to load"
yetus_add_option "--project=<name>" "The short name for project currently using test-patch (default 'yetus')"
yetus_add_option "--plugins=<list>" "Specify which plug-ins to add/delete (comma delimited; use 'all' for all found) e.g. --plugins=all,-ant,-scalac (all plugins except ant and scalac)"
yetus_add_option "--resetrepo" "Forcibly clean the repo"
yetus_add_option "--run-tests" "Run all relevant tests below the base directory"
yetus_add_option "--skip-dirs=<list>" "Skip following directories for module finding"
yetus_add_option "--skip-system-plugins" "Do not load plugins from ${BINDIR}/test-patch.d"
yetus_add_option "--summarize=<bool>" "Allow tests to summarize results"
yetus_add_option "--test-parallel=<bool>" "Run multiple tests in parallel (default false in developer mode, true in Jenkins mode)"
yetus_add_option "--test-threads=<int>" "Number of tests to run in parallel (default defined in ${PROJECT_NAME} build)"
yetus_add_option "--user-plugins=<dir>" "A directory of user provided plugins. see test-patch.d for examples (default empty)"
yetus_add_option "--version" "Print release version information and exit"
yetus_generic_columnprinter "${YETUS_OPTION_USAGE[@]}"
yetus_reset_usage
echo ""
echo "Shell binary overrides:"
yetus_add_option "--awk-cmd=<cmd>" "The 'awk' command to use (default 'awk')"
yetus_add_option "--curl-cmd=<cmd>" "The 'curl' command to use (default 'curl')"
yetus_add_option "--diff-cmd=<cmd>" "The GNU-compatible 'diff' command to use (default 'diff')"
yetus_add_option "--file-cmd=<cmd>" "The 'file' command to use (default 'file')"
yetus_add_option "--git-cmd=<cmd>" "The 'git' command to use (default 'git')"
yetus_add_option "--grep-cmd=<cmd>" "The 'grep' command to use (default 'grep')"
yetus_add_option "--patch-cmd=<cmd>" "The 'patch' command to use (default 'patch')"
yetus_add_option "--sed-cmd=<cmd>" "The 'sed' command to use (default 'sed')"
yetus_generic_columnprinter "${YETUS_OPTION_USAGE[@]}"
yetus_reset_usage
echo ""
echo "Jenkins-only options:"
yetus_add_option "--jenkins" "Jenkins mode"
yetus_add_option "--build-url" "Set the build location web page"
yetus_add_option "--mv-patch-dir" "Move the patch-dir into the basedir during cleanup."
yetus_generic_columnprinter "${YETUS_OPTION_USAGE[@]}"
yetus_reset_usage
for plugin in ${BUILDTOOLS} ${TESTTYPES} ${BUGSYSTEMS} ${TESTFORMATS}; do
if declare -f ${plugin}_usage >/dev/null 2>&1; then
echo ""
echo "'${plugin}' plugin usage options:"
"${plugin}_usage"
yetus_generic_columnprinter "${YETUS_OPTION_USAGE[@]}"
yetus_reset_usage
fi
done
}
## @description Interpret the command line parameters
## @audience private
## @stability stable
## @replaceable no
## @param $@
## @return May exit on failure
function parse_args
{
local i
local j
common_args "$@"
for i in "$@"; do
case ${i} in
--bugcomments=*)
BUGCOMMENTS=${i#*=}
BUGCOMMENTS=${BUGCOMMENTS//,/ }
;;
--build-native=*)
BUILD_NATIVE=${i#*=}
;;
--build-tool=*)
BUILDTOOL=${i#*=}
;;
--build-url=*)
BUILD_URL=${i#*=}
;;
--contrib-guide=*)
PATCH_NAMING_RULE=${i#*=}
;;
--dirty-workspace)
DIRTY_WORKSPACE=true
;;
--docker)
DOCKERSUPPORT=true
;;
--dockercmd=*)
#shellcheck disable=SC2034
DOCKERCMD=${i#*=}
;;
--dockerfile=*)
DOCKERFILE=${i#*=}
;;
--dockermode)
DOCKERMODE=true
;;
--dockeronfail=*)
DOCKERFAIL=${i#*=}
;;
--dockerprivd=*)
DOCKER_ENABLE_PRIVILEGED=${i#*=}
;;
--java-home=*)
JAVA_HOME=${i#*=}
;;
--jenkins)
JENKINS=true
TEST_PARALLEL=${TEST_PARALLEL:-true}
INSTANCE=${EXECUTOR_NUMBER:-RANDOM}
;;
--linecomments=*)
BUGLINECOMMENTS=${i#*=}
BUGLINECOMMENTS=${BUGLINECOMMENTS//,/ }
;;
--modulelist=*)
USER_MODULE_LIST=${i#*=}
USER_MODULE_LIST=${USER_MODULE_LIST//,/ }
yetus_debug "Manually forcing modules ${USER_MODULE_LIST}"
;;
--multijdkdirs=*)
JDK_DIR_LIST=${i#*=}
JDK_DIR_LIST=${JDK_DIR_LIST//,/ }
yetus_debug "Multi-JVM mode activated with ${JDK_DIR_LIST}"
;;
--multijdktests=*)
JDK_TEST_LIST=${i#*=}
JDK_TEST_LIST=${JDK_TEST_LIST//,/ }
yetus_debug "Multi-JVM test list: ${JDK_TEST_LIST}"
;;
--mv-patch-dir)
RELOCATE_PATCH_DIR=true;
;;
--personality=*)
PERSONALITY=${i#*=}
;;
--reexec)
REEXECED=true
;;
--resetrepo)
RESETREPO=true
;;
--run-tests)
RUN_TESTS=true
;;
--skip-dirs=*)
MODULE_SKIPDIRS=${i#*=}
MODULE_SKIPDIRS=${MODULE_SKIPDIRS//,/ }
yetus_debug "Setting skipdirs to ${MODULE_SKIPDIRS}"
;;
--summarize=*)
ALLOWSUMMARIES=${i#*=}
;;
--test-parallel=*)
TEST_PARALLEL=${i#*=}
;;
--test-threads=*)
# shellcheck disable=SC2034
TEST_THREADS=${i#*=}
;;
--tpglobaltimer=*)
GLOBALTIMER=${i#*=}
;;
--tpinstance=*)
INSTANCE=${i#*=}
EXECUTOR_NUMBER=${INSTANCE}
;;
--tpperson=*)
REEXECPERSONALITY=${i#*=}
;;
--tpreexectimer=*)
REEXECLAUNCHTIMER=${i#*=}
;;
--*)
## PATCH_OR_ISSUE can't be a --. So this is probably
## a plugin thing.
continue
;;
*)
PATCH_OR_ISSUE=${i}
;;
esac
done
if [[ "${DOCKERMODE}" = true ]]; then
add_vote_table 0 reexec "Docker mode activated."
elif [[ "${REEXECED}" = true ]]; then
add_vote_table 0 reexec "Precommit patch detected."
fi
if [[ -n ${REEXECLAUNCHTIMER} ]]; then
TIMER=${REEXECLAUNCHTIMER};
else
start_clock
fi
if [[ -z "${PATCH_OR_ISSUE}" ]]; then
yetus_usage
exit 1
fi
# we need absolute dir for ${BASEDIR}
cd "${STARTINGDIR}"
BASEDIR=$(yetus_abs "${BASEDIR}")
if [[ -n ${USER_PATCH_DIR} ]]; then
PATCH_DIR="${USER_PATCH_DIR}"
fi
cd "${STARTINGDIR}"
if [[ ! -d ${PATCH_DIR} ]]; then
mkdir -p "${PATCH_DIR}"
if [[ $? == 0 ]] ; then
echo "${PATCH_DIR} has been created"
else
echo "Unable to create ${PATCH_DIR}"
cleanup_and_exit 1
fi
fi
# we need absolute dir for PATCH_DIR
PATCH_DIR=$(yetus_abs "${PATCH_DIR}")
if [[ ${JENKINS} == "true" ]]; then
echo "Running in Jenkins mode"
ISSUE=${PATCH_OR_ISSUE}
RESETREPO=true
else
if [[ ${RESETREPO} == "true" ]] ; then
echo "Running in destructive (--resetrepo) developer mode"
else
echo "Running in developer mode"
fi
JENKINS=false
fi
if [[ -n "${USER_PLUGIN_DIR}" ]]; then
USER_PLUGIN_DIR=$(yetus_abs "${USER_PLUGIN_DIR}")
fi
GITDIFFLINES="${PATCH_DIR}/gitdifflines.txt"
GITDIFFCONTENT="${PATCH_DIR}/gitdiffcontent.txt"
GITUNIDIFFLINES="${PATCH_DIR}/gitdiffunilines.txt"
if [[ "${REEXECED}" = true
&& -f "${PATCH_DIR}/precommit/personality/provided.sh" ]]; then
REEXECPERSONALITY="${PERSONALITY}"
PERSONALITY="${PATCH_DIR}/precommit/personality/provided.sh"
fi
}
## @description Locate the build file for a given directory
## @audience private
## @stability stable
## @replaceable no
## @return directory containing the buildfile. Nothing returned if not found.
## @param buildfile
## @param directory
function find_buildfile_dir
{
local buildfile=$1
local dir=$2
yetus_debug "Find ${buildfile} dir for: ${dir}"
while builtin true; do
if [[ -f "${dir}/${buildfile}" ]];then
echo "${dir}"
yetus_debug "Found: ${dir}"
return 0
elif [[ ${dir} == "." || ${dir} == "/" ]]; then
yetus_debug "ERROR: ${buildfile} is not found."
return 1
else
dir=$(dirname "${dir}")
fi
done
}
## @description List of files that ${PATCH_DIR}/patch modifies
## @audience private
## @stability stable
## @replaceable no
## @return None; sets ${CHANGED_FILES}
function find_changed_files
{
# get a list of all of the files that have been changed,
# except for /dev/null (which would be present for new files).
# Additionally, remove any a/ b/ patterns at the front of the patch filenames.
# shellcheck disable=SC2016
CHANGED_FILES=$(${AWK} 'function p(s){sub("^[ab]/","",s); if(s!~"^/dev/null"){print s}}
/^diff --git / { p($3); p($4) }
/^(\+\+\+|---) / { p($2) }' "${PATCH_DIR}/patch" | sort -u)
}
## @description Check for directories to skip during
## @description changed module calcuation
## @audience private
## @stability stable
## @replaceable no
## @param directory
## @return 0 for use