2023-09-06 19:02:27 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Bisect parsing a file at various line cut-off points to see which line causes the parse to differ from emacs.
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
|
|
|
|
|
|
|
############## Setup #########################
|
|
|
|
|
|
|
|
function die {
|
|
|
|
local status_code="$1"
|
|
|
|
shift
|
|
|
|
(>&2 echo "${@}")
|
|
|
|
exit "$status_code"
|
|
|
|
}
|
|
|
|
|
|
|
|
function log {
|
|
|
|
(>&2 echo "${@}")
|
|
|
|
}
|
|
|
|
|
|
|
|
############## Program #########################
|
|
|
|
|
|
|
|
function main {
|
2023-09-16 17:34:33 +00:00
|
|
|
local target_full_path
|
|
|
|
target_full_path=$($REALPATH "$1")
|
2023-09-06 19:02:27 +00:00
|
|
|
SOURCE_FOLDER=$(dirname "$target_full_path")
|
|
|
|
TARGET_DOCUMENT=$(basename "$target_full_path")
|
|
|
|
|
|
|
|
|
|
|
|
local good=0
|
2023-09-16 17:34:33 +00:00
|
|
|
local bad
|
|
|
|
bad=$(wc -l "$SOURCE_FOLDER/$TARGET_DOCUMENT" | awk '{print $1}')
|
2023-09-06 19:02:27 +00:00
|
|
|
|
|
|
|
set +e
|
2023-09-16 17:34:33 +00:00
|
|
|
(run_parse "$bad")
|
2023-09-06 19:02:27 +00:00
|
|
|
local status=$?
|
|
|
|
set -e
|
|
|
|
if [ $status -eq 0 ]; then
|
|
|
|
log "Entire file passes."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [[ "$((bad - good))" -gt 1 ]]; do
|
|
|
|
local next_line=$((((bad - good) / 2) + good))
|
|
|
|
log "Testing line $next_line"
|
|
|
|
set +e
|
|
|
|
run_parse "$next_line" &> /dev/null
|
|
|
|
local status=$?
|
|
|
|
set -e
|
|
|
|
if [ $status -eq 0 ]; then
|
|
|
|
good="$next_line"
|
|
|
|
log "Line $next_line good"
|
|
|
|
else
|
|
|
|
bad="$next_line"
|
|
|
|
log "Line $next_line bad"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Bad line: $bad"
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_parse {
|
|
|
|
local lines="$1"
|
2023-09-16 17:34:33 +00:00
|
|
|
|
|
|
|
cd "$SOURCE_FOLDER"
|
2023-09-20 03:57:40 +00:00
|
|
|
head -n "$lines" "$SOURCE_FOLDER/$TARGET_DOCUMENT" | PROFILE=release-lto "${DIR}/run_docker_compare.bash"
|
2023-09-06 19:02:27 +00:00
|
|
|
local status=$?
|
|
|
|
return "$status"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "${@}"
|