Improve dependency tracking, cleanup and presentation in test Makefiles.

pull/936/head
Jesse Vincent 4 years ago
parent 61f8fc5456
commit 6ef1570964
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -1,51 +1,41 @@
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
CXX_FILES := $(wildcard ${top_dir}/testing/*.cpp)
H_FILES := $(wildcard ${top_dir}/testing/*.h)
CXX_FILES := $(sort $(wildcard ${top_dir}/testing/*.cpp))
H_FILES := $(sort $(wildcard ${top_dir}/testing/*.h))
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}
$(QUIET) install -d "${LIB_DIR}"
$(QUIET) $(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 $@"
@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"' \
$<
$(info compile $@)
$(QUIET) install -d "${OBJ_DIR}"
$(QUIET) $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "$@" -c -std=c++14 ${shared_includes} ${shared_defines} $<
clean:
rm -rf "${build_dir}"
$(QUIET) rm -rf -- "${build_dir}"
include $(top_dir)/etc/makefiles/arduino-cli.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 \

@ -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,13 +11,20 @@ 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)
BIN_FILE=$(subst .ino,,$(SKETCH_FILE))
LIB_FILE=${BIN_FILE}-latest.a
TEST_FILES=$(wildcard $(SRC_DIR)/*.cpp)
TEST_FILES=$(sort $(wildcard $(SRC_DIR)/*.cpp))
# If we have a ktest file and no generated testcase,
# we want to turn it into a generated testcase
@ -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
$(QUIET) "${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)"' \
compile-sketch: ${TEST_OBJS}
@install -d "${BIN_DIR}" "${LIB_DIR}"
$(QUIET) env LIBONLY=yes VERBOSE=${VERBOSE} \
OUTPUT_PATH="${LIB_DIR}" \
VERBOSE=${VERBOSE} \
ARCH=virtual DEFAULT_SKETCH=sketch \
$(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 \
$(QUIET) $(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}"
perl ${top_dir}/testing/bin/ktest-to-cxx \
$(info Compiling ${testcase} ktest script into ${SRC_DIR}/generated-testcase.cpp)
$(QUIET) install -d "${SRC_DIR}"
$(QUIET) 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"' \
$<
$(QUIET) install -d "${OBJ_DIR}"
$(QUIET) $(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}"
$(QUIET) rm -f -- "${SRC_DIR}/generated-testcase.cpp"
$(QUIET) rm -rf -- "${build_dir}"
.PHONY: clean run all build

@ -1,39 +1,56 @@
top_dir := $(abspath $(dir $(lastword ${MAKEFILE_LIST}))..)
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

Loading…
Cancel
Save