From 24f935587a4a33f213f2165ffd0e3f937b555fff Mon Sep 17 00:00:00 2001 From: sfja Date: Mon, 23 Mar 2026 20:14:31 +0100 Subject: [PATCH] dont rebuild on test --- .github/workflows/verify.yml | 3 +++ backend/Makefile | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index cb246b9..b52a75b 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -28,4 +28,7 @@ jobs: - name: build working-directory: ./backend run: make all LD=clang++-22 CXX=clang++-22 + - name: test + working-directory: ./backend + run: make test diff --git a/backend/Makefile b/backend/Makefile index a43f801..f570284 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -33,26 +33,33 @@ obj_dir = $(build_dir)/obj src_dir = src test_dir = tests -sources = $(shell find $(src_dir) -name '*.cpp' -and -not -name 'main.cpp') -sources_with_main=$(sources) src/main.cpp +sources_without_main = $(shell find $(src_dir) -name '*.cpp' -and -not -name 'main.cpp') +main_source = src/main.cpp +sources = $(sources_without_main) $(main_source) -tests = $(shell find $(test_dir) -name '*.cpp') +objects_without_main = $(sources_without_main:%.cpp=$(obj_dir)/%.o) +main_object = $(main_source:%.cpp=$(obj_dir)/%.o) +objects = $(objects_without_main) $(main_object) -target=$(build_dir)/backend +target = $(build_dir)/backend -all: $(target) +test_sources = $(shell find $(test_dir) -name '*.cpp') +test_objects = $(test_sources:$(test_dir)/%.cpp=$(obj_dir)/$(test_dir)/%.o) +test_targets = $(test_sources:$(test_dir)/%.cpp=$(build_dir)/$(test_dir)/test_%) -$(target): $(sources_with_main:%.cpp=$(obj_dir)/%.o) +all: $(target) $(test_targets) + +$(target): $(objects) $(LD) -o $@ $(CXXFLAGS) $(LDFLAGS) $^ $(obj_dir)/%.o:%.cpp @mkdir -p $(dir $@) $(CXX) $< -c -o $@ -MMD -MP $(CXXFLAGS) -test: $(tests:tests/%.cpp=$(build_dir)/tests/test_%) +test: $(test_targets) printf "%s\n" $^ | xargs -I % sh -c 'echo "- %..." && ./% && echo "- %: OK" || (echo "- %: FAILED" && exit 1)' -$(build_dir)/tests/test_%: $(obj_dir)/tests/%.o $(sources:%.cpp=$(obj_dir)/%.o) +$(build_dir)/$(test_dir)/test_%: $(test_objects) $(objects_without_main) @mkdir -p $(dir $@) $(LD) -o $@ $(CXXFLAGS) $(LDFLAGS) $^ @@ -65,5 +72,5 @@ check: clean: rm -rf $(build_dir) --include $(sources_with_main:%.cpp=$(obj_dir)/%.d) $(tests:%.cpp=$(obj_dir)/%.d) +-include $(sources:%.cpp=$(obj_dir)/%.d) $(tests:%.cpp=$(obj_dir)/%.d)