Skip to content

Commit 428672a

Browse files
pks-tgitster
authored andcommitted
Makefile: stop listing test library objects twice
Whenever one adds another test library compilation unit one has to wire it up twice in the Makefile: once to append it to `UNIT_TEST_OBJS`, and once to append it to the `UNIT_TEST_PROGS` target. Ideally, we'd just reuse the `UNIT_TEST_OBJS` variable in the target so that we can avoid the duplication. But it also contains all the objects for our test programs, each of which contains a `cmd_main()`, and thus we cannot link them all into the target executable. Refactor the code such that `UNIT_TEST_OBJS` does not contain the unit test program objects anymore, which we can instead manually append to the `OBJECTS` variable. Like this, the former variable now only contains objects for test libraries and can thus be reused. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d8faf50 commit 428672a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,6 @@ UNIT_TEST_PROGRAMS += t-strvec
13561356
UNIT_TEST_PROGRAMS += t-trailer
13571357
UNIT_TEST_PROGRAMS += t-urlmatch-normalization
13581358
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
1359-
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))
13601359
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
13611360
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
13621361

@@ -2715,6 +2714,7 @@ OBJECTS += $(XDIFF_OBJS)
27152714
OBJECTS += $(FUZZ_OBJS)
27162715
OBJECTS += $(REFTABLE_OBJS) $(REFTABLE_TEST_OBJS)
27172716
OBJECTS += $(UNIT_TEST_OBJS)
2717+
OBJECTS += $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))
27182718

27192719
ifndef NO_CURL
27202720
OBJECTS += http.o http-walker.o remote-curl.o
@@ -3852,9 +3852,7 @@ $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
38523852
-Wl,--allow-multiple-definition \
38533853
$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
38543854

3855-
$(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o \
3856-
$(UNIT_TEST_DIR)/test-lib.o \
3857-
$(UNIT_TEST_DIR)/lib-oid.o \
3855+
$(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
38583856
$(GITLIBS) GIT-LDFLAGS
38593857
$(call mkdir_p_parent_template)
38603858
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \

0 commit comments

Comments
 (0)