Merge pull request #934 from keyboardio/build-cleanup

Some more builder cleanups.
pull/944/head
Gergely Nagy 4 years ago committed by GitHub
commit 1d0d2d43d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -121,6 +121,12 @@ shellcheck:
shellcheck ${SHELL_FILES}; \
fi
check-docs:
doxygen $(PLUGIN_TEST_SUPPORT_DIR)/quality/etc/check-docs.conf 2> /dev/null >/dev/null
python $(PLUGIN_TEST_SUPPORT_DIR)/quality/doxy-coverage.py /tmp/undocced/xml
SMOKE_SKETCHES=$(shell if [ -d ./examples ]; then find ./examples -type f -name \*ino | xargs -n 1 dirname; fi)
smoke-sketches: $(SMOKE_SKETCHES)

@ -26,42 +26,39 @@ 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}"
}
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}"
}
@ -107,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
@ -174,7 +171,7 @@ prompt_before_flashing () {
}
flash () {
maybe_build "$@"
compile "$@"
# Check to see if we can see a keyboard bootloader port.
# If we -can-, then we should skip over the "reset to bootloader" thing
@ -280,14 +277,14 @@ flash_over_usb () {
}
flash_from_bootloader() {
maybe_build "$@"
compile "$@"
prompt_before_flashing
find_bootloader_ports
check_bootloader_port_and_flash
}
program() {
maybe_build "$@"
compile "$@"
prompt_before_flashing
flash_with_programmer
}
@ -304,15 +301,13 @@ 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}}"
}
hex_with_bootloader () {
if [ ! -e "${HEX_FILE_PATH}" ]; then
compile
fi
compile
find_bootloader_path
@ -331,21 +326,6 @@ hex_with_bootloader () {
EOF
}
maybe_build () {
find_sketch
build_version
build_paths
build_filenames
# If the hex file is older than the sketch file, or the hex file does not exist
# then rebuild. This is not as correct as letting make check our dependencies
# But it's less broken for most user use cases
# TODO(anyone): Make this suck less
if [ "${HEX_FILE_PATH}" -ot "${SKETCH_FILE_PATH}" ]; then
build "$@"
fi
}
build () {
compile "$@"
size "$@"
@ -356,13 +336,24 @@ prepare_ccache () {
build_paths
enable_ccache
}
compile () {
find_sketch
build_version
build_paths
build_filenames
enable_ccache
# If the hex file is older than the sketch file, or the hex file does not exist
# then rebuild. This is not as correct as letting make check our dependencies
# But it's less broken for most user use cases
# TODO(anyone): Make this suck less
if [ "${HEX_FILE_PATH}" -ot "${SKETCH_FILE_PATH}" ]; then
do_compile "$@"
fi
}
do_compile () {
prepare_ccache
install -d "${OUTPUT_PATH}"
@ -496,9 +487,7 @@ compile_all () {
size () {
if [ ! -e "${HEX_FILE_PATH}" ]; then
compile
fi
compile
echo "- Size: ${ELF_FILE_PATH}"
# shellcheck disable=SC2086
@ -507,18 +496,13 @@ size () {
}
size_map () {
if [ ! -e "${HEX_FILE_PATH}" ]; then
compile
fi
compile
"${AVR_NM}" --size-sort -C -r -l -t decimal "${ELF_FILE_PATH}"
}
disassemble () {
if [ ! -e "${HEX_FILE_PATH}" ]; then
compile
fi
compile
"${AVR_OBJDUMP}" -C -d "${ELF_FILE_PATH}"
}
@ -665,23 +649,20 @@ KALEIDOSCOPE_BIN_DIR="${KALEIDOSCOPE_DIR}/bin/"
# shellcheck disable=SC2155
export SOURCEDIR="$(pwd)"
if [ -e "${HOME}/.kaleidoscope-builder.conf" ]; then
# shellcheck disable=SC1090
. "${HOME}/.kaleidoscope-builder.conf"
fi
if [ -e "${SOURCEDIR}/.kaleidoscope-builder.conf" ]; then
# shellcheck disable=SC1090
. "${SOURCEDIR}/.kaleidoscope-builder.conf"
fi
for conf_file in \
"${HOME}/.kaleidoscope-builder.conf" \
"${SOURCEDIR}/.kaleidoscope-builder.conf" \
"${SOURCEDIR}/kaleidoscope-builder.conf" \
"${KALEIDOSCOPE_DIR}/etc/kaleidoscope-builder.conf"; do
if [ -e "${conf_file}" ]; then
# shellcheck disable=SC1090
. "${conf_file}"
fi
if [ -e "${SOURCEDIR}/kaleidoscope-builder.conf" ]; then
# shellcheck disable=SC1090
. "${SOURCEDIR}/kaleidoscope-builder.conf"
fi
done
# shellcheck disable=SC1090
. "${KALEIDOSCOPE_DIR}/etc/kaleidoscope-builder.conf"
if [ -n "${VERBOSE}" ] && [[ "${VERBOSE}" -gt 0 ]]; then
ARDUINO_VERBOSE="-verbose"

@ -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