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

Re: [PATCH v2 3/3] Makefile: simplify $(test_bindir_programs) rule by splitting it up

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 26, 2022, 19:14 UTC
Message-ID
<221026.86tu3qbd03.gmgdl@evledraar.gmail.com>
In-Reply-To
<xmqqr0yuh144.fsf@gitster.g>
On Wed, Oct 26 2022, Junio C Hamano wrote:
Show 11 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> -test_bindir_programs := $(patsubst %,bin-wrappers/%,$(BINDIR_PROGRAMS_NEED_X) $(BINDIR_PROGRAMS_NO_X) $(TEST_PROGRAMS_NEED_X))
>> +define cmd_munge_bin_wrappers_script
>> +sed \
>> +	-e $(call cmd_munge_script_sed_shell_path_arg) \
>> +	-e 's|@@BUILD_DIR@@|$(shell pwd)|' \
>> +	-e 's|@@PROG@@|$(2)$(1)$(3)|' \
>> +	<$< >$@ && \
>> +	chmod +x $@
>> +endef
[Re-arranged your question a bit for the reply...]
Show 5 quoted lines
> We've talked about relying on another feature of GNU make (which we
> already depend on) to automatically remove the target build artifact
> when a rule to build it fails, [...]  What happens when a rule that
> uses the above fails in the middle?  Do we correctly remove the
> half-built target?

Are you asking if "define"'s execute in some context outside the purview of rules, so that if you $(call) one from within a rule and it errors, that we won't clean up the file?

No, that won't happen, they'll be cleaned up properly. First, these are basically macros, but secondly it wouldn't matter if they weren't. E.g. you can execute an arbitrary program that happens to write to a file that matches your $@.

The only thing that matters is that we carry forward the exit code, which we do here. I.e. the "&&" after the $(call).

(Even then we'd still error properly, unless you ran "make -i" to ignore errors in the rule, the && is more in service of the $(QUIET_*) in our Makefile).

> but I see quite a many old world best practice pattern "generate >$@+
> && chmod +x $@+ && mv $@+ $@" still in today's Makefile.

Those are mostly there because nobody's cleaned them up, we don't need them anymore.

"Mostly" because one thing they still do is not replace the file until it's ready, we had a previous discussion on a related topic in reply to https://lore.kernel.org/git/patch-1.6-3330cdbccc0-20210329T161723Z-avarab@gmail.com/ (it didn't go in).

Show 11 quoted lines
>> -all:: $(test_bindir_programs)
>> +define bin_wrappers_template
>> +
>> +## bin_wrappers_template
>> +# 1 = $(1)
>> +# 2 = $(2)
>> +# 3 = $(3)
>> +# 4 = $(4)
>
> Whatever the above comment wants to convey to readers, it seems to
> fail to do so at least to me, while ...
I can drop them, FWIW I've found it quite handy to add these to ad-hoc
debug templates. E.g. you can run:
	
	$ make -f /dev/null -E '$(eval $(file <Makefile))' -E '$(error $(call bin_wrappers_template,a,b,c,d))'
	make: *** 
	## bin_wrappers_template
	# 1 = a
	# 2 = b
	# 3 = c
	# 4 = d
	BW_a = $(a:%=bin-wrappers/%)
	BIN_WRAPPERS += $(BW_a)
	all:: $(BW_a)
	$(BW_a): bin-wrappers/% : c%d
	$(BW_a): wrap-for-bin.sh
	        $(call mkdir_p_parent_template)
	        $(QUIET_GEN)$(call cmd_munge_bin_wrappers_script,b,c,d).  Stop.

So you see what the parameters expand to. Maybe just changing the heading to:

	## bin_wrappers_template: $(1..N) below for manual "$(error $(call ..." deubgging
?
Previous: Junio C HamanoNext: Junio C Hamano
Message 19 of 70 in “scalar: integrate into core Git”
  1. 0/8 scalar: integrate into core GitVictoria Dye via GitGitGadget, Aug 31, 2022
  2. 1/8 scalar: fix command documentation section headerVictoria Dye via GitGitGadget, Aug 31, 2022
  3. 3/8 git help: special-case `scalar`Johannes Schindelin via GitGitGadget, Aug 31, 2022
  4. 2/8 scalar: include in standard Git build & installationVictoria Dye via GitGitGadget, Aug 31, 2022
  5. Johannes SchindelinSep 1, 2022
  6. 0/5 Makefile: split up $(test_bindir_programs)Ævar Arnfjörð Bjarmason, Sep 1, 2022
  7. 1/5 Makefile: factor sed-powered '#!/bin/sh' munging into a variableÆvar Arnfjörð Bjarmason, Sep 1, 2022
  8. 2/5 Makefile: define "TEST_{PROGRAM,OBJS}" variables earlierÆvar Arnfjörð Bjarmason, Sep 1, 2022
  9. 3/5 Makefile: simplify $(test_bindir_programs) rule by splitting it upÆvar Arnfjörð Bjarmason, Sep 1, 2022
  10. 5/5 Makefile: fix "make clean && make bin-wrappers/$NAME" dependenciesÆvar Arnfjörð Bjarmason, Sep 1, 2022
  11. 4/5 Makefile: define bin-wrappers/% rules with a templateÆvar Arnfjörð Bjarmason, Sep 1, 2022
  12. Derrick StoleeSep 1, 2022
  13. Johannes SchindelinSep 2, 2022
  14. 0/3 Makefile: fix issues with bin-wrappers/% ruleÆvar Arnfjörð Bjarmason, Oct 26, 2022
  15. 1/3 Makefile: factor sed-powered '#!/bin/sh' munging into a variableÆvar Arnfjörð Bjarmason, Oct 26, 2022
  16. Junio C HamanoOct 26, 2022
  17. 3/3 Makefile: simplify $(test_bindir_programs) rule by splitting it upÆvar Arnfjörð Bjarmason, Oct 26, 2022
  18. Junio C HamanoOct 26, 2022
  19. Ævar Arnfjörð BjarmasonOct 26, 2022
  20. Junio C HamanoOct 26, 2022
  21. Ævar Arnfjörð BjarmasonOct 26, 2022
  22. 2/3 Makefile: define "TEST_{PROGRAM,OBJS}" variables earlierÆvar Arnfjörð Bjarmason, Oct 26, 2022
  23. Junio C HamanoOct 26, 2022
  24. Ævar Arnfjörð BjarmasonOct 26, 2022
  25. Junio C HamanoOct 26, 2022
  26. Jeff KingOct 28, 2022
  27. Ævar Arnfjörð BjarmasonOct 28, 2022
  28. 0/4 Makefile: untangle bin-wrappers/% rule complexityÆvar Arnfjörð Bjarmason, Oct 31, 2022
  29. 1/4 Makefile: factor sed-powered '#!/bin/sh' munging into a variableÆvar Arnfjörð Bjarmason, Oct 31, 2022
  30. 3/4 Makefile: rename "test_bindir_programs" variable, pre-declareÆvar Arnfjörð Bjarmason, Oct 31, 2022
  31. 2/4 Makefile: define "TEST_{PROGRAM,OBJS}" variables earlierÆvar Arnfjörð Bjarmason, Oct 31, 2022
  32. 4/4 Makefile: simplify $(test_bindir_programs) rule by splitting it upÆvar Arnfjörð Bjarmason, Oct 31, 2022
  33. Taylor BlauOct 31, 2022
  34. Ævar Arnfjörð BjarmasonNov 1, 2022
  35. 4/8 scalar: implement the `help` subcommandJohannes Schindelin via GitGitGadget, Aug 31, 2022
  36. Ævar Arnfjörð BjarmasonAug 31, 2022
  37. Victoria DyeSep 1, 2022
  38. Johannes SchindelinSep 1, 2022
  39. Johannes SchindelinSep 1, 2022
  40. 5/8 scalar-clone: add test coverageVictoria Dye via GitGitGadget, Aug 31, 2022
  41. Johannes SchindelinSep 1, 2022
  42. Victoria DyeSep 1, 2022
  43. Johannes SchindelinSep 2, 2022
  44. Junio C HamanoSep 2, 2022
  45. 7/8 t/perf: add 'GIT_PERF_USE_SCALAR' run optionVictoria Dye via GitGitGadget, Aug 31, 2022
  46. Johannes SchindelinSep 1, 2022
  47. Victoria DyeSep 2, 2022
  48. Johannes SchindelinSep 2, 2022
  49. 6/8 t/perf: add Scalar performance testsVictoria Dye via GitGitGadget, Aug 31, 2022
  50. Johannes SchindelinSep 1, 2022
  51. Victoria DyeSep 1, 2022
  52. Victoria DyeSep 1, 2022
  53. Johannes SchindelinSep 2, 2022
  54. Junio C HamanoSep 1, 2022
  55. 8/8 Documentation/technical: include Scalar technical docVictoria Dye via GitGitGadget, Aug 31, 2022
  56. Ævar Arnfjörð BjarmasonAug 31, 2022
  57. Victoria DyeAug 31, 2022
  58. Johannes SchindelinSep 1, 2022
  59. 0/9 scalar: integrate into core GitVictoria Dye via GitGitGadget, Sep 2, 2022
  60. 4/9 scalar: implement the `help` subcommandJohannes Schindelin via GitGitGadget, Sep 2, 2022
  61. 3/9 git help: special-case `scalar`Johannes Schindelin via GitGitGadget, Sep 2, 2022
  62. 1/9 scalar: fix command documentation section headerVictoria Dye via GitGitGadget, Sep 2, 2022
  63. 7/9 t/perf: add Scalar performance testsVictoria Dye via GitGitGadget, Sep 2, 2022
  64. 6/9 scalar-clone: add test coverageVictoria Dye via GitGitGadget, Sep 2, 2022
  65. 2/9 scalar: include in standard Git build & installationVictoria Dye via GitGitGadget, Sep 2, 2022
  66. 8/9 t/perf: add 'GIT_PERF_USE_SCALAR' run optionVictoria Dye via GitGitGadget, Sep 2, 2022
  67. 9/9 Documentation/technical: include Scalar technical docVictoria Dye via GitGitGadget, Sep 2, 2022
  68. 5/9 scalar: add to 'git help -a' command listVictoria Dye via GitGitGadget, Sep 2, 2022
  69. Johannes SchindelinSep 5, 2022
  70. Derrick StoleeSep 8, 2022

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.