Display output on error only

This commit is contained in:
urob 2023-01-14 23:34:05 -05:00
parent 8e5ebef8c3
commit 1bdb36540a

View file

@ -1,7 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
RUNWITH_DOCKER=true # Parse input arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
# needed when user isn't in docker group # needed when user isn't in docker group
@ -30,6 +29,11 @@ while [[ $# -gt 0 ]]; do
shift shift
;; ;;
--log-dir)
LOG_DIR="$2"
shift
;;
--host-config-dir) --host-config-dir)
HOST_CONFIG_DIR="$2" HOST_CONFIG_DIR="$2"
shift shift
@ -66,7 +70,10 @@ done
# Set defaults # Set defaults
[[ -z $WEST_VERSION ]] && WEST_VERSION="3.0" [[ -z $WEST_VERSION ]] && WEST_VERSION="3.0"
[[ -z $RUNWITH_DOCKER ]] && RUNWITH_DOCKER=true
[[ -z $OUTPUT_DIR ]] && OUTPUT_DIR="$WINHOME/Downloads" [[ -z $OUTPUT_DIR ]] && OUTPUT_DIR="$WINHOME/Downloads"
[[ -z $LOG_DIR ]] && LOG_DIR="/tmp"
[[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk" [[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk"
[[ -z $HOST_CONFIG_DIR ]] && HOST_CONFIG_DIR="$HOME/zmk-config" [[ -z $HOST_CONFIG_DIR ]] && HOST_CONFIG_DIR="$HOME/zmk-config"
@ -84,25 +91,28 @@ DOCKER_IMG="zmkfirmware/zmk-dev-arm:$WEST_VERSION"
cd "$HOST_CONFIG_DIR" cd "$HOST_CONFIG_DIR"
# update maximum combos per key if [[ -f config/combos.dtsi ]]
count=$( \ # update maximum combos per key
tail -n +10 config/combos.dtsi | \ then
grep -Eo '[LR][TMBH][0-9]' | \ count=$( \
sort | uniq -c | sort -nr | \ tail -n +10 config/combos.dtsi | \
awk 'NR==1{print $1}' \ grep -Eo '[LR][TMBH][0-9]' | \
) sort | uniq -c | sort -nr | \
sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" config/*.conf awk 'NR==1{print $1}' \
echo "Setting MAX_COMBOS_PER_KEY to $count" )
sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" config/*.conf
echo "Setting MAX_COMBOS_PER_KEY to $count"
# update maximum keys per combo # update maximum keys per combo
count=$( \ count=$( \
tail -n +10 config/combos.dtsi | \ tail -n +10 config/combos.dtsi | \
grep -o -n '[LR][TMBH][0-9]' | \ grep -o -n '[LR][TMBH][0-9]' | \
cut -d : -f 1 | uniq -c | sort -nr | \ cut -d : -f 1 | uniq -c | sort -nr | \
awk 'NR==1{print $1}' \ awk 'NR==1{print $1}' \
) )
sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" config/*.conf sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" config/*.conf
echo "Setting MAX_KEYS_PER_COMBO to $count" echo "Setting MAX_KEYS_PER_COMBO to $count"
fi
# +--------------------+ # +--------------------+
# | BUILD THE FIRMWARE | # | BUILD THE FIRMWARE |
@ -130,13 +140,16 @@ fi
# usage: compile_board board # usage: compile_board board
compile_board () { compile_board () {
echo -e "\n$(tput setaf 4)Building $1$(tput sgr0)" echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)"
BUILD_DIR="${1}_$SUFFIX" BUILD_DIR="${1}_$SUFFIX"
LOGFILE="$LOG_DIR/zmk_build_$1.log"
$DOCKER_CMD west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \ $DOCKER_CMD west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \
-- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev -- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev > "$LOGFILE" 2>&1
if [[ $? -eq 0 ]] if [[ $? -eq 0 ]]
then then
echo "$(tput setaf 4)Success: $1 done$(tput sgr0)" # echo "$(tput setaf 4)Success: $1 done$(tput sgr0)"
echo "$(tput setaf 2)done$(tput sgr0)"
echo "Build log saved to \"$LOGFILE\"."
if [[ -f $HOST_ZMK_DIR/app/build/$BUILD_DIR/zephyr/zmk.uf2 ]] if [[ -f $HOST_ZMK_DIR/app/build/$BUILD_DIR/zephyr/zmk.uf2 ]]
then then
TYPE="uf2" TYPE="uf2"
@ -147,6 +160,8 @@ compile_board () {
[[ -f $OUTPUT ]] && [[ ! -L $OUTPUT ]] && mv "$OUTPUT" "$OUTPUT.bak" [[ -f $OUTPUT ]] && [[ ! -L $OUTPUT ]] && mv "$OUTPUT" "$OUTPUT.bak"
cp "$HOST_ZMK_DIR/app/build/$BUILD_DIR/zephyr/zmk.$TYPE" "$OUTPUT" cp "$HOST_ZMK_DIR/app/build/$BUILD_DIR/zephyr/zmk.$TYPE" "$OUTPUT"
else else
echo
cat "$LOGFILE"
echo "$(tput setaf 1)Error: $1 failed$(tput sgr0)" echo "$(tput setaf 1)Error: $1 failed$(tput sgr0)"
fi fi
} }