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

Re: [PATCH v2 1/5] Makefile: rename objects in-place, don't clobber

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 29, 2021, 18:21 UTC
Message-ID
<xmqqy2e5kegv.fsf@gitster.g>
In-Reply-To
<patch-1.6-3330cdbccc0-20210329T161723Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 9 quoted lines
> Per the log of changes to the Makfile and Junio's recent comment about
> [1] why that pattern got introduced it was for a different reason
> entirely, i.e. ("[]" edits are mine, for brevity):
>
>     [T]hat age old convention [...] is spelled [as]:
>
>     	thing:
>     		rm -f thing thing+
>     		prepare contents for thing >thing+

Did I say that? I recall I specifically avoided the "redirection" because this is *NOT* shell-script only principle. If a command is so broken that "cmd -o thing" that fails to work correctly leaves a broken output in thing, then the pattern should be applied and made to "cmd -o thing+ && mv thing+ thing".

On the other hand, if "cmd" refrains from leaving a half-baked result in "-o thing" (and I believe $(CC) is well-behaved even on AIX), I do not think it is a good idea to use that pattern. One version of AIX may refuse to overwrite a file in use because creat("thing") that is necessary for "-o thing" may fail while "thing" is in use), but another system may refuse to rename over a file in use (i.e. "-o thing+" into a brand new "thing+" may be OK but the final "mv thing+ thing" may fail). So pretending that it is a cure for broken use case is cluttering Makefile for no real benefit and leading readers into confused thinking.

Show 17 quoted lines
>     		mv thing+ thing
>
>     It protects us from a failure mode where "prepare contents for
>     thing" step is broken and leaves a "thing" that does not work, but
>     confuses make that make does not need to rebuild it, if you wrote it
>     as such:
>
>     	thing:
>     		prepare contents for thing >thing
>
>     [It might leave behind a corrupt 'thing'.] In any case, it is not
>     "we are trying to make thing available while it is being
>     rewritten" at all.
>
> That makes perfect sense for shellscripts, but as this change shows
> there's other good reasons to use this age old convention that weren't
> considered at the time.

So, no, the age old convention may have considered and does not apply to such a use case.

Show 6 quoted lines
>  git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
> -	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
> -		$(filter %.o,$^) $(LIBS)
> +	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@+ $(ALL_LDFLAGS) \
> +		$(filter %.o,$^) $(LIBS) && \
> +	mv $@+ $@

Really, does anybody else use "$(CC) -o $@" in such a way in their Makefile? Having to do this smells simply crazy (I am not saying you are crazy---the platform that forces you to write such a thing is crazy).

So, while I do not think the end result would break the build (other than it probably would leave crufts "make clean" would not notice behind when interrupted in the middle), I am moderately negative on this change.

Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 8 of 48 in “Makefile: generate 'git' as 'cc [...] -o git+ && mv git+ git'”
  1. Makefile: generate 'git' as 'cc [...] -o git+ && mv git+ git'Ævar Arnfjörð Bjarmason, Mar 7, 2021
  2. Junio C HamanoMar 7, 2021
  3. Ævar Arnfjörð BjarmasonMar 8, 2021
  4. Junio C HamanoMar 8, 2021
  5. Jeff KingMar 8, 2021
  6. 0/5 Makefile: don't die on AIX with open ./gitÆvar Arnfjörð Bjarmason, Mar 29, 2021
  7. 1/5 Makefile: rename objects in-place, don't clobberÆvar Arnfjörð Bjarmason, Mar 29, 2021
  8. Junio C HamanoMar 29, 2021
  9. Junio C HamanoMar 29, 2021
  10. Ævar Arnfjörð BjarmasonMar 29, 2021
  11. Junio C HamanoMar 30, 2021
  12. Ævar Arnfjörð BjarmasonMar 31, 2021
  13. Junio C HamanoMar 31, 2021
  14. 4/5 Makefile: add the ".DELETE_ON_ERROR" flagÆvar Arnfjörð Bjarmason, Mar 29, 2021
  15. Junio C HamanoMar 29, 2021
  16. Ævar Arnfjörð BjarmasonMar 29, 2021
  17. Junio C HamanoMar 29, 2021
  18. Jeff KingMar 30, 2021
  19. Junio C HamanoMar 30, 2021
  20. Jeff KingMar 31, 2021
  21. Junio C HamanoMar 31, 2021
  22. Johannes SchindelinMar 31, 2021
  23. 3/5 Makefile: don't needlessly "rm $@ $@+" before "mv $@+ $@"Ævar Arnfjörð Bjarmason, Mar 29, 2021
  24. Junio C HamanoMar 29, 2021
  25. 2/5 Makefile: rename scripts in-place, don't clobberÆvar Arnfjörð Bjarmason, Mar 29, 2021
  26. Junio C HamanoMar 29, 2021
  27. Ævar Arnfjörð BjarmasonMar 29, 2021
  28. 5/5 Makefile: don't "rm configure" before generating itÆvar Arnfjörð Bjarmason, Mar 29, 2021
  29. 0/6 Makefile: make non-symlink & non-hardlink install saneÆvar Arnfjörð Bjarmason, Mar 29, 2021
  30. 1/6 Makefile: symlink the same way under "symlinks" and "no hardlinks"Ævar Arnfjörð Bjarmason, Mar 29, 2021
  31. Junio C HamanoMar 29, 2021
  32. 5/6 Makefile: use "ln -f" instead of "rm && ln"Ævar Arnfjörð Bjarmason, Mar 29, 2021
  33. Junio C HamanoMar 29, 2021
  34. 4/6 Makefile: make INSTALL_SYMLINKS affect the build directoryÆvar Arnfjörð Bjarmason, Mar 29, 2021
  35. Junio C HamanoMar 29, 2021
  36. Ævar Arnfjörð BjarmasonMar 31, 2021
  37. 6/6 Makefile: add a INSTALL_FALLBACK_LN_CP modeÆvar Arnfjörð Bjarmason, Mar 29, 2021
  38. Junio C HamanoMar 29, 2021
  39. Ævar Arnfjörð BjarmasonMar 31, 2021
  40. Junio C HamanoMar 31, 2021
  41. Ævar Arnfjörð BjarmasonMar 31, 2021
  42. 3/6 Makefile: refactor out "ln || ln -s || cp" patternÆvar Arnfjörð Bjarmason, Mar 29, 2021
  43. Junio C HamanoMar 29, 2021
  44. Jeff KingMar 30, 2021
  45. Junio C HamanoMar 30, 2021
  46. 2/6 Makefile: begin refactoring out "ln || ln -s || cp" patternÆvar Arnfjörð Bjarmason, Mar 29, 2021
  47. Junio C HamanoMar 29, 2021
  48. Junio C HamanoMar 29, 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.