Switch to logger function and fix exit codes

This commit is contained in:
Jordan Carlin 2024-07-23 22:56:07 -07:00
parent 4c0265f67d
commit 07ac498623

View File

@ -45,6 +45,7 @@ WARNING_COLOR='\033[93m'
FAIL_COLOR='\033[91m' FAIL_COLOR='\033[91m'
ENDC='\033[0m' # Reset to default color ENDC='\033[0m' # Reset to default color
## Helper functions
# Error handler # Error handler
error() { error() {
echo -e "${FAIL_COLOR}Error: $STATUS installation failed" echo -e "${FAIL_COLOR}Error: $STATUS installation failed"
@ -66,6 +67,12 @@ git_check() {
fi fi
} }
# Log output to a file and only print lines with keywords
logger() {
local log="$RISCV/logs/$1.log"
cat < /dev/stdin | tee -a "$log" | (grep -iE --color=never "(\bwarning|\berror|\bfail|\bsuccess|\bstamp)" || true)
}
set -e # break on error set -e # break on error
trap error ERR # run error handler on error trap error ERR # run error handler on error
STATUS="setup" # keep track of what part of the installation is running for error messages STATUS="setup" # keep track of what part of the installation is running for error messages
@ -209,7 +216,7 @@ if git_check "riscv-gnu-toolchain" "https://github.com/riscv/riscv-gnu-toolchain
git reset --hard && git clean -f && git checkout master && git pull git reset --hard && git clean -f && git checkout master && git pull
git pull git pull
./configure --prefix="${RISCV}" --with-multilib-generator="rv32e-ilp32e--;rv32i-ilp32--;rv32im-ilp32--;rv32iac-ilp32--;rv32imac-ilp32--;rv32imafc-ilp32f--;rv32imafdc-ilp32d--;rv64i-lp64--;rv64ic-lp64--;rv64iac-lp64--;rv64imac-lp64--;rv64imafdc-lp64d--;rv64im-lp64--;" ./configure --prefix="${RISCV}" --with-multilib-generator="rv32e-ilp32e--;rv32i-ilp32--;rv32im-ilp32--;rv32iac-ilp32--;rv32imac-ilp32--;rv32imafc-ilp32f--;rv32imafdc-ilp32d--;rv64i-lp64--;rv64ic-lp64--;rv64iac-lp64--;rv64imac-lp64--;rv64imafdc-lp64d--;rv64im-lp64--;"
make -j ${NUM_THREADS} 2>&1 | tee "$RISCV"/logs/riscv-gnu-toolchain.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess|\bstamp)" || true) make -j ${NUM_THREADS} 2>&1 | logger riscv-gnu-toolchain; [ "${PIPESTATUS[0]}" == 0 ]
if [ "$clean" ]; then if [ "$clean" ]; then
cd "$RISCV" cd "$RISCV"
rm -rf riscv-gnu-toolchain rm -rf riscv-gnu-toolchain
@ -236,8 +243,8 @@ if git_check "elf2hex" "https://github.com/sifive/elf2hex.git" "$RISCV/bin/riscv
git reset --hard && git clean -f && git checkout master && git pull git reset --hard && git clean -f && git checkout master && git pull
autoreconf -i autoreconf -i
./configure --target=riscv64-unknown-elf --prefix="$RISCV" ./configure --target=riscv64-unknown-elf --prefix="$RISCV"
make 2>&1 | tee "$RISCV"/logs/elf2hex.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make 2>&1 | logger elf2hex; [ "${PIPESTATUS[0]}" == 0 ]
make install 2>&1 | tee -a "$RISCV"/logs/elf2hex.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make install 2>&1 | logger elf2hex; [ "${PIPESTATUS[0]}" == 0 ]
if [ "$clean" ]; then if [ "$clean" ]; then
cd "$RISCV" cd "$RISCV"
rm -rf elf2hex rm -rf elf2hex
@ -258,8 +265,8 @@ if git_check "qemu" "https://github.com/qemu/qemu" "$RISCV/include/qemu-plugin.h
git reset --hard && git clean -f && git checkout master && git pull --recurse-submodules -j ${NUM_THREADS} git reset --hard && git clean -f && git checkout master && git pull --recurse-submodules -j ${NUM_THREADS}
git submodule update --init --recursive git submodule update --init --recursive
./configure --target-list=riscv64-softmmu --prefix="$RISCV" ./configure --target-list=riscv64-softmmu --prefix="$RISCV"
make -j ${NUM_THREADS} 2>&1 | tee "$RISCV"/logs/qemu.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make -j ${NUM_THREADS} 2>&1 | logger qemu; [ "${PIPESTATUS[0]}" == 0 ]
make install 2>&1 | tee -a "$RISCV"/logs/qemu.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make install 2>&1 | logger qemu; [ "${PIPESTATUS[0]}" == 0 ]
if [ "$clean" ]; then if [ "$clean" ]; then
cd "$RISCV" cd "$RISCV"
rm -rf qemu rm -rf qemu
@ -281,8 +288,8 @@ if git_check "riscv-isa-sim" "https://github.com/riscv-software-src/riscv-isa-si
mkdir -p build mkdir -p build
cd build cd build
../configure --prefix="$RISCV" ../configure --prefix="$RISCV"
make -j ${NUM_THREADS} 2>&1 | tee "$RISCV"/logs/spike.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make -j ${NUM_THREADS} 2>&1 | logger spike; [ "${PIPESTATUS[0]}" == 0 ]
make install 2>&1 | tee -a "$RISCV"/logs/spike.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make install 2>&1 | logger spike; [ "${PIPESTATUS[0]}" == 0 ]
if [ "$clean" ]; then if [ "$clean" ]; then
cd "$RISCV" cd "$RISCV"
rm -rf riscv-isa-sim rm -rf riscv-isa-sim
@ -306,8 +313,8 @@ if git_check "verilator" "https://github.com/verilator/verilator" "$RISCV/share/
git reset --hard && git clean -f && git checkout master && git pull git reset --hard && git clean -f && git checkout master && git pull
autoconf autoconf
./configure --prefix="$RISCV" ./configure --prefix="$RISCV"
make -j ${NUM_THREADS} 2>&1 | tee "$RISCV"/logs/verilator.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make -j ${NUM_THREADS} 2>&1 | logger verilator; [ "${PIPESTATUS[0]}" == 0 ]
make install 2>&1 | tee -a "$RISCV"/logs/verilator.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) make install 2>&1 | logger verilator; [ "${PIPESTATUS[0]}" == 0 ]
if [ "$clean" ]; then if [ "$clean" ]; then
cd "$RISCV" cd "$RISCV"
rm -rf verilator rm -rf verilator
@ -361,8 +368,8 @@ if git_check "sail-riscv" "https://github.com/riscv/sail-riscv.git" "$RISCV/bin/
cd sail-riscv cd sail-riscv
git reset --hard && git clean -f && git checkout master && git pull git reset --hard && git clean -f && git checkout master && git pull
export OPAMCLI=2.0 # Sail is not compatible with opam 2.1 as of 4/16/24 export OPAMCLI=2.0 # Sail is not compatible with opam 2.1 as of 4/16/24
ARCH=RV64 make -j ${NUM_THREADS} c_emulator/riscv_sim_RV64 2>&1 | tee "$RISCV"/logs/sail_model.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) ARCH=RV64 make -j ${NUM_THREADS} c_emulator/riscv_sim_RV64 2>&1 | logger sailModel; [ "${PIPESTATUS[0]}" == 0 ]
ARCH=RV32 make -j ${NUM_THREADS} c_emulator/riscv_sim_RV32 2>&1 | tee -a "$RISCV"/logs/sail_model.log | (grep -iE "(\bwarning|\berror|\bfail|\bsuccess)" || true) ARCH=RV32 make -j ${NUM_THREADS} c_emulator/riscv_sim_RV32 2>&1 | logger sailModel; [ "${PIPESTATUS[0]}" == 0 ]
cp -f c_emulator/riscv_sim_RV64 "$RISCV"/bin/riscv_sim_RV64 cp -f c_emulator/riscv_sim_RV64 "$RISCV"/bin/riscv_sim_RV64
cp -f c_emulator/riscv_sim_RV32 "$RISCV"/bin/riscv_sim_RV32 cp -f c_emulator/riscv_sim_RV32 "$RISCV"/bin/riscv_sim_RV32
if [ "$clean" ]; then if [ "$clean" ]; then