diff --git a/testing/makefiles/libcommon.mk b/testing/makefiles/libcommon.mk index 65e5c43b..0dc6cd8c 100644 --- a/testing/makefiles/libcommon.mk +++ b/testing/makefiles/libcommon.mk @@ -1,11 +1,10 @@ -top_dir := $(dir $(lastword ${MAKEFILE_LIST}))../.. -build_dir := ${top_dir}/_build +mkfile_dir := $(dir $(lastword ${MAKEFILE_LIST})) +top_dir := $(abspath $(mkfile_dir)../..) -ifndef BOARD_HARDWARE_PATH -bundle_path = ${top_dir}/.. -else -bundle_path = ${BOARD_HARDWARE_PATH}/keyboardio/avr/libraries -endif +include $(mkfile_dir)/shared.mk + + +build_dir := ${top_dir}/_build LIB_DIR := ${build_dir}/lib OBJ_DIR := ${build_dir}/obj @@ -16,36 +15,27 @@ BARE_CXX_FILES := $(foreach path,${CXX_FILES},$(notdir ${path})) OBJ_FILES := $(patsubst %.cpp,${OBJ_DIR}/%.o,$(BARE_CXX_FILES)) LIB_FILE := libcommon.a +ifneq ($(KALEIDOSCOPE_CCACHE),) +COMPILER_WRAPPER := ccache +endif + + .PHONY: all +DEFAULT_GOAL: all + all: ${OBJ_FILES} ${LIB_DIR}/${LIB_FILE} ${LIB_DIR}/${LIB_FILE}: ${OBJ_FILES} @install -d "${LIB_DIR}" - ar rcs "${LIB_DIR}/${LIB_FILE}" ${OBJ_FILES} + $(call _arduino_prop,compiler.ar.cmd) $(call _arduino_prop,compiler.ar.flags) "${LIB_DIR}/${LIB_FILE}" ${OBJ_FILES} ${OBJ_DIR}/%.o: ${top_dir}/testing/%.cpp ${H_FILES} - @echo "compile $@" + $(info compile $@) @install -d "${OBJ_DIR}" - g++ -o "$@" -c \ - -std=c++14 \ - -I${top_dir} \ - -I${top_dir}/src \ - -I${bundle_path}/../../virtual/cores/arduino \ - -I${bundle_path}/Kaleidoscope-HIDAdaptor-KeyboardioHID/src \ - -I${bundle_path}/KeyboardioHID/src \ - -I${top_dir}/testing/googletest/googlemock/include \ - -I${top_dir}/testing/googletest/googletest/include \ - -DARDUINO=10607 \ - -DARDUINO_ARCH_VIRTUAL \ - -DARDUINO_AVR_MODEL01 \ - '-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Model01.h"' \ - -DKALEIDOSCOPE_VIRTUAL_BUILD=1 \ - -DKEYBOARDIOHID_BUILD_WITHOUT_HID=1 \ - -DUSBCON=dummy \ - -DARDUINO_ARCH_AVR=1 \ - '-DUSB_PRODUCT="Model 01"' \ - $< + $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "$@" -c -std=c++14 ${shared_includes} ${shared_defines} $< clean: - rm -rf "${build_dir}" + rm -rf -- "${build_dir}" + +include $(top_dir)/etc/makefiles/arduino-cli.mk diff --git a/testing/makefiles/shared.mk b/testing/makefiles/shared.mk new file mode 100644 index 00000000..9c4b2e32 --- /dev/null +++ b/testing/makefiles/shared.mk @@ -0,0 +1,21 @@ +arduino_platform_path := ${ARDUINO_DIRECTORIES_USER}/hardware/keyboardio/virtual/ + +shared_defines := \ + -DARDUINO=10607 \ + -DARDUINO_ARCH_VIRTUAL \ + -DKALEIDOSCOPE_VIRTUAL_BUILD=1 \ + -DKEYBOARDIOHID_BUILD_WITHOUT_HID=1 \ + -DUSBCON=dummy \ + -DARDUINO_ARCH_AVR=1 \ + -DARDUINO_AVR_MODEL01 \ + '-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Model01.h"' \ + '-DUSB_PRODUCT="Model 01"' + +shared_includes := \ + -I${top_dir} \ + -I${top_dir}/src \ + -I${arduino_platform_path}/cores/arduino \ + -I${arduino_platform_path}/libraries/KeyboardioHID/src \ + -I${top_dir}/testing/googletest/googlemock/include \ + -I${top_dir}/testing/googletest/googletest/include \ + diff --git a/testing/makefiles/testcase.mk b/testing/makefiles/testcase.mk index f28aff9f..67f5158d 100644 --- a/testing/makefiles/testcase.mk +++ b/testing/makefiles/testcase.mk @@ -1,5 +1,7 @@ -top_dir := $(dir $(lastword ${MAKEFILE_LIST}))../.. +mkfile_dir := $(dir $(lastword ${MAKEFILE_LIST})) +top_dir := $(abspath $(mkfile_dir)../..) +include $(mkfile_dir)/shared.mk build_dir := ${top_dir}/_build/${testcase} @@ -9,6 +11,13 @@ BIN_DIR := ${build_dir}/bin COMMON_LIB_DIR := ${top_dir}/_build/lib +include $(top_dir)/etc/makefiles/arduino-cli.mk + +ifneq ($(KALEIDOSCOPE_CCACHE),) +COMPILER_WRAPPER := ccache +endif + + SRC_DIR := test SKETCH_FILE=$(wildcard *.ino) @@ -28,48 +37,31 @@ TEST_FILES += $(SRC_DIR)/generated-testcase.cpp endif endif +.DEFAULT_GOAL := build TEST_OBJS=$(patsubst $(SRC_DIR)/%.cpp,${OBJ_DIR}/%.o,$(TEST_FILES)) -ifndef BOARD_HARDWARE_PATH -bundle_path = ${top_dir}/.. -else -bundle_path = ${BOARD_HARDWARE_PATH}/keyboardio/avr/libraries -endif - build: ${BIN_DIR}/${BIN_FILE} compile-sketch all: run run: ${BIN_DIR}/${BIN_FILE} - @echo "run" "${BIN_DIR}/${BIN_FILE}" -t -q ${BIN_DIR}/${BIN_FILE}: ${TEST_OBJS} # We force sketch recompiliation because otherwise, make won't pick up changes to...anything on the arduino side -compile-sketch: - @echo "link" - install -d "${BIN_DIR}" "${LIB_DIR}" - env LIBONLY=yes \ - LOCAL_CFLAGS='"-I$(shell pwd)"' \ - OUTPUT_PATH="${LIB_DIR}" \ - VERBOSE=${VERBOSE} \ - ARCH=virtual DEFAULT_SKETCH=sketch \ +compile-sketch: ${TEST_OBJS} + @install -d "${BIN_DIR}" "${LIB_DIR}" + env LIBONLY=yes VERBOSE=${VERBOSE} \ + OUTPUT_PATH="${LIB_DIR}" \ $(MAKE) -f ${top_dir}/testing/makefiles/delegate.mk compile - g++ -o "${BIN_DIR}/${BIN_FILE}" \ - -lpthread \ - -g \ - -w \ - ${TEST_OBJS} \ - -L"${COMMON_LIB_DIR}" \ - -lcommon \ + $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "${BIN_DIR}/${BIN_FILE}" \ + -lpthread -g -w ${TEST_OBJS} \ + -L"${COMMON_LIB_DIR}" -lcommon \ "${LIB_DIR}/${LIB_FILE}" \ -L"${top_dir}/testing/googletest/build/lib" \ - -lgtest \ - -lgmock \ - -lpthread \ - -lm + -lgtest -lgmock -lpthread -lm # If we have a test.ktest file, it should be processed into a c++ testcase @@ -79,37 +71,20 @@ generate-testcase: $(if $(HAS_KTEST_FILE), ${SRC_DIR}/generated-testcase.cpp) ${SRC_DIR}/generated-testcase.cpp: test.ktest ifneq (,$(wildcard test.ktest)) - @echo "Compiling ${testcase} ktest script into ${SRC_DIR}/generated-testcase.cpp" - install -d "${SRC_DIR}" + $(info Compiling ${testcase} ktest script into ${SRC_DIR}/generated-testcase.cpp) + @install -d "${SRC_DIR}" perl ${top_dir}/testing/bin/ktest-to-cxx \ --ktest=test.ktest \ --cxx=${SRC_DIR}/generated-testcase.cpp endif ${OBJ_DIR}/%.o: ${SRC_DIR}/%.cpp - @echo "compile $@" - install -d "${OBJ_DIR}" - g++ -o "$@" -c \ - -std=c++14 \ - -I${top_dir} \ - -I${top_dir}/src \ - -I${bundle_path}/../../virtual/cores/arduino \ - -I${bundle_path}/KeyboardioHID/src \ - -I${top_dir}/testing/googletest/googlemock/include \ - -I${top_dir}/testing/googletest/googletest/include \ - -DARDUINO=10607 \ - -DARDUINO_ARCH_VIRTUAL \ - -DARDUINO_AVR_MODEL01 \ - '-DKALEIDOSCOPE_HARDWARE_H="Kaleidoscope-Hardware-Model01.h"' \ - -DKALEIDOSCOPE_VIRTUAL_BUILD=1 \ - -DKEYBOARDIOHID_BUILD_WITHOUT_HID=1 \ - -DUSBCON=dummy \ - -DARDUINO_ARCH_AVR=1 \ - '-DUSB_PRODUCT="Model 01"' \ - $< + @install -d "${OBJ_DIR}" + $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "$@" -c -std=c++14 \ + ${shared_includes} ${shared_defines} $< clean: - rm -f "${SRC_DIR}/generated-testcase.cpp" - rm -rf "${build_dir}" + rm -f -- "${SRC_DIR}/generated-testcase.cpp" + rm -rf -- "${build_dir}" .PHONY: clean run all build diff --git a/tests/Makefile b/tests/Makefile index bb1b1e1a..bc84a06e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,39 +1,56 @@ -top_dir := $(abspath $(dir $(lastword ${MAKEFILE_LIST}))..) -build_dir := ${top_dir}/_build + +tests_dir := $(abspath $(dir $(lastword ${MAKEFILE_LIST}))) + +top_dir := $(abspath $(tests_dir)/..) + +build_dir := ${top_dir}/_build + LIB_DIR := ${build_dir}/lib libcommon_a := ${top_dir}/_build/lib/libcommon.a -TEST_PATH ?= tests/ +TEST_PATH ?= ./ + +export FQBN ?= keyboardio:virtual:model01 + +TESTS ?= $(shell cd $(tests_dir); find ${TEST_PATH} -name '*.ino' -exec dirname {} \;) + + +# If we start off in tests to run make all, the sketch makefiles guess the wrong location for +# Kaliedoscope's makefiles + +KALEIDOSCOPE_ETC_DIR ?= $(top_dir)/etc + + +.PHONY: clean cmake-clean all googletest generate-testcases -TESTS ?= $(shell find ${top_dir}/${TEST_PATH} -name '*.ino' -exec dirname {} \;) -.PHONY: clean cmake-clean all googletest generate-testcases: @for test in ${TESTS}; do \ - ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $${test} top_dir=${top_dir} testcase=$${test} generate-testcase; \ + ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $${test} testcase=$${test} generate-testcase; \ done -all: ${TESTS} +all: ${TESTS} run-all + +run-all: ${TESTS} @for test in ${TESTS}; do \ - ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $${test} top_dir=${top_dir} testcase=$${test} run; \ + ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $${test} testcase=$${test} run; \ done || exit 1 cmake-clean: - rm -rf "${top_dir}/testing/googletest/build/*" + rm -rf "${top_dir}"/testing/googletest/build/* clean: cmake-clean -# ${top_dir}/testing/googletest/build/Makefile @for test in ${TESTS}; do \ - ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $${test} top_dir=${top_dir} testcase=$${test} clean; \ + ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $${test} testcase=$${test} clean; \ done - - rm -rf "${build_dir}/*" + rm -rf "${build_dir}"/* googletest: ${top_dir}/testing/googletest/build/Makefile cd ${top_dir}/testing/googletest/build && $(MAKE) ${top_dir}/testing/googletest/build/Makefile: + $(info googletest Makefile is being remade) install -d ${top_dir}/testing/googletest/build && cd ${top_dir}/testing/googletest/build && cmake .. ${libcommon_a}: @@ -43,7 +60,7 @@ Makefile: @: ${TESTS}: ${libcommon_a} googletest - ${MAKE} -f ${top_dir}/testing/makefiles/testcase.mk -C $@ top_dir=${top_dir} testcase=$@ + ${MAKE} -f ${top_dir}/testing/makefiles/testcase.mk -C $@ testcase=$@ build %+run: - ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $* top_dir=${top_dir} testcase=$* run + ${MAKE} -s -f ${top_dir}/testing/makefiles/testcase.mk -C $* testcase=$* run