Re: [PATCH] Makefile: dedup git-ls-files output to prevent duplicate targets
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 26, 2022, 06:23 UTC
- Message-ID
- <xmqq5yls3j8i.fsf@gitster.g>
- In-Reply-To
- <CANYiYbEcNJ7+7XW-8-v+p8q=aiOP9RJYvST8ethVjxVdNugR5Q@mail.gmail.com>
Jiang Xin <worldhello.net@gmail.com> writes:
Show 21 quoted lines
>> ) >> -FOUND_SOURCE_FILES := $(shell $(SOURCES_CMD)) >> +FOUND_SOURCE_FILES := $(sort $(shell $(SOURCES_CMD))) >> >> FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES)) >> FOUND_H_SOURCES = $(filter %.h,$(FOUND_SOURCE_FILES)) >> > > If I disabled the git-ls-files command like below, > > @@ -846,7 +846,7 @@ generated-hdrs: $(GENERATED_H) >... > This is because the three generated header files (defined in > $(GENERATED_H)) are also included in the result of "SOURCES_CMD". We > can fix this by sorting LOCALIZED_C: > > -LOCALIZED_C = $(FOUND_C_SOURCES) $(FOUND_H_SOURCES) $(SCALAR_SOURCES) \ > - $(GENERATED_H) > +LOCALIZED_C = $(sort $(FOUND_C_SOURCES) $(FOUND_H_SOURCES) > $(SCALAR_SOURCES) \ > + $(GENERATED_H))
If you make FOUND_SOURCE_FILES unique upfront, the at least there wouldn't be any duplicates there. Do you mean that some of what is in FOUND_SOURCE_FILES appear in either SCALAR_SOURCES or GENERATED_H?
If not, I think deduplicating near the source of the issue, i.e.
FOUND_SOURCE_FILES := $(sort $(shell $(SOURCES_CMD)))
may be sufficient. Deduplicating near the consumer, like LOCALIZED_C, may force us to dedup all the consumers of it (e.g. LOCALIZED_C is not the sole consumer of FOUND_C_SOURCES; you'd need to sort the input to COCCI_SOURCES, for example).
Thanks.