git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PoC] coccinelle: make Coccinelle-related make targets more fine-grained

From
René Scharfe <l.s.r@web.de>
Date
Aug 2, 2018, 13:24 UTC
Message-ID
<edd896c5-9d73-7771-984e-f7443b74d01f@web.de>
In-Reply-To
<20180802115522.16107-1-szeder.dev@gmail.com>
Am 02.08.2018 um 13:55 schrieb SZEDER Gábor:
Show 24 quoted lines
> Let's add a bit of Makefile metaprogramming to generate finer-grained
> make targets applying one semantic patch to only a single source file,
> and specify these as dependencies of the targets applying one semantic
> patch to all source files.  This way that shell loop can be avoided,
> semantic patches will only be applied to changed source files, and the
> same semantic patch can be applied in parallel to multiple source
> files.  The only remaining sequential part is aggregating the
> suggested transformations from the individual targets into a single
> patch file, which is comparatively cheap (especially since ideally
> there aren't any suggestions).
> 
> This change brings spectacular speedup in the scenario described in
> point (1) above.  When the results of a previous 'make coccicheck' are
> there, the time needed to run
> 
>    touch apply.c ; time make -j4 coccicheck
> 
> went from 3m42s to 1.848s, which is just over 99% speedup, yay!, and
> 'apply.c' is the second longest source file in our codebase.  In the
> scenario in point (2), running
> 
>    touch contrib/coccinelle/array.cocci ; time make -j4 coccicheck
> 
> went from 56.364s to 35.883s, which is ~36% speedup.
Awesome!
Show 17 quoted lines
> Unfortunately, this new approach has some disadvantages compared to
> the current situation:
> 
>    - [RFC]
>      With this patch 'make coccicheck's output will look like this
>      ('make' apparently doesn't iterate over semantic patches in
>      lexicographical order):
> 
>        SPATCH commit.cocci              abspath.c
>        SPATCH commit.cocci              advice.c
>        <... lots of lines ...>
>        SPATCH array.cocci               http-walker.c
>        SPATCH array.cocci               remote-curl.c
> 
>      which means that the number of lines in the output grows from
>      "Nr-of-semantic-patches" to "Nr-of-semantic-patches *
>      Nr-of-source-files".

The output is mostly interesting to see if something is happening, to see if some semantic patch generated a non-empty diff and to get error details. We have ca. 400 .c files and 8 .cocci files -- that means the lines would fill up my scroll-back buffer. Hmm.

Would it be possible to have a phony target (or directory) per source file that just prints a line and depends on the individual file+cocci targets? (I don't know much make, you probably thought about it already.)

Or to select one random .cocci file (let's say the first one) and only print SPATCH lines for this one (without mentioning its name)? (A dirty hack..)

Show 50 quoted lines
> ---
>   Makefile                      | 52 ++++++++++++++++++++++++-----------
>   contrib/coccinelle/.gitignore |  3 +-
>   2 files changed, 38 insertions(+), 17 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index d616c04125..f516dd93d1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2674,25 +2674,44 @@ COCCI_SOURCES = $(filter-out sha1collisiondetection/%,$(C_SOURCES))
>   else
>   COCCI_SOURCES = $(filter-out sha1dc/%,$(C_SOURCES))
>   endif
> +COCCI_SEM_PATCHES = $(wildcard contrib/coccinelle/*.cocci)
>   
> -%.cocci.patch: %.cocci $(COCCI_SOURCES)
> -	@echo '    ' SPATCH $<; \
> -	ret=0; \
> -	for f in $(COCCI_SOURCES); do \
> -		$(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
> -			{ ret=$$?; break; }; \
> -	done >$@+ 2>$@.log; \
> -	if test $$ret != 0; \
> +define cocci_template
> +$(cocci_sem_patch)_dirs := $$(addprefix $(cocci_sem_patch).patches/,$$(sort $$(dir $$(COCCI_SOURCES))))
> +
> +$$($(cocci_sem_patch)_dirs):
> +	@mkdir -p $$@
> +
> +# e.g. 'contrib/coccinelle/strbuf.cocci.patches/builtin/commit.c.patch'
> +# Applies one semantic patch to _one_ source file.
> +$(cocci_sem_patch).patches/%.patch: % $(cocci_sem_patch)
> +	@printf '     SPATCH %-25s %s\n' $$(notdir $(cocci_sem_patch)) $$<; \
> +	if ! $$(SPATCH) --sp-file $(cocci_sem_patch) $$< $$(SPATCH_FLAGS) >$$@ 2>$$@.log; \
>   	then \
> -		cat $@.log; \
> +		rm -f $$@; \
> +		cat $$@.log; \
>   		exit 1; \
> -	fi; \
> -	mv $@+ $@; \
> -	if test -s $@; \
> -	then \
> -		echo '    ' SPATCH result: $@; \
>   	fi
> -coccicheck: $(addsuffix .patch,$(wildcard contrib/coccinelle/*.cocci))
> +
> +# e.g. 'contrib/coccinelle/strbuf.cocci.patch'
> +# Applies one semantic patch to _all_ source files.
> +$(cocci_sem_patch).patch: $(cocci_sem_patch) $$($(cocci_sem_patch)_dirs) $$(patsubst %,$(cocci_sem_patch).patches/%.patch,$(COCCI_SOURCES))

Are the dependencies correct (before and after the patch)? E.g. are all semantic patches reapplied after cache.h was changed? I think we ignore header files currently, and that becomes more of a problem if the check becomes more fine-grained.

René
Previous: SZEDER GáborNext: Jeff King
Message 19 of 31 in “Misc Coccinelle-related improvements”
  1. 0/5 Misc Coccinelle-related improvementsSZEDER Gábor, Jul 23, 2018
  2. 1/5 coccinelle: mark the 'coccicheck' make target as .PHONYSZEDER Gábor, Jul 23, 2018
  3. Derrick StoleeJul 23, 2018
  4. Junio C HamanoJul 23, 2018
  5. 2/5 coccinelle: use $(addsuffix) in 'coccicheck' make targetSZEDER Gábor, Jul 23, 2018
  6. Junio C HamanoJul 23, 2018
  7. 3/5 coccinelle: exclude sha1dc source files from static analysisSZEDER Gábor, Jul 23, 2018
  8. Eric SunshineJul 23, 2018
  9. SZEDER GáborJul 23, 2018
  10. Eric SunshineJul 23, 2018
  11. 4/5 coccinelle: put sane filenames into output patchesSZEDER Gábor, Jul 23, 2018
  12. Derrick StoleeJul 23, 2018
  13. 5/5 coccinelle: extract dedicated make target to clean Coccinelle's resultsSZEDER Gábor, Jul 23, 2018
  14. Derrick StoleeJul 23, 2018
  15. Duy NguyenJul 23, 2018
  16. René ScharfeJul 23, 2018
  17. Junio C HamanoJul 23, 2018
  18. [PoC] coccinelle: make Coccinelle-related make targets more fine-grainedSZEDER Gábor, Aug 2, 2018
  19. René ScharfeAug 2, 2018
  20. Jeff KingAug 2, 2018
  21. Jeff KingAug 2, 2018
  22. Jonathan NiederAug 3, 2018
  23. Jeff KingAug 3, 2018
  24. Jonathan NiederAug 5, 2018
  25. Eric SunshineAug 2, 2018
  26. Jeff KingAug 2, 2018
  27. Ævar Arnfjörð BjarmasonAug 2, 2018
  28. Julia LawallAug 3, 2018
  29. Jonathan NiederAug 3, 2018
  30. Julia LawallAug 3, 2018
  31. Julia LawallAug 3, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.