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

[PATCH v2] Makefile: add and use the ".DELETE_ON_ERROR" flag

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 29, 2021, 08:44 UTC
Message-ID
<patch-1.1-2557117855-20210629T084356Z-avarab@gmail.com>
In-Reply-To
<patch-1.1-9420448e74f-20210622T141100Z-avarab@gmail.com>

Use the GNU make ".DELETE_ON_ERROR" flag in our main Makefile, as we already do in the Documentation/Makefile since db10fc6c09f (doc: simplify Makefile using .DELETE_ON_ERROR, 2021-05-21).

Now if a command to make X fails X will be removed, the default behavior of GNU make is to only do so if "make" itself is interrupted with a signal.

E.g. if we now intentionally break one of the rules with:
    -       mv $@+ $@
    +       mv $@+ $@ && \
    +       false
We'll get output like:
    $ make git
        CC git.o
        LINK git
    make: *** [Makefile:2179: git] Error 1
    make: *** Deleting file 'git'
    $ file git
    git: cannot open `git' (No such file or directory)

Before this change we'd leave the file in place in under this scenario.

As in db10fc6c09f this allows us to remove patterns of removing leftover $@ files at the start of rules, since previous failing runs of the Makefile won't have left those littered around anymore.

I'm not as confident that we should be replacing the "mv $@+ $@" pattern entirely, since that means that external programs or one of our other Makefiles might race and get partial content.

I'm not changing $(REMOTE_CURL_ALIASES) since that uses a ln/ln -s/cp dance, and would require the addition of "-f" flags if the "rm" at the start was removed. I've also got plans to fix that ln/ln -s/cp pattern in another series.

For $(LIB_FILE) and $(XDIFF_LIB) we can rely on the "c" (create) being present in ARFLAGS.

I'm not changing "$(ETAGS_TARGET)", "tags" and "cscope" because they've got a messy combination of removing "$@+" not "$@" at the beginning, or "$@*". I'm also addressing those in another series.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

The large thread on v1 is mostly/entirely a digression about an earlier patch series of mine not directly applicable to the change here. Felipe feedback about "why not change these rules too?" which I've incorporated into the commit message, and fixed the omission of a change to the $(XDIFF_LIB) rule.

Range-diff against v1:
1:  9420448e74 ! 1:  2557117855 Makefile: add and use the ".DELETE_ON_ERROR" flag
    @@ Commit message
         pattern entirely, since that means that external programs or one of
         our other Makefiles might race and get partial content.
     
    +    I'm not changing $(REMOTE_CURL_ALIASES) since that uses a ln/ln -s/cp
    +    dance, and would require the addition of "-f" flags if the "rm" at the
    +    start was removed. I've also got plans to fix that ln/ln -s/cp pattern
    +    in another series.
    +
    +    For $(LIB_FILE) and $(XDIFF_LIB) we can rely on the "c" (create) being
    +    present in ARFLAGS.
    +
    +    I'm not changing "$(ETAGS_TARGET)", "tags" and "cscope" because
    +    they've got a messy combination of removing "$@+" not "$@" at the
    +    beginning, or "$@*". I'm also addressing those in another series.
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Makefile ##
    @@ Makefile: endif
      	$(QUIET_GEN)sed -e '1s/^/[/' -e '$$s/,$$/]/' $(compdb_dir)/*.o.json > $@+
      	@if test -s $@+; then mv $@+ $@; else $(RM) $@+; fi
      endif
    +@@ Makefile: $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS
    + 		$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
    + 
    + $(LIB_FILE): $(LIB_OBJS)
    +-	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
    ++	$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^
    + 
    + $(XDIFF_LIB): $(XDIFF_OBJS)
    +-	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
    ++	$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^
    + 
    + export DEFAULT_EDITOR DEFAULT_PAGER
    + 
 Makefile | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/Makefile b/Makefile
index c3565fc0f8..157293b555 100644
--- a/Makefile
+++ b/Makefile
@@ -2160,6 +2160,16 @@ shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
 strip: $(PROGRAMS) git$X
 	$(STRIP) $(STRIP_OPTS) $^
 
+### Flags affecting all rules
+
+# A GNU make extension since gmake 3.72 (released in late 1994) to
+# remove the target of rules if commands in those rules fail. The
+# default is to only do that if make itself receives a signal. Affects
+# all targets, see:
+#
+#    info make --index-search=.DELETE_ON_ERROR
+.DELETE_ON_ERROR:
+
 ### Target-specific flags and dependencies
 
 # The generic compilation pattern rule and automatically
@@ -2243,7 +2253,6 @@ SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
 	$(gitwebdir_SQ):$(PERL_PATH_SQ):$(SANE_TEXT_GREP):$(PAGER_ENV):\
 	$(perllibdir_SQ)
 define cmd_munge_script
-$(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
     -e 's|@@DIFF@@|$(DIFF_SQ)|' \
@@ -2313,7 +2322,7 @@ endif
 PERL_DEFINES += $(gitexecdir) $(perllibdir) $(localedir)
 
 $(SCRIPT_PERL_GEN): % : %.perl GIT-PERL-DEFINES GIT-PERL-HEADER GIT-VERSION-FILE
-	$(QUIET_GEN)$(RM) $@ $@+ && \
+	$(QUIET_GEN) \
 	sed -e '1{' \
 	    -e '	s|#!.*perl|#!$(PERL_PATH_SQ)|' \
 	    -e '	r GIT-PERL-HEADER' \
@@ -2333,7 +2342,7 @@ GIT-PERL-DEFINES: FORCE
 	    fi
 
 GIT-PERL-HEADER: $(PERL_HEADER_TEMPLATE) GIT-PERL-DEFINES Makefile
-	$(QUIET_GEN)$(RM) $@ && \
+	$(QUIET_GEN) \
 	INSTLIBDIR='$(perllibdir_SQ)' && \
 	INSTLIBDIR_EXTRA='$(PERLLIB_EXTRA_SQ)' && \
 	INSTLIBDIR="$$INSTLIBDIR$${INSTLIBDIR_EXTRA:+:$$INSTLIBDIR_EXTRA}" && \
@@ -2359,7 +2368,7 @@ git-instaweb: git-instaweb.sh GIT-SCRIPT-DEFINES
 	mv $@+ $@
 else # NO_PERL
 $(SCRIPT_PERL_GEN) git-instaweb: % : unimplemented.sh
-	$(QUIET_GEN)$(RM) $@ $@+ && \
+	$(QUIET_GEN) \
 	sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 	    -e 's|@@REASON@@|NO_PERL=$(NO_PERL)|g' \
 	    unimplemented.sh >$@+ && \
@@ -2373,14 +2382,14 @@ $(SCRIPT_PYTHON_GEN): GIT-BUILD-OPTIONS
 ifndef NO_PYTHON
 $(SCRIPT_PYTHON_GEN): GIT-CFLAGS GIT-PREFIX GIT-PYTHON-VARS
 $(SCRIPT_PYTHON_GEN): % : %.py
-	$(QUIET_GEN)$(RM) $@ $@+ && \
+	$(QUIET_GEN) \
 	sed -e '1s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
 	    $< >$@+ && \
 	chmod +x $@+ && \
 	mv $@+ $@
 else # NO_PYTHON
 $(SCRIPT_PYTHON_GEN): % : unimplemented.sh
-	$(QUIET_GEN)$(RM) $@ $@+ && \
+	$(QUIET_GEN) \
 	sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
 	    -e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \
 	    unimplemented.sh >$@+ && \
@@ -2388,8 +2397,7 @@ $(SCRIPT_PYTHON_GEN): % : unimplemented.sh
 	mv $@+ $@
 endif # NO_PYTHON
 
-CONFIGURE_RECIPE = $(RM) configure configure.ac+ && \
-		   sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
+CONFIGURE_RECIPE = sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
 			configure.ac >configure.ac+ && \
 		   autoconf -o configure configure.ac+ && \
 		   $(RM) configure.ac+
@@ -2514,7 +2522,6 @@ endif
 ifeq ($(GENERATE_COMPILATION_DATABASE),yes)
 all:: compile_commands.json
 compile_commands.json:
-	@$(RM) $@
 	$(QUIET_GEN)sed -e '1s/^/[/' -e '$$s/,$$/]/' $(compdb_dir)/*.o.json > $@+
 	@if test -s $@+; then mv $@+ $@; else $(RM) $@+; fi
 endif
@@ -2587,10 +2594,10 @@ $(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS
 		$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
 
 $(LIB_FILE): $(LIB_OBJS)
-	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
+	$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^
 
 $(XDIFF_LIB): $(XDIFF_OBJS)
-	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
+	$(QUIET_AR)$(AR) $(ARFLAGS) $@ $^
 
 export DEFAULT_EDITOR DEFAULT_PAGER
 
-- 
2.32.0.613.g20d5ce26552
Previous: Felipe ContrerasNext: SZEDER Gábor
Message 32 of 35 in “Makefile: add and use the ".DELETE_ON_ERROR" flag”
  1. Makefile: add and use the ".DELETE_ON_ERROR" flagÆvar Arnfjörð Bjarmason, Jun 22, 2021
  2. Taylor BlauJun 22, 2021
  3. Ævar Arnfjörð BjarmasonJun 22, 2021
  4. Jeff KingJun 22, 2021
  5. Ævar Arnfjörð BjarmasonJun 23, 2021
  6. Jeff KingJun 23, 2021
  7. Ævar Arnfjörð BjarmasonJun 24, 2021
  8. Jeff KingJun 24, 2021
  9. Ævar Arnfjörð BjarmasonJun 25, 2021
  10. Jeff KingJun 29, 2021
  11. Junio C HamanoJun 29, 2021
  12. Ævar Arnfjörð BjarmasonJun 29, 2021
  13. Junio C HamanoJun 29, 2021
  14. Jeff KingJun 30, 2021
  15. Felipe ContrerasJul 1, 2021
  16. Ævar Arnfjörð BjarmasonJul 1, 2021
  17. Felipe ContrerasJul 3, 2021
  18. Ævar Arnfjörð BjarmasonJul 3, 2021
  19. Felipe ContrerasJul 3, 2021
  20. Felipe ContrerasJun 23, 2021
  21. Felipe ContrerasJun 23, 2021
  22. Felipe ContrerasJun 23, 2021
  23. Ævar Arnfjörð BjarmasonJun 23, 2021
  24. Felipe ContrerasJun 23, 2021
  25. Ævar Arnfjörð BjarmasonJun 29, 2021
  26. Felipe ContrerasJul 1, 2021
  27. Felipe ContrerasJun 23, 2021
  28. Ævar Arnfjörð BjarmasonJun 23, 2021
  29. Felipe ContrerasJun 23, 2021
  30. Ævar Arnfjörð BjarmasonJun 29, 2021
  31. Felipe ContrerasJul 1, 2021
  32. Makefile: add and use the ".DELETE_ON_ERROR" flagÆvar Arnfjörð Bjarmason, Jun 29, 2021
  33. Makefile: remove archives before manipulating them with 'ar'SZEDER Gábor, Aug 18, 2021
  34. Junio C HamanoAug 19, 2021
  35. Ævar Arnfjörð BjarmasonSep 1, 2021

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.