From 7e43c91eb2cd77f2ce6cfa0ca98d780b26418fd3 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 16 Nov 2020 00:35:52 -0800 Subject: [PATCH] Finish migrating everything to the makefile, even if the output is ugly --- bin/kaleidoscope-builder | 119 -------------------------------------- etc/sketch-arduino-cli.mk | 28 +++++++-- 2 files changed, 24 insertions(+), 123 deletions(-) delete mode 100755 bin/kaleidoscope-builder diff --git a/bin/kaleidoscope-builder b/bin/kaleidoscope-builder deleted file mode 100755 index a3b0703d..00000000 --- a/bin/kaleidoscope-builder +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash -# kaleidoscope-builder - Kaleidoscope helper tool -# Copyright (C) 2017-2018 Keyboard.io, Inc. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, version 3. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see . - -set -e - -###### -###### Build and output configuration -###### - - -_run_arduino_cli() { - "${ARDUINO_CLI}" "$@" -} - - -_arduino_prop() { - pref=$1 - # Strip the preference name. And then strip leading and trailing quotations - _arduino_props | grep --max-count=1 "${pref}=" | sed -e s/^.*"${pref}"=// -e 's/^"//' -e 's/"$//' -} - -_arduino_props() { - if [ "x${_ARDUINO_PREFS}x" == "xx" ]; then - _ARDUINO_PREFS=$(_run_arduino_cli --fqbn "${FQBN}" compile --show-properties "${SKETCH_FILE_PATH}") - fi - echo "$_ARDUINO_PREFS" -} - - -_find_sketch() { - if [ -z "${SKETCH_FILE_PATH}" ] || [ ! -f "${SKETCH_FILE_PATH}" ]; then - # Didn't find a sketch - echo "I couldn't find your sketch (.ino file)" >&2 - exit 1 - fi -} - - - -cmd_flash() { - #TODO (arduino team) I'd love to do this with their json output - #but it's short some of the data we kind of need - port=$(_run_arduino_cli board list --format=text | grep "$FQBN" |cut -d' ' -f 1) - - flashing_instructions=$(_arduino_prop 'build.flashing_instructions') - : "${flashing_instructions:="If your keyboard needs you to do something to put it in flashing mode, do that now."}" - - printf '%b\n\n' "${flashing_instructions}" - echo "When you're ready to proceed, press 'Enter'." - - # We do not want to permit line continuations here. We just want a newline. - - # shellcheck disable=SC2162 - read - - _run_arduino_cli upload --fqbn "${FQBN}" --port "${port}" "${ARDUINO_VERBOSE}" -} - - - - -cmd_help() { - cat <<-EOF - Usage: $0 SKETCH commands... - - Runs all of the commands in the context of the Sketch. - - Available commands: - - help - This help screen. - - compile - Compiles the sketch. - - clean - Cleans up the output directory. - - size-map - Displays the size map for the sketch. - - disassemble - Decompile the sketch. - - flash - Flashes the firmware using avrdude. - - EOF -} - -if [ $# -lt 1 ]; then - cmd_help - exit 1 -fi - -# shellcheck disable=SC1090 - -if [ $# -eq 1 ]; then - cmd="$(echo "$1" | tr '-' '_')" - "cmd_${cmd}" - exit $? -else - "You passed more than two arguments to $0" - help - exit 1 -/ -fi diff --git a/etc/sketch-arduino-cli.mk b/etc/sketch-arduino-cli.mk index b4ca451f..3872b383 100644 --- a/etc/sketch-arduino-cli.mk +++ b/etc/sketch-arduino-cli.mk @@ -87,6 +87,16 @@ sketch_dir_candidates = $(sketch_dir) src/ . sketch_exists_p = $(realpath $(wildcard $(dir)/$(SKETCH_FILE_NAME))) +export FQBN := $(call _arduino_prop,build.fqbn) + +# Flashing related config +port = $(shell $(ARDUINO_CLI) board list --format=text | grep $(FQBN) |cut -d' ' -f 1) +flashing_instructions = $(call _arduino_prop,build.flashing_instructions) +ifeq ($(flashing_instructions),) +flashing_instructions = "If your keyboard needs you to do something to put it in flashing mode, do that now." +endif + + export BOOTLOADER_PATH := $(call _arduino_prop,runtime.platform.path)/bootloaders/$(call _arduino_prop,bootloader.file) # Find the path of the sketch file @@ -217,10 +227,20 @@ else cp "${BUILD_PATH}/${SKETCH_FILE_NAME}.a" "${LIB_FILE_PATH}" ln -sf "${OUTPUT_FILE_PREFIX}.a" "${OUTPUT_PATH}/${SKETCH_BASE_NAME}-latest.a" endif - @echo "Build artifacts can be found in ${BUILD_PATH}" - + $(info Build artifacts can be found in ${BUILD_PATH}) -%: - $(KALEIDOSCOPE_BIN_DIR)/kaleidoscope-builder $@ +#TODO (arduino team) I'd love to do this with their json output +#but it's short some of the data we kind of need +flash: +ifeq ($(port),) + $(info Unable to detect keyboard serial port.) + #@exit 1 +endif + $(info $(flashing_instructions)) + $(info) + $(info When you're ready to proceed, press 'Enter'.) + $(info) + @$(shell read) + @$(ARDUINO_CLI) upload --fqbn $(FQBN) --port $(port) ${ARDUINO_VERBOSE}