Merge pull request #932 from keyboardio/builder-cleanup

Additional cleanup of kaleidoscope-builder
pull/944/head
Gergely Nagy 4 years ago committed by GitHub
commit fed3a6d6dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -98,6 +98,29 @@ find-filename-conflicts:
bin/find-filename-conflicts; \
fi
#.PHONY: astyle test cpplint cpplint-noisy shellcheck smoke-examples find-filename-conflicts:
astyle:
PATH="$(PLUGIN_TEST_BIN_DIR):$(PATH)" $(PLUGIN_TEST_SUPPORT_DIR)/quality/run-astyle
check-astyle: astyle
PATH="$(PLUGIN_TEST_BIN_DIR):$(PATH)" $(PLUGIN_TEST_SUPPORT_DIR)/quality/astyle-check
cpplint-noisy:
-$(PLUGIN_TEST_SUPPORT_DIR)/quality/cpplint.py --filter=-legal/copyright,-build/include,-readability/namespace,-whitespace/line_length,-runtime/references --recursive --extensions=cpp,h,ino --exclude=$(BOARD_HARDWARE_PATH) src examples
cpplint:
$(PLUGIN_TEST_SUPPORT_DIR)/quality/cpplint.py --quiet --filter=-whitespace,-legal/copyright,-build/include,-readability/namespace,-runtime/references --recursive --extensions=cpp,h,ino src examples
SHELL_FILES = $(shell if [ -d bin ]; then egrep -n -r -l "(env (ba)?sh)|(/bin/(ba)?sh)" bin; fi)
shellcheck:
@if [ -d "bin" ]; then \
shellcheck ${SHELL_FILES}; \
fi
SMOKE_SKETCHES=$(shell if [ -d ./examples ]; then find ./examples -type f -name \*ino | xargs -n 1 dirname; fi)
smoke-sketches: $(SMOKE_SKETCHES)

@ -26,15 +26,17 @@ absolute_filename() {
build_version () {
GIT_VERSION="$(cd "${SKETCH_DIR}"; if [ -d .git ]; then echo -n '-g' && git describe --abbrev=4 --dirty --always; fi)"
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 "$(absolute_filename "${SKETCH_DIR}/${SKETCH}.ino")" | cksum | cut -d ' ' -f 1)-${SKETCH}.ino"
SKETCH_IDENTIFIER="$(echo "${SKETCH_FILE_PATH}" | cksum | cut -d ' ' -f 1)-${SKETCH_FILE_NAME}"
KALEIDOSCOPE_TEMP_PATH="${KALEIDOSCOPE_TEMP_PATH:-${TMPDIR:-/tmp}/kaleidoscope-${USER}}"
@ -55,7 +57,7 @@ build_paths() {
}
build_filenames () {
OUTPUT_FILE_PREFIX="${OUTPUT_FILE_PREFIX:-${SKETCH}-${LIB_VERSION}}"
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}"
@ -105,9 +107,10 @@ firmware_size () {
return
fi
MAX_PROG_SIZE=${MAX_PROG_SIZE:-$(get_arduino_pref 'upload.maximum_size')}
## This is a terrible hack, please don't hurt me. - algernon
find_max_prog_size
set +e
raw_output=$("$@" 2> /dev/null)
rc=$?
@ -130,23 +133,21 @@ firmware_size () {
find_sketch () {
SKETCH="${SKETCH:-${DEFAULT_SKETCH}}"
LIBRARY="${LIBRARY:-${SKETCH}}"
if [ -z "${SKETCH}" ] || [ -z "${LIBRARY}" ] || [ -z "${ROOT}" ] || [ -z "${SOURCEDIR}" ]; then
echo "SKETCH, LIBRARY, SOURCEDIR, and ROOT need to be set before including this file!" >&2
if [ -z "${SKETCH}" ]; then
echo "SKETCH needs to be set before including this file!" >&2
exit 1
fi
SKETCH_DIR="$SKETCH"
SKETCH_FILE=$(basename "$SKETCH")
SKETCH_DIR="${SKETCH}"
SKETCH_BASE_NAME=$(basename "$SKETCH")
SKETCH_FILE_NAME="${SKETCH_BASE_NAME}.ino"
for path in "${SKETCH_DIR}" \
"examples/${LIBRARY}" \
"src" \
"."; do
if [ -f "${path}/${SKETCH_FILE}.ino" ]; then
if [ -f "${path}/${SKETCH_FILE_NAME}" ]; then
SKETCH_DIR="${path}"
SKETCH="${SKETCH_FILE}"
SKETCH_FILE_PATH=$(absolute_filename "${SKETCH_DIR}/${SKETCH_FILE_NAME}")
return
fi
done
@ -301,6 +302,13 @@ flash_with_programmer() {
"-Uflash:w:${HEX_FILE_PATH}:i"
}
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}}"
}
hex_with_bootloader () {
if [ ! -e "${HEX_FILE_PATH}" ]; then
compile
@ -312,7 +320,7 @@ hex_with_bootloader () {
echo "Using ${BOOTLOADER_PATH}"
${MD5} "${BOOTLOADER_PATH}"
cat "${BOOTLOADER_PATH}" >> "${HEX_FILE_WITH_BOOTLOADER_PATH}"
ln -sf -- "${OUTPUT_FILE_PREFIX}-with-bootloader.hex" "${OUTPUT_PATH}/${SKETCH}-latest-with-bootloader.hex"
ln -sf -- "${OUTPUT_FILE_PREFIX}-with-bootloader.hex" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest-with-bootloader.hex"
cat <<- EOF
Combined firmware and bootloader are now at ${HEX_FILE_WITH_BOOTLOADER_PATH}
@ -332,7 +340,6 @@ maybe_build () {
# 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
SKETCH_FILE_PATH=$(absolute_filename "${SKETCH_DIR}/${SKETCH}.ino")
if [ "${HEX_FILE_PATH}" -ot "${SKETCH_FILE_PATH}" ]; then
build "$@"
fi
@ -359,7 +366,7 @@ compile () {
install -d "${OUTPUT_PATH}"
echo "Building ${SKETCH_DIR}/${SKETCH}"
echo "Building ${SKETCH_FILE_PATH}"
# This is defined in the (optional) user config.
# shellcheck disable=SC2154
@ -410,7 +417,7 @@ compile () {
-tools "${ARDUINO_PATH}/tools-builder" \
-fqbn "${FQBN}" \
-libraries "." \
-libraries "${ROOT}" \
-libraries "${KALEIDOSCOPE_DIR}" \
-libraries "${BOARD_HARDWARE_PATH}/.." \
${local_LIBS} \
${EXTRA_BUILDER_ARGS} \
@ -428,16 +435,16 @@ compile () {
-warnings all \
${ARDUINO_VERBOSE} \
${ARDUINO_AVR_GCC_PREFIX_PARAM} \
"${SKETCH_DIR}/${SKETCH}.ino"
"${SKETCH_FILE_PATH}"
if [ -z "${LIBONLY}" ]; then
cp "${BUILD_PATH}/${SKETCH}.ino.hex" "${HEX_FILE_PATH}"
cp "${BUILD_PATH}/${SKETCH}.ino.elf" "${ELF_FILE_PATH}"
ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH}-latest.hex"
ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH}-latest.elf"
cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.hex" "${HEX_FILE_PATH}"
cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.elf" "${ELF_FILE_PATH}"
ln -sf "${OUTPUT_FILE_PREFIX}.hex" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.hex"
ln -sf "${OUTPUT_FILE_PREFIX}.elf" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.elf"
else
cp "${BUILD_PATH}/${SKETCH}.ino.a" "${LIB_FILE_PATH}"
ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH}-latest.a"
cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.a" "${LIB_FILE_PATH}"
ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.a"
fi
if [ "${ARDUINO_VERBOSE}" = "-verbose" ]; then
@ -473,7 +480,6 @@ build_all () {
for plugin in ${plugins}; do
export SKETCH="${plugin}"
export LIBRARY="${plugin}"
$0 "${plugin}" build
done
}
@ -484,7 +490,6 @@ compile_all () {
for plugin in ${plugins}; do
export SKETCH="${plugin}"
export LIBRARY="${plugin}"
$0 "${plugin}" compile
done
}
@ -495,7 +500,7 @@ size () {
compile
fi
echo "- Size: firmware/${LIBRARY}/${OUTPUT_FILE_PREFIX}.elf"
echo "- Size: ${ELF_FILE_PATH}"
# shellcheck disable=SC2086
firmware_size "${AVR_SIZE}" ${AVR_SIZE_FLAGS} "${ELF_FILE_PATH}"
echo
@ -650,8 +655,13 @@ fi
##
## - if there is only one argument, that's a command
ROOT="$(cd "$(dirname "$0")"/..; pwd)"
export ROOT
KALEIDOSCOPE_DIR="$(cd "$(dirname "$0")"/..; pwd)"
# shellcheck disable=SC2034
KALEIDOSCOPE_BIN_DIR="${KALEIDOSCOPE_DIR}/bin/"
# shellcheck disable=SC2155
export SOURCEDIR="$(pwd)"
@ -671,7 +681,7 @@ if [ -e "${SOURCEDIR}/kaleidoscope-builder.conf" ]; then
fi
# shellcheck disable=SC1090
. "${ROOT}/etc/kaleidoscope-builder.conf"
. "${KALEIDOSCOPE_DIR}/etc/kaleidoscope-builder.conf"
if [ -n "${VERBOSE}" ] && [[ "${VERBOSE}" -gt 0 ]]; then
ARDUINO_VERBOSE="-verbose"
@ -723,11 +733,6 @@ for i in $(seq 1 $#); do
shift
done
LIBRARY="${SKETCH}"
export SKETCH
export LIBRARY
for cmd in ${cmds}; do
${cmd}
done

@ -1,10 +1,9 @@
# -*- shell-script -*-
## NEEDS: LIBRARY, SKETCH, ROOT, SOURCEDIR
## NEEDS: SKETCH
## Should be included when the current directory is the dir of the Sketch.
SKETCH="${SKETCH:-${DEFAULT_SKETCH}}"
LIBRARY="${LIBRARY:-${SKETCH}}"
########
######## Keyboard hardware definitions
@ -45,11 +44,6 @@ uname_S=$(uname -s 2>/dev/null || echo not)
uname_O=$(uname -o 2>/dev/null || echo not)
find_max_prog_size() {
MAX_PROG_SIZE=${MAX_PROG_SIZE:-$(get_arduino_pref 'upload.maximum_size')}
}
find_device_vid_pid() {
VID=${VID:-$(get_arduino_pref 'build.vid')}
SKETCH_PID=${SKETCH_PID:-$(get_arduino_pref 'build.pid')}
@ -86,8 +80,7 @@ dump_arduino_prefs() {
find_device_port() {
find_device_vid_pid
DIR=$(dirname "$(readlink -f "$0")")
DEVICE_PORT_PROBER="${DIR}/find-device-port-linux-udev"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-linux-udev"
if [[ "${DEVICE_PORT}" = "" ]]; then
DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID})"
else
@ -103,9 +96,8 @@ reset_device_cmd() {
find_bootloader_ports() {
find_device_vid_pid
DIR=$(dirname "$(readlink -f "$0")")
BOOTLOADER_VID="${BOOTLOADER_VID:-${VID}}"
DEVICE_PORT_PROBER="${DIR}/find-device-port-linux-udev"
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})"
else
@ -113,19 +105,13 @@ find_bootloader_ports() {
fi
}
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}}"
}
MD5="md5sum"
if [ "${uname_S}" = "Darwin" ]; then
find_device_port() {
DIR=$(dirname "$0")
DEVICE_PORT_PROBER="${DIR}/find-device-port-macos"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-macos"
DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID})"
}
@ -141,9 +127,8 @@ if [ "${uname_S}" = "Darwin" ]; then
find_bootloader_ports() {
find_device_vid_pid
DIR=$(dirname "$0")
BOOTLOADER_VID="${BOOTLOADER_VID:-${VID}}"
DEVICE_PORT_PROBER="${DIR}/find-device-port-macos"
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})"
else
@ -154,8 +139,7 @@ if [ "${uname_S}" = "Darwin" ]; then
elif [ "${uname_S}" = "FreeBSD" ]; then
find_device_port() {
DIR=$(dirname "$0")
DEVICE_PORT_PROBER="${DIR}/find-device-port-freebsd"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-freebsd"
DEVICE_PORT="$(perl ${DEVICE_PORT_PROBER})"
}
@ -172,8 +156,7 @@ elif [ "${uname_S}" = "FreeBSD" ]; then
ARDUINO_BUILDER="${ARDUINO_BUILDER:-/usr/local/bin/arduino-builder}"
find_bootloader_ports() {
DIR=$(dirname "$0")
DEVICE_PORT_PROBER="${DIR}/find-device-port-freebsd"
DEVICE_PORT_PROBER="${KALEIDOSCPE_BIN_DIR}/find-device-port-freebsd"
DEVICE_PORT_BOOTLOADER="$(perl ${DEVICE_PORT_PROBER})"
}
@ -209,14 +192,11 @@ elif [ "${uname_O}" = "Cygwin" ]; then
ARDUINO_PATH="$(realpath --relative-to=./ ${ARDUINO_PATH})"
ARDUINO_PACKAGE_PATH="$(realpath --relative-to=./ ${ARDUINO_PACKAGE_PATH})"
ARDUINO_LOCAL_LIB_PATH="$(realpath --relative-to=./ ${ARDUINO_LOCAL_LIB_PATH})"
ROOT="$(realpath --relative-to=./ ${ROOT})"
export ROOT
TMPDIR="$(realpath --relative-to=./ ${ARDUINO_PATH})"
find_device_port() {
find_device_vid_pid
DIR=$(dirname "$0")
DEVICE_PORT_PROBER="${DIR}/find-device-port-windows.ps1"
DEVICE_PORT_PROBER="${KALEIDOSCOPE_BIN_DIR}/find-device-port-windows.ps1"
DEVICE_PORT="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID} -Format Cygwin)"
DEVICE_COM_PORT="$(powershell -noprofile -executionpolicy bypass ${DEVICE_PORT_PROBER} ${VID} ${SKETCH_PID} -Format COM)"
}
@ -227,9 +207,8 @@ elif [ "${uname_O}" = "Cygwin" ]; then
find_bootloader_ports() {
find_device_vid_pid
DIR=$(dirname "$0")
BOOTLOADER_VID="${BOOTLOADER_VID:-${VID}}"
DEVICE_PORT_PROBER="${DIR}/find-device-port-windows.ps1"
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)"
}

Loading…
Cancel
Save