forked from AdoptOpenJDK/IcedTea-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bisect-script.sh
146 lines (123 loc) · 3.87 KB
/
bisect-script.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
#!/bin/sh
#set -x
set -e
#script only for master branch currently as none other uses maven
JNLPFILE=$1
## resolve folder of this script, following all symlinks,
## http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
SCRIPT_SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SCRIPT_SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" && pwd )"
SCRIPT_SOURCE="$(readlink "$SCRIPT_SOURCE")"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $SCRIPT_SOURCE != /* ]] && SCRIPT_SOURCE="$SCRIPT_DIR/$SCRIPT_SOURCE"
done
readonly SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" && pwd )"
set +e
#cat ~/.config/icedtea-web/deployment.properties
set -e
LOGFILEPATH="/dev/null"
function join_by { local IFS="$1"; shift; echo "$*"; }
function testonecommit () {
COMMIT=$1
JNLPFILE=$2
cd "$SCRIPT_DIR"
git checkout $COMMIT &>$LOGFILEPATH
mvn clean install -DskipTests 1>$LOGFILEPATH
clearCache
JARS=$(join_by ":" `find $PWD | grep "\.jar$"` $TAGSOUP $SLF4J) 1>$LOGFILEPATH
#runWithTimeout "echo 'YES
#YES
#YES
#YES
#YES
#YES' | java -Xbootclasspath/a:$JARS net.sourceforge.jnlp.runtime.Boot $JNLPFILE -Xnofork -headless"
echo "YES 1>$LOGFILEPATH
YES
YES
YES
YES
YES
YES" | java -Xbootclasspath/a:$JARS net.sourceforge.jnlp.runtime.Boot $JNLPFILE -Xnofork -headless
RES=$?
clearCache
mvn clean 1>$LOGFILEPATH
return $RES
}
function hashToNumber () {
HASH=$1
NUMBER=`cd "$SCRIPT_DIR" && git checkout master &>$LOGFILEPATH ; git rev-list HEAD | grep -n $HASH | cut -d : -f 1`
echo "$NUMBER"
}
function numberToHash () {
NUMBER=$1
HASH=`cd "$SCRIPT_DIR" && git checkout master &>$LOGFILEPATH && git rev-list HEAD | head -n $NUMBER | tail -n 1`
echo "$HASH"
}
function clearCache () {
#java -Xbootclasspath/a:$JARS net.sourceforge.jnlp.runtime.Boot -Xnofork -XclearCache
rm -rf ~/.cache/icedtea-web/*
}
# https://stackoverflow.com/questions/687948/timeout-a-command-in-bash-without-unnecessary-delay
# WIP - killing process as soon as it starts, not working currently
function runWithTimeout () {
COMMAND=$1
if [ -z $2 ]; then
TIMEOUT=30
else
TIMEOUT=$2
fi
( eval "$COMMAND" ) 2>/dev/null & pid=$!
( sleep $TIMEOUT && kill -SIGKILL $pid ) 2>/dev/null & watcher=$!
RES=`wait $pid`
if wait $pid 2>/dev/null; then
RES=0
pkill -HUP -P $watcher
wait $watcher
else
RES=1
fi
return $RES
}
HIGHERHASH=$(numberToHash 1)
LOWERHASH="d8ca907c1b98fabc1d2129046ae704ec0d6416e6"
if [[ -z "$TAGSOUP" || ! -f "$TAGSOUP" ]]
then
TAGSOUP=`find ~/.m2 /usr/share / 2>$LOGFILEPATH | grep -v "javadoc" | grep "tagsoup" | grep "\.jar$" | head -n 4`
fi
# slf4j-api and slf4j-simple jars are required for some past commits and not provided via mvn install
if [[ -z "$SLF4J" || ! -f "$SLF4J" ]]
then
SLF4J="$(find /usr/share ~/.m2 / -type f 2>$LOGFILEPATH | grep -v "javadoc" | grep "slf4j-simple" | grep "\.jar$" | head -n 4 ) $(find /usr/share ~/.m2 / -type f 2>$LOGFILEPATH | grep -v "javadoc" | grep "slf4j-api" | grep "\.jar$" | head -n 4 )"
fi
# translating hashes to numbers
LOWER=$(hashToNumber $LOWERHASH)
HIGHER=$(hashToNumber $HIGHERHASH)
# switch if in wrong order - probably not necessary anymore
if [ $HIGHER -ge $LOWER ]
then
TMP=$HIGHER
HIGHER=$LOWER
LOWER=$TMP
fi
function main () {
while [ $(($LOWER - $HIGHER)) -gt 1 ]
do
MID=$(( ($HIGHER+$LOWER)/2 ))
CURRENT=$(numberToHash $MID)
set +e
testonecommit $CURRENT $JNLPFILE &>$LOGFILEPATH
RES=$?
set -e
if [ $RES -eq 0 ] ; then
LOWER=$MID
echo "its closer than $MID"
else
HIGHER=$MID
echo "its farther than $MID"
fi
done
CURRENT=`cd "$SCRIPT_DIR" && git rev-list HEAD | head -n 1`
echo "[DONE]: sought commit should be - $HIGHER with hash: $CURRENT"
}
main