Switch to a less verbose way to set defaults for environment variables

By reducing duplication, we improve readability and reduce errors
pull/934/head
Jesse Vincent 4 years ago
parent a91c6a556e
commit 6e8d1d020a
No known key found for this signature in database
GPG Key ID: CC228463465E40BC

@ -26,7 +26,7 @@ absolute_filename() {
build_version () {
LIB_PROPERTIES_PATH="${LIB_PROPERTIES_PATH:-"../.."}"
: "${LIB_PROPERTIES_PATH:="../.."}"
GIT_VERSION="$(cd "${SKETCH_DIR}"; if [ -d .git ]; then echo -n '-g' && git describe --abbrev=4 --dirty --always; fi)"
LIB_VERSION="$(cd "${SKETCH_DIR}"; (grep version= "${LIB_PROPERTIES_PATH}/library.properties" 2>/dev/null || echo version=0.0.0) | cut -d= -f2)${GIT_VERSION}"
}
@ -35,30 +35,30 @@ build_paths() {
# We need that echo because we\re piping to cksum
# shellcheck disable=SC2005
SKETCH_IDENTIFIER="$(echo "${SKETCH_FILE_PATH}" | cksum | cut -d ' ' -f 1)-${SKETCH_FILE_NAME}"
KALEIDOSCOPE_TEMP_PATH="${KALEIDOSCOPE_TEMP_PATH:-${TMPDIR:-/tmp}/kaleidoscope-${USER}}"
: "${KALEIDOSCOPE_TEMP_PATH:=${TMPDIR:-/tmp}/kaleidoscope-${USER}}"
KALEIDOSCOPE_BUILD_PATH="${KALEIDOSCOPE_BUILD_PATH:-${KALEIDOSCOPE_TEMP_PATH}/sketch}"
KALEIDOSCOPE_OUTPUT_PATH="${KALEIDOSCOPE_OUTPUT_PATH:-${KALEIDOSCOPE_TEMP_PATH}/sketch}"
: "${KALEIDOSCOPE_BUILD_PATH:=${KALEIDOSCOPE_TEMP_PATH}/sketch}"
: "${KALEIDOSCOPE_OUTPUT_PATH:=${KALEIDOSCOPE_TEMP_PATH}/sketch}"
SKETCH_OUTPUT_DIR="${SKETCH_OUTPUT_DIR:-${SKETCH_IDENTIFIER}/output}"
SKETCH_BUILD_DIR="${SKETCH_BUILD_DIR:-${SKETCH_IDENTIFIER}/build}"
: "${SKETCH_OUTPUT_DIR:=${SKETCH_IDENTIFIER}/output}"
: "${SKETCH_BUILD_DIR:=${SKETCH_IDENTIFIER}/build}"
BUILD_PATH="${BUILD_PATH:-${KALEIDOSCOPE_BUILD_PATH}/${SKETCH_BUILD_DIR}}"
OUTPUT_PATH="${OUTPUT_PATH:-${KALEIDOSCOPE_OUTPUT_PATH}/${SKETCH_OUTPUT_DIR}}"
: "${BUILD_PATH:=${KALEIDOSCOPE_BUILD_PATH}/${SKETCH_BUILD_DIR}}"
: "${OUTPUT_PATH:=${KALEIDOSCOPE_OUTPUT_PATH}/${SKETCH_OUTPUT_DIR}}"
CCACHE_WRAPPER_PATH="${CCACHE_WRAPPER_PATH:-${KALEIDOSCOPE_TEMP_PATH}/ccache/bin}"
CORE_CACHE_PATH="${CORE_CACHE_PATH:-${KALEIDOSCOPE_TEMP_PATH}/arduino-cores}"
: "${CCACHE_WRAPPER_PATH:=${KALEIDOSCOPE_TEMP_PATH}/ccache/bin}"
: "${CORE_CACHE_PATH:=${KALEIDOSCOPE_TEMP_PATH}/arduino-cores}"
mkdir -p "$CORE_CACHE_PATH"
mkdir -p "$BUILD_PATH"
}
build_filenames () {
OUTPUT_FILE_PREFIX="${OUTPUT_FILE_PREFIX:-${SKETCH_BASE_NAME}-${LIB_VERSION}}"
HEX_FILE_PATH="${HEX_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex}"
HEX_FILE_WITH_BOOTLOADER_PATH="${HEX_FILE_WITH_BOOTLOADER_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}-with-bootloader.hex}"
ELF_FILE_PATH="${ELF_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf}"
LIB_FILE_PATH="${LIB_FILE_PATH:-${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.a}"
: "${OUTPUT_FILE_PREFIX:=${SKETCH_BASE_NAME}-${LIB_VERSION}}"
: "${HEX_FILE_PATH:=${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.hex}"
: "${HEX_FILE_WITH_BOOTLOADER_PATH:=${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}-with-bootloader.hex}"
: "${ELF_FILE_PATH:=${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.elf}"
: "${LIB_FILE_PATH:=${OUTPUT_PATH}/${OUTPUT_FILE_PREFIX}.a}"
}
@ -104,7 +104,7 @@ firmware_size () {
return
fi
MAX_PROG_SIZE=${MAX_PROG_SIZE:-$(get_arduino_pref 'upload.maximum_size')}
: "${MAX_PROG_SIZE:=$(get_arduino_pref 'upload.maximum_size')}"
## This is a terrible hack, please don't hurt me. - algernon
@ -301,8 +301,8 @@ flash_with_programmer() {
find_bootloader_path() {
BOOTLOADER_FILE=$( get_arduino_pref 'bootloader.file' )
BOOTLOADER_FILE="${BOOTLOADER_FILE:-caterina/Caterina.hex}"
BOOTLOADER_PATH="${BOOTLOADER_PATH:-${BOARD_HARDWARE_PATH}/keyboardio/avr/bootloaders/${BOOTLOADER_FILE}}"
: "${BOOTLOADER_FILE:=caterina/Caterina.hex}"
: "${BOOTLOADER_PATH:=${BOARD_HARDWARE_PATH}/keyboardio/avr/bootloaders/${BOOTLOADER_FILE}}"
}

@ -9,15 +9,15 @@ SKETCH="${SKETCH:-${DEFAULT_SKETCH}}"
######## Keyboard hardware definitions
########
BOARD="${BOARD:-model01}"
MCU="${MCU:-atmega32u4}"
: "${BOARD:=model01}"
: "${MCU:=atmega32u4}"
if [ -z "${ARCH}" ]; then
ARCH=$(echo "${FQBN}" | sed -n -e 's/^[^:]\+:\([^:]\+\).*/\1/p')
fi
if [ "${ARCH}" = "virtual" ]; then
FQBN="${FQBN:-keyboardio:virtual:${BOARD}}"
: "${FQBN:=keyboardio:virtual:${BOARD}}"
# Set the compiler path for virtual builds
#
@ -31,7 +31,7 @@ else
fi
if [ -z "${FQBN}" ]; then
FQBN="${FQBN:-keyboardio:avr:${BOARD}}"
: "${FQBN:=keyboardio:avr:${BOARD}}"
fi
########
@ -45,10 +45,10 @@ uname_O=$(uname -o 2>/dev/null || echo not)
find_device_vid_pid() {
VID=${VID:-$(get_arduino_pref 'build.vid')}
SKETCH_PID=${SKETCH_PID:-$(get_arduino_pref 'build.pid')}
BOOTLOADER_PID=${BOOTLOADER_PID:-$(get_arduino_pref 'bootloader.pid')}
BOOTLOADER_VID=${BOOTLOADER_VID:-$(get_arduino_pref 'bootloader.vid')}
: ${VID:=$(get_arduino_pref 'build.vid')}
: ${SKETCH_PID:=$(get_arduino_pref 'build.pid')}
: ${BOOTLOADER_PID:=$(get_arduino_pref 'bootloader.pid')}
: ${BOOTLOADER_VID:=$(get_arduino_pref 'bootloader.vid')}
}
@ -96,7 +96,7 @@ reset_device_cmd() {
find_bootloader_ports() {
find_device_vid_pid
BOOTLOADER_VID="${BOOTLOADER_VID:-${VID}}"
: "${BOOTLOADER_VID:=${VID}}"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-linux-udev"
if [[ "${DEVICE_PORT_BOOTLOADER}" = "" ]]; then
DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID})"
@ -119,15 +119,15 @@ if [ "${uname_S}" = "Darwin" ]; then
/bin/stty -f ${DEVICE_PORT} 1200
}
ARDUINO_PATH="${ARDUINO_PATH:-/Applications/Arduino.app/Contents/Java/}"
ARDUINO_PACKAGE_PATH="${ARDUINO_PACKAGE_PATH:-${HOME}/Library/Arduino15/packages}"
ARDUINO_LOCAL_LIB_PATH="${ARDUINO_LOCAL_LIB_PATH:-${HOME}/Documents/Arduino}"
: "${ARDUINO_PATH:=/Applications/Arduino.app/Contents/Java/}"
: "${ARDUINO_PACKAGE_PATH:=${HOME}/Library/Arduino15/packages}"
: "${ARDUINO_LOCAL_LIB_PATH:=${HOME}/Documents/Arduino}"
MD5="md5"
find_bootloader_ports() {
find_device_vid_pid
BOOTLOADER_VID="${BOOTLOADER_VID:-${VID}}"
: "${BOOTLOADER_VID:=${VID}}"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-macos"
if [[ "${DEVICE_PORT_BOOTLOADER}" = "" ]]; then
DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID})"
@ -148,12 +148,12 @@ elif [ "${uname_S}" = "FreeBSD" ]; then
}
MD5="md5"
AVR_SIZE="${AVR_SIZE:-/usr/local/bin/avr-size}"
AVR_NM="${AVR_NM:-/usr/local/bin/avr-nm}"
AVR_OBJDUMP="${AVR_OBJDUMP:-/usr/local/bin/avr-objdump}"
AVRDUDE="${AVRDUDE:-/usr/local/bin/avrdude}"
AVRDUDE_CONF="${AVRDUDE_CONF:-/usr/local/etc/avrdude.conf}"
ARDUINO_BUILDER="${ARDUINO_BUILDER:-/usr/local/bin/arduino-builder}"
: "${AVR_SIZE:=/usr/local/bin/avr-size}"
: "${AVR_NM:=/usr/local/bin/avr-nm}"
: "${AVR_OBJDUMP:=/usr/local/bin/avr-objdump}"
: "${AVRDUDE:=/usr/local/bin/avrdude}"
: "${AVRDUDE_CONF:=/usr/local/etc/avrdude.conf}"
: "${ARDUINO_BUILDER:=/usr/local/bin/arduino-builder}"
find_bootloader_ports() {
DEVICE_PORT_PROBER="${KALEIDOSCPE_BIN_DIR}/find-device-port-freebsd"
@ -161,7 +161,7 @@ elif [ "${uname_S}" = "FreeBSD" ]; then
}
if [ "${ARCH}" = "virtual" ]; then
COMPILER_PATH="${COMPILER_PATH:-/usr/local/bin/}"
: "${COMPILER_PATH:=/usr/local/bin/}"
fi
elif [ "${uname_O}" = "Cygwin" ]; then
@ -173,9 +173,9 @@ elif [ "${uname_O}" = "Cygwin" ]; then
#
# It's important that all of these be underneath /cygdrive/c so they can be converted to Windows paths that the
# Windows Arduino binaries can understand.
ARDUINO_PATH="${ARDUINO_PATH:-/cygdrive/c/Program\ Files\ (x86)/Arduino}"
ARDUINO_PACKAGE_PATH="${ARDUINO_PACKAGE_PATH:-/cygdrive/c/Users/${USER}/AppData/Local/Arduino15/packages}"
ARDUINO_LOCAL_LIB_PATH="${ARDUINO_LOCAL_LIB_PATH:-/cygdrive/c/Users/${USER}/Arduino}"
: "${ARDUINO_PATH:=/cygdrive/c/Program\ Files\ (x86)/Arduino}"
: "${ARDUINO_PACKAGE_PATH:=/cygdrive/c/Users/${USER}/AppData/Local/Arduino15/packages}"
: "${ARDUINO_LOCAL_LIB_PATH:=/cygdrive/c/Users/${USER}/Arduino}"
TMPDIR="${ARDUINO_LOCAL_LIB_PATH:-/cygdrive/c/Users/${USER}/AppData/Local/Temp}"
# We need to prevent Windows executables from being passed parameters that are absolute paths, since they won't
@ -207,7 +207,7 @@ elif [ "${uname_O}" = "Cygwin" ]; then
find_bootloader_ports() {
find_device_vid_pid
BOOTLOADER_VID="${BOOTLOADER_VID:-${VID}}"
: "${BOOTLOADER_VID:=${VID}}"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-windows.ps1"
DEVICE_PORT_BOOTLOADER="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${BOOTLOADER_VID} ${BOOTLOADER_PID} -Format COM)"
}
@ -218,12 +218,12 @@ fi
###### Arduino tools configuration
######
ARDUINO_PATH="${ARDUINO_PATH:-/usr/local/arduino}"
ARDUINO_LOCAL_LIB_PATH="${ARDUINO_LOCAL_LIB_PATH:-${HOME}/Arduino}"
ARDUINO_TOOLS_PATH="${ARDUINO_TOOLS_PATH:-${ARDUINO_PATH}/hardware/tools}"
ARDUINO_PACKAGE_PATH="${ARDUINO_PACKAGE_PATH:-${HOME}/.arduino15/packages}"
: "${ARDUINO_PATH:=/usr/local/arduino}"
: "${ARDUINO_LOCAL_LIB_PATH:=${HOME}/Arduino}"
: "${ARDUINO_TOOLS_PATH:=${ARDUINO_PATH}/hardware/tools}"
: "${ARDUINO_PACKAGE_PATH:=${HOME}/.arduino15/packages}"
ARDUINO_BUILDER="${ARDUINO_BUILDER:-${ARDUINO_PATH}/arduino-builder}"
: "${ARDUINO_BUILDER:=${ARDUINO_PATH}/arduino-builder}"
ARDUINO_IDE_VERSION="10607"
######
@ -231,7 +231,7 @@ ARDUINO_IDE_VERSION="10607"
######
# Allow the compiler path to be empty for virtual builds
COMPILER_PATH="${COMPILER_PATH-${ARDUINO_TOOLS_PATH}/avr/bin/}"
: "${COMPILER_PATH=${ARDUINO_TOOLS_PATH}/avr/bin/}"
COMPILER_SUFFIX=""
@ -242,25 +242,25 @@ OBJCOPY_BASENAME=$(basename ${OBJCOPY:-objcopy})
# Allow the compiler prefix to be empty for virtual builds
COMPILER_PREFIX="${COMPILER_PREFIX-avr-}"
AVR_SIZE="${AVR_SIZE:-${COMPILER_PATH}/${COMPILER_PREFIX}size}"
AVR_SIZE_FLAGS="${AVR_SIZE_FLAGS:--C --mcu=${MCU}}"
AVR_OBJDUMP="${AVR_OBJDUMP:-${COMPILER_PATH}/${COMPILER_PREFIX}objdump}"
AVR_OBJCOPY="${AVR_OBJCOPY:-${COMPILER_PATH}/${COMPILER_PREFIX}objcopy}"
AVR_NM="${AVR_NM:-${COMPILER_PATH}/${COMPILER_PREFIX}nm}"
AVR_AR="${AVR_AR:-${COMPILER_PATH}/${COMPILER_PREFIX}ar}"
AVR_GCC="${AVR_GCC:-${COMPILER_PATH}/${COMPILER_PREFIX}${C_COMPILER_BASENAME}}"
: "${AVR_SIZE:=${COMPILER_PATH}/${COMPILER_PREFIX}size}"
: "${AVR_SIZE_FLAGS:=-C --mcu=${MCU}}"
: "${AVR_OBJDUMP:=${COMPILER_PATH}/${COMPILER_PREFIX}objdump}"
: "${AVR_OBJCOPY:=${COMPILER_PATH}/${COMPILER_PREFIX}objcopy}"
: "${AVR_NM:=${COMPILER_PATH}/${COMPILER_PREFIX}nm}"
: "${AVR_AR:=${COMPILER_PATH}/${COMPILER_PREFIX}ar}"
: "${AVR_GCC:=${COMPILER_PATH}/${COMPILER_PREFIX}${C_COMPILER_BASENAME}}"
AVR_GPLUSPLUS="${AVR_GCC:-${COMPILER_PATH}/${COMPILER_PREFIX}${CXX_COMPILER_BASENAME}}"
AVRDUDE="${AVRDUDE:-${ARDUINO_TOOLS_PATH}/avr/bin/avrdude}"
AVRDUDE_CONF="${AVRDUDE_CONF:-${ARDUINO_TOOLS_PATH}/avr/etc/avrdude.conf}"
: "${AVRDUDE:=${ARDUINO_TOOLS_PATH}/avr/bin/avrdude}"
: "${AVRDUDE_CONF:=${ARDUINO_TOOLS_PATH}/avr/etc/avrdude.conf}"
######
###### Source files and dependencies
######
BOARD_HARDWARE_PATH="${BOARD_HARDWARE_PATH:-${ARDUINO_LOCAL_LIB_PATH}/hardware}"
: "${BOARD_HARDWARE_PATH:=${ARDUINO_LOCAL_LIB_PATH}/hardware}"
if [ ! -z "${ARDUINO_TOOLS_PATH}" ]; then
ARDUINO_TOOLS_PARAM="${ARDUINO_TOOLS_PATH}"

Loading…
Cancel
Save