|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +PROJ=$1 |
| 4 | +SLEEP_BETWEEN=$3 |
| 5 | +CACHE="$HOME/.cache/sway-bench" |
| 6 | + |
| 7 | +NC='\033[0m' |
| 8 | +BOLD_GREEN="\033[1;32m" |
| 9 | +BOLD_RED='\033[1;31m' |
| 10 | +BOLD_WHITE='\033[1;97m' |
| 11 | + |
| 12 | +# $1 = commit hash |
| 13 | +compile_and_cp_to_cache() { |
| 14 | + if [ ! -f "$CACHE/$1" ]; then |
| 15 | + if [[ -n $SLEEP_BETWEEN ]]; then |
| 16 | + sleep "$SLEEP_BETWEEN" |
| 17 | + fi |
| 18 | + cargo b --release &>> /dev/null |
| 19 | + cp target/release/forc "$CACHE/$1" &>> /dev/null |
| 20 | + fi |
| 21 | +} |
| 22 | + |
| 23 | +run_cargo() { |
| 24 | + if [ "$2" = "" ]; then |
| 25 | + bash -c "$CACHE/$CACHENAME build --path $PROJ" &>> /dev/null |
| 26 | + echo "$?" |
| 27 | + else |
| 28 | + bash -c "$CACHE/$CACHENAME $2 --path $PROJ" &>> /dev/null |
| 29 | + echo "$?" |
| 30 | + fi |
| 31 | +} |
| 32 | + |
| 33 | +INITIAL_COMMIT="$(git show -s --format='%H' HEAD)" |
| 34 | +END_COMMIT="" |
| 35 | + |
| 36 | +echo "Forc command will be:" |
| 37 | +if [ "$2" = "" ]; then |
| 38 | + echo "> forc build --path $PROJ" |
| 39 | +else |
| 40 | + echo "> forc $2 --path $PROJ" |
| 41 | +fi |
| 42 | + |
| 43 | +echo "Starting the search at: " |
| 44 | +echo -n " " |
| 45 | +git log -1 --oneline |
| 46 | + |
| 47 | +echo -n "Running: " |
| 48 | + |
| 49 | +CACHENAME="$(git show -s --format='%as-%ct-%H' HEAD)" |
| 50 | +compile_and_cp_to_cache "$CACHENAME" |
| 51 | +INITIAL_COMPILATION_STATUS=$(run_cargo) |
| 52 | + |
| 53 | +if [ "$INITIAL_COMPILATION_STATUS" = "0" ]; then |
| 54 | + echo -e " ${BOLD_GREEN}Ok${NC}" |
| 55 | + echo "" |
| 56 | + echo "Searching the newest version which compilation was failing." |
| 57 | +else |
| 58 | + echo -e " ${BOLD_RED}Failed${NC}" |
| 59 | + echo "" |
| 60 | + echo "Searching the newest version which compilation was succeeding." |
| 61 | +fi |
| 62 | + |
| 63 | + |
| 64 | +for HASH in `git log --format="%H" --tags --no-walk`; do |
| 65 | + git checkout "$HASH" &>> /dev/null |
| 66 | + git checkout . &>> /dev/null |
| 67 | + |
| 68 | + git log -1 --oneline |
| 69 | + |
| 70 | + CACHENAME="$(git show -s --format='%as-%ct-%H' HEAD)" |
| 71 | + compile_and_cp_to_cache "$CACHENAME" |
| 72 | + LAST_STATUS=$(run_cargo) |
| 73 | + if [ "$INITIAL_COMPILATION_STATUS" != "$LAST_STATUS" ]; then |
| 74 | + echo -e "^^^^^^^^^ ${BOLD_WHITE}This version result is different!${NC}" |
| 75 | + break |
| 76 | + fi |
| 77 | +done |
| 78 | + |
| 79 | +END_COMMIT="$(git show -s --format='%H' HEAD)" |
| 80 | + |
| 81 | +echo "" |
| 82 | +echo -e "${BOLD_WHITE}Starting bisect between: ${NC}$INITIAL_COMMIT..$END_COMMIT" |
| 83 | + |
| 84 | +git checkout $INITIAL_COMMIT &>> /dev/null |
| 85 | + |
| 86 | +git bisect start &>> /dev/null |
| 87 | +git bisect new $INITIAL_COMMIT &>> /dev/null |
| 88 | +git bisect old $END_COMMIT &>> /dev/null |
| 89 | + |
| 90 | +while : |
| 91 | +do |
| 92 | + #echo "-----------------------" |
| 93 | + #git --no-pager bisect visualize --oneline |
| 94 | + |
| 95 | + git bisect next | grep "is the first new commit" &>> /dev/null |
| 96 | + if [ "$LAST_STATUS" = "0" ]; then |
| 97 | + FIRST_COMMIT="$(git bisect next 2>&1 | head -n 1 | cut -f1 -d" ")" |
| 98 | + git checkout "$FIRST_COMMIT" &>> /dev/null |
| 99 | + break |
| 100 | + fi |
| 101 | + |
| 102 | + git bisect next | grep "Bisecting" |
| 103 | + if [ "$LAST_STATUS" != "0" ]; then |
| 104 | + break |
| 105 | + fi |
| 106 | + |
| 107 | + git checkout . &>> /dev/null |
| 108 | + |
| 109 | + CACHENAME="$(git show -s --format='%as-%ct-%H' HEAD)" |
| 110 | + compile_and_cp_to_cache "$CACHENAME" |
| 111 | + LAST_STATUS=$(run_cargo) |
| 112 | + if [ "$LAST_STATUS" = "$INITIAL_COMPILATION_STATUS" ]; then |
| 113 | + git bisect new &>> /dev/null |
| 114 | + else |
| 115 | + git bisect old &>> /dev/null |
| 116 | + fi |
| 117 | +done |
| 118 | + |
| 119 | +FOUND_COMMIT="$(git show -s --format='%H' HEAD)" |
| 120 | + |
| 121 | +echo -e "${BOLD_GREEN}Found!${NC} - ${FOUND_COMMIT}" |
| 122 | +echo "" |
| 123 | + |
| 124 | + |
| 125 | +# check this commit has the same behaviour |
| 126 | +echo -n "checking the found commit has the same behaviour as the initial commit..." |
| 127 | + |
| 128 | +CACHENAME="$(git show -s --format='%as-%ct-%H' HEAD)" |
| 129 | +compile_and_cp_to_cache "$CACHENAME" |
| 130 | +LAST_STATUS=$(run_cargo) |
| 131 | + |
| 132 | +if [ "$INITIAL_COMPILATION_STATUS" != "$LAST_STATUS" ]; then |
| 133 | + echo -e " ${BOLD_RED}Unexpected exit code${NC}" |
| 134 | + exit 1 |
| 135 | +fi |
| 136 | + |
| 137 | +echo -e " ${BOLD_GREEN}Ok${NC}" |
| 138 | + |
| 139 | +## check the previous commit has the inverse |
| 140 | +echo -n "checking the previous commit has the inverse behaviour as the initial commit..." |
| 141 | + |
| 142 | +git checkout HEAD~1 &>> /dev/null |
| 143 | +PREVIOUS_COMMIT="$(git show -s --format='%H' HEAD)" |
| 144 | +CACHENAME="$(git show -s --format='%as-%ct-%H' HEAD)" |
| 145 | +compile_and_cp_to_cache "$CACHENAME" |
| 146 | +LAST_STATUS=$(run_cargo) |
| 147 | + |
| 148 | +if [ "$INITIAL_COMPILATION_STATUS" = "$LAST_STATUS" ]; then |
| 149 | + echo -e " ${BOLD_RED}Unexpected exit code${NC}" |
| 150 | + exit 1 |
| 151 | +fi |
| 152 | + |
| 153 | +echo -e " ${BOLD_GREEN}Ok${NC}" |
| 154 | + |
| 155 | +echo "" |
| 156 | + |
| 157 | +git checkout . &>> /dev/null |
| 158 | +git bisect reset &>> /dev/null |
| 159 | + |
| 160 | +git checkout "$FOUND_COMMIT" &>> /dev/null |
| 161 | +echo "This is the commit that changed the compiler behavior" |
| 162 | +git log -1 --oneline |
0 commit comments