Makefile: copy contrib/coccinelle/*.cocci to build/

Change the "coccinelle" rule so that we first copy the *.cocci source in e.g. "contrib/coccinelle/strbuf.cocci" to ".build/contrib/coccinelle/strbuf.cocci" before operating on it. For now this serves as a rather pointless indirection, but prepares us for the subsequent commit where we'll be able to inject generated *.cocci files. Having the entire dependency tree live inside .build/* simplifies both the globbing we'd need to do, and any "clean" rules. It will also help for future targets which will want to act on the generated patches or the logs, e.g. targets to alert if we can't parse certain files (or, less so than usual) with "spatch", and e.g. a replacement for "ci/run-static-analysis.sh". Such a replacement won't care about placing the patches in the in-tree, only whether they're "OK" (and about the diff). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Ævar Arnfjörð Bjarmason committed Nov 1, 2022 at 23:35 UTC 202086b85c6591e99ee18e31277786d43f2804a2
2 files changed +22 -6
Makefile
+21 -6
@@ -3159,8 +3159,11 @@ check: $(GENERATED_H)
3159 fi
3160
3161 COCCI_GLOB = $(wildcard contrib/coccinelle/*.cocci)
3162 -COCCI_RULES = $(COCCI_GLOB)
3163 -COCCI_NAMES = $(COCCI_RULES:contrib/coccinelle/%.cocci=%)
3162 +COCCI_RULES_TRACKED = $(COCCI_GLOB:%=.build/%)
3163 +COCCI_RULES =
3164 +COCCI_RULES += $(COCCI_RULES_TRACKED)
3165 +COCCI_NAMES =
3166 +COCCI_NAMES += $(COCCI_RULES:.build/contrib/coccinelle/%.cocci=%)
3167
3168 COCCICHECK_PENDING = $(filter %.pending.cocci,$(COCCI_RULES))
3169 COCCICHECK = $(filter-out $(COCCICHECK_PENDING),$(COCCI_RULES))
@@ -3168,6 +3171,9 @@ COCCICHECK = $(filter-out $(COCCICHECK_PENDING),$(COCCI_RULES))
3171 COCCICHECK_PATCHES = $(COCCICHECK:%=%.patch)
3172 COCCICHECK_PATCHES_PENDING = $(COCCICHECK_PENDING:%=%.patch)
3173
3174 +COCCICHECK_PATCHES_INTREE = $(COCCICHECK_PATCHES:.build/%=%)
3175 +COCCICHECK_PATCHES_PENDING_INTREE = $(COCCICHECK_PATCHES_PENDING:.build/%=%)
3176 +
3177 # It's expensive to compute the many=many rules below, only eval them
3178 # on $(MAKECMDGOALS) that match these $(COCCI_RULES)
3179 COCCI_RULES_GLOB =
@@ -3175,10 +3181,16 @@ COCCI_RULES_GLOB += cocci%
3181 COCCI_RULES_GLOB += .build/contrib/coccinelle/%
3182 COCCI_RULES_GLOB += $(COCCICHECK_PATCHES)
3183 COCCI_RULES_GLOB += $(COCCICHEC_PATCHES_PENDING)
3184 +COCCI_RULES_GLOB += $(COCCICHECK_PATCHES_INTREE)
3185 +COCCI_RULES_GLOB += $(COCCICHECK_PATCHES_PENDING_INTREE)
3186 COCCI_GOALS = $(filter $(COCCI_RULES_GLOB),$(MAKECMDGOALS))
3187
3188 COCCI_TEST_RES = $(wildcard contrib/coccinelle/tests/*.res)
3189
3190 +$(COCCI_RULES_TRACKED): .build/% : %
3191 + $(call mkdir_p_parent_template)
3192 + $(QUIET_CP)cp $< $@
3193 +
3194 .build/contrib/coccinelle/FOUND_H_SOURCES: $(FOUND_H_SOURCES)
3195 $(call mkdir_p_parent_template)
3196 $(QUIET_GEN) >$@
@@ -3192,7 +3204,7 @@ define cocci-rule
3204 # $(1) = e.g. "free.cocci"
3205 # $(2) = e.g. "grep.c"
3206 # $(3) = e.g. "grep.o"
3195 -COCCI_$(1:contrib/coccinelle/%.cocci=%) += .build/$(1).patch/$(2)
3207 +COCCI_$(1:.build/contrib/coccinelle/%.cocci=%) += .build/$(1).patch/$(2)
3208 .build/$(1).patch/$(2): GIT-SPATCH-DEFINES
3209 .build/$(1).patch/$(2): $(if $(and $(SPATCH_USE_O_DEPENDENCIES),$(wildcard $(3))),$(3),.build/contrib/coccinelle/FOUND_H_SOURCES)
3210 .build/$(1).patch/$(2): $(1)
@@ -3220,12 +3232,15 @@ endif
3232
3233 define spatch-rule
3234
3223 -contrib/coccinelle/$(1).cocci.patch: $$(COCCI_$(1))
3235 +.build/contrib/coccinelle/$(1).cocci.patch: $$(COCCI_$(1))
3236 $$(QUIET_SPATCH_CAT)cat $$^ >$$@ && \
3237 if test -s $$@; \
3238 then \
3239 echo ' ' SPATCH result: $$@; \
3240 fi
3241 +contrib/coccinelle/$(1).cocci.patch: .build/contrib/coccinelle/$(1).cocci.patch
3242 + $$(QUIET_CP)cp $$< $$@
3243 +
3244 endef
3245
3246 ifdef COCCI_GOALS
@@ -3249,11 +3264,11 @@ $(COCCI_TEST_RES_GEN): .build/contrib/coccinelle/tests/%.res : contrib/coccinell
3264 coccicheck-test: $(COCCI_TEST_RES_GEN)
3265
3266 coccicheck: coccicheck-test
3252 -coccicheck: $(COCCICHECK_PATCHES)
3267 +coccicheck: $(COCCICHECK_PATCHES_INTREE)
3268
3269 # See contrib/coccinelle/README
3270 coccicheck-pending: coccicheck-test
3256 -coccicheck-pending: $(COCCICHECK_PATCHES_PENDING)
3271 +coccicheck-pending: $(COCCICHECK_PATCHES_PENDING_INTREE)
3272
3273 .PHONY: coccicheck coccicheck-pending
3274
shared.mak
+1
@@ -60,6 +60,7 @@ ifndef V
60 QUIET_AR = @echo ' ' AR $@;
61 QUIET_LINK = @echo ' ' LINK $@;
62 QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
63 + QUIET_CP = @echo ' ' CP $< $@;
64 QUIET_LNCP = @echo ' ' LN/CP $@;
65 QUIET_XGETTEXT = @echo ' ' XGETTEXT $@;
66 QUIET_MSGINIT = @echo ' ' MSGINIT $@;