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

[PATCH v2 4/4] Makefile: stop using `test -o` when unlinking duplicate executables

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 10, 2023, 10:01 UTC
Message-ID
<5326d86888a46931e8893657bda9a2063a5cee3a.1699609940.git.ps@pks.im>
In-Reply-To
<cover.1699609940.git.ps@pks.im>

When building executables we may end up with both `foo` and `foo.exe` in the project's root directory. This can cause issues on Cygwin, which is why we unlink the `foo` binary (see 6fc301bbf68 (Makefile: remove $foo when $foo.exe is built/installed., 2007-01-10)). This step is skipped if either:

    - `foo` is a directory, which can happen when building Git on
      Windows via MSVC (see ade2ca0ca9f (Do not try to remove
      directories when removing old links, 2009-10-27)).
    - `foo` is a hardlink to `foo.exe`, which can happen on Cygwin (see
      0d768f7c8f1 (Makefile: building git in cygwin 1.7.0, 2008-08-15)).

These two conditions are currently chained together via `test -o`, which is discouraged by our code style guide. Convert the recipe to instead use an `if` statement with `&&`'d conditions, which both matches our style guide and is easier to ready.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 03adcb5a480..1094a557711 100644
--- a/Makefile
+++ b/Makefile
@@ -2342,7 +2342,7 @@ profile-fast: profile-clean
 
 all:: $(ALL_COMMANDS_TO_INSTALL) $(SCRIPT_LIB) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
 ifneq (,$X)
-	$(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
+	$(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), if test ! -d '$p' && test ! '$p' -ef '$p$X'; then $(RM) '$p'; fi;)
 endif
 
 all::
-- 
2.42.0
Previous: Patrick SteinhardtNext: Jeff King
Message 25 of 26 in “Replace use of `test <expr> -o/a <expr>`”
  1. 0/4 Replace use of `test <expr> -o/a <expr>`Patrick Steinhardt, Nov 9, 2023
  2. 1/4 global: convert trivial usages of `test <expr> -a/-o <expr>`Patrick Steinhardt, Nov 9, 2023
  3. Junio C HamanoNov 9, 2023
  4. Jeff KingNov 9, 2023
  5. Junio C HamanoNov 9, 2023
  6. Patrick SteinhardtNov 10, 2023
  7. 2/4 contrib/subtree: stop using `-o` to test for number of argsPatrick Steinhardt, Nov 9, 2023
  8. Jeff KingNov 9, 2023
  9. Junio C HamanoNov 9, 2023
  10. Patrick SteinhardtNov 10, 2023
  11. Junio C HamanoNov 10, 2023
  12. Patrick SteinhardtNov 10, 2023
  13. 3/4 contrib/subtree: convert subtree type check to use case statementPatrick Steinhardt, Nov 9, 2023
  14. Jeff KingNov 9, 2023
  15. 4/4 Makefile: stop using `test -o` when unlinking duplicate executablesPatrick Steinhardt, Nov 9, 2023
  16. 0/4 Replace use of `test <expr> -o/a <expr>`Patrick Steinhardt, Nov 10, 2023
  17. 1/4 global: convert trivial usages of `test <expr> -a/-o <expr>`Patrick Steinhardt, Nov 10, 2023
  18. Jeff KingNov 10, 2023
  19. Junio C HamanoNov 11, 2023
  20. Junio C HamanoNov 11, 2023
  21. Patrick SteinhardtNov 13, 2023
  22. Junio C HamanoNov 11, 2023
  23. 2/4 contrib/subtree: stop using `-o` to test for number of argsPatrick Steinhardt, Nov 10, 2023
  24. 3/4 contrib/subtree: convert subtree type check to use case statementPatrick Steinhardt, Nov 10, 2023
  25. 4/4 Makefile: stop using `test -o` when unlinking duplicate executablesPatrick Steinhardt, Nov 10, 2023
  26. Jeff KingNov 10, 2023

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.