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}))../.. mkfile_dir := $(dir $(lastword ${MAKEFILE_LIST}))
build_dir := ${top_dir}/_build top_dir := $(abspath $(mkfile_dir)../..)
ifndef BOARD_HARDWARE_PATH include $(mkfile_dir)/shared.mk
bundle_path = ${top_dir}/..
else
bundle_path = ${BOARD_HARDWARE_PATH}/keyboardio/avr/libraries build_dir := ${top_dir}/_build
endif
LIB_DIR := ${build_dir}/lib LIB_DIR := ${build_dir}/lib
OBJ_DIR := ${build_dir}/obj OBJ_DIR := ${build_dir}/obj
CXX_FILES := $(wildcard ${top_dir}/testing/*.cpp) CXX_FILES := $(sort $(wildcard ${top_dir}/testing/*.cpp))
H_FILES := $(wildcard ${top_dir}/testing/*.h) H_FILES := $(sort $(wildcard ${top_dir}/testing/*.h))
BARE_CXX_FILES := $(foreach path,${CXX_FILES},$(notdir ${path})) BARE_CXX_FILES := $(foreach path,${CXX_FILES},$(notdir ${path}))
OBJ_FILES := $(patsubst %.cpp,${OBJ_DIR}/%.o,$(BARE_CXX_FILES)) OBJ_FILES := $(patsubst %.cpp,${OBJ_DIR}/%.o,$(BARE_CXX_FILES))
LIB_FILE := libcommon.a LIB_FILE := libcommon.a
ifneq ($(KALEIDOSCOPE_CCACHE),)
COMPILER_WRAPPER := ccache
endif
.PHONY: all .PHONY: all
DEFAULT_GOAL: all
all: ${OBJ_FILES} ${LIB_DIR}/${LIB_FILE} all: ${OBJ_FILES} ${LIB_DIR}/${LIB_FILE}
${LIB_DIR}/${LIB_FILE}: ${OBJ_FILES} ${LIB_DIR}/${LIB_FILE}: ${OBJ_FILES}
@install -d "${LIB_DIR}" $(QUIET) install -d "${LIB_DIR}"
ar rcs "${LIB_DIR}/${LIB_FILE}" ${OBJ_FILES} $(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} ${OBJ_DIR}/%.o: ${top_dir}/testing/%.cpp ${H_FILES}
@echo "compile $@" $(info compile $@)
@install -d "${OBJ_DIR}" $(QUIET) install -d "${OBJ_DIR}"
g++ -o "$@" -c \ $(QUIET) $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "$@" -c -std=c++14 ${shared_includes} ${shared_defines} $<
-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"' \
$<
clean: 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} build_dir := ${top_dir}/_build/${testcase}
@ -9,13 +11,20 @@ BIN_DIR := ${build_dir}/bin
COMMON_LIB_DIR := ${top_dir}/_build/lib 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 SRC_DIR := test
SKETCH_FILE=$(wildcard *.ino) SKETCH_FILE=$(wildcard *.ino)
BIN_FILE=$(subst .ino,,$(SKETCH_FILE)) BIN_FILE=$(subst .ino,,$(SKETCH_FILE))
LIB_FILE=${BIN_FILE}-latest.a 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, # If we have a ktest file and no generated testcase,
# we want to turn it into a generated testcase # we want to turn it into a generated testcase
@ -28,48 +37,31 @@ TEST_FILES += $(SRC_DIR)/generated-testcase.cpp
endif endif
endif endif
.DEFAULT_GOAL := build
TEST_OBJS=$(patsubst $(SRC_DIR)/%.cpp,${OBJ_DIR}/%.o,$(TEST_FILES)) 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 build: ${BIN_DIR}/${BIN_FILE} compile-sketch
all: run all: run
run: ${BIN_DIR}/${BIN_FILE} run: ${BIN_DIR}/${BIN_FILE}
@echo "run" $(QUIET) "${BIN_DIR}/${BIN_FILE}" -t -q
"${BIN_DIR}/${BIN_FILE}" -t -q
${BIN_DIR}/${BIN_FILE}: ${TEST_OBJS} ${BIN_DIR}/${BIN_FILE}: ${TEST_OBJS}
# We force sketch recompiliation because otherwise, make won't pick up changes to...anything on the arduino side # We force sketch recompiliation because otherwise, make won't pick up changes to...anything on the arduino side
compile-sketch: compile-sketch: ${TEST_OBJS}
@echo "link" @install -d "${BIN_DIR}" "${LIB_DIR}"
install -d "${BIN_DIR}" "${LIB_DIR}" $(QUIET) env LIBONLY=yes VERBOSE=${VERBOSE} \
env LIBONLY=yes \ OUTPUT_PATH="${LIB_DIR}" \
LOCAL_CFLAGS='"-I$(shell pwd)"' \
OUTPUT_PATH="${LIB_DIR}" \
VERBOSE=${VERBOSE} \
ARCH=virtual DEFAULT_SKETCH=sketch \
$(MAKE) -f ${top_dir}/testing/makefiles/delegate.mk compile $(MAKE) -f ${top_dir}/testing/makefiles/delegate.mk compile
g++ -o "${BIN_DIR}/${BIN_FILE}" \ $(QUIET) $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "${BIN_DIR}/${BIN_FILE}" \
-lpthread \ -lpthread -g -w ${TEST_OBJS} \
-g \ -L"${COMMON_LIB_DIR}" -lcommon \
-w \
${TEST_OBJS} \
-L"${COMMON_LIB_DIR}" \
-lcommon \
"${LIB_DIR}/${LIB_FILE}" \ "${LIB_DIR}/${LIB_FILE}" \
-L"${top_dir}/testing/googletest/build/lib" \ -L"${top_dir}/testing/googletest/build/lib" \
-lgtest \ -lgtest -lgmock -lpthread -lm
-lgmock \
-lpthread \
-lm
# If we have a test.ktest file, it should be processed into a c++ testcase # 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 ${SRC_DIR}/generated-testcase.cpp: test.ktest
ifneq (,$(wildcard test.ktest)) ifneq (,$(wildcard test.ktest))
@echo "Compiling ${testcase} ktest script into ${SRC_DIR}/generated-testcase.cpp" $(info Compiling ${testcase} ktest script into ${SRC_DIR}/generated-testcase.cpp)
install -d "${SRC_DIR}" $(QUIET) install -d "${SRC_DIR}"
perl ${top_dir}/testing/bin/ktest-to-cxx \ $(QUIET) perl ${top_dir}/testing/bin/ktest-to-cxx \
--ktest=test.ktest \ --ktest=test.ktest \
--cxx=${SRC_DIR}/generated-testcase.cpp --cxx=${SRC_DIR}/generated-testcase.cpp
endif endif
${OBJ_DIR}/%.o: ${SRC_DIR}/%.cpp ${OBJ_DIR}/%.o: ${SRC_DIR}/%.cpp
@echo "compile $@" $(QUIET) install -d "${OBJ_DIR}"
install -d "${OBJ_DIR}" $(QUIET) $(COMPILER_WRAPPER) $(call _arduino_prop,compiler.cpp.cmd) -o "$@" -c -std=c++14 \
g++ -o "$@" -c \ ${shared_includes} ${shared_defines} $<
-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"' \
$<
clean: clean:
rm -f "${SRC_DIR}/generated-testcase.cpp" $(QUIET) rm -f -- "${SRC_DIR}/generated-testcase.cpp"
rm -rf "${build_dir}" $(QUIET) rm -rf -- "${build_dir}"
.PHONY: clean run all build .PHONY: clean run all build

@ -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 LIB_DIR := ${build_dir}/lib
libcommon_a := ${top_dir}/_build/lib/libcommon.a 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: generate-testcases:
@for test in ${TESTS}; do \ @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 done
all: ${TESTS} all: ${TESTS} run-all
run-all: ${TESTS}
@for test in ${TESTS}; do \ @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 done || exit 1
cmake-clean: cmake-clean:
rm -rf "${top_dir}/testing/googletest/build/*" rm -rf "${top_dir}"/testing/googletest/build/*
clean: cmake-clean clean: cmake-clean
# ${top_dir}/testing/googletest/build/Makefile
@for test in ${TESTS}; do \ @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 done
rm -rf "${build_dir}"/*
rm -rf "${build_dir}/*"
googletest: ${top_dir}/testing/googletest/build/Makefile googletest: ${top_dir}/testing/googletest/build/Makefile
cd ${top_dir}/testing/googletest/build && $(MAKE) cd ${top_dir}/testing/googletest/build && $(MAKE)
${top_dir}/testing/googletest/build/Makefile: ${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 .. install -d ${top_dir}/testing/googletest/build && cd ${top_dir}/testing/googletest/build && cmake ..
${libcommon_a}: ${libcommon_a}:
@ -43,7 +60,7 @@ Makefile:
@: @:
${TESTS}: ${libcommon_a} googletest ${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: %+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