leahneukirchen / redo-c

An implementation of the redo build system in portable C with zero dependencies
105 stars 12 forks source link

Prevent virtual rules from creating empty files #22

Closed KAction closed 3 years ago

KAction commented 3 years ago

I somewhat bothered that virtual rules create empty files that are used for nothing.

I came up with this patch which seems to implement that, at least in simple cases. What do you think? Is it going to break anything?

diff --git a/redo.c b/redo.c
index 9b893ae..5a18da7 100644
--- a/redo.c
+++ b/redo.c
@@ -707,8 +707,10 @@ djb-style default.o.do:
                setenvfd("REDO_LEVEL", level + 1);
                if (sflag > 0)
                        dup2(target_fd, 1);
-               else
+               else {
+                       remove(temp_target);
                        close(target_fd);
+               }

                if (access(dofile, X_OK) != 0)   // run -x files with /bin/sh
                        execl("/bin/sh", "/bin/sh", xflag > 0 ? "-ex" : "-e",
leahneukirchen commented 3 years ago

We had this, it was reverted in https://github.com/leahneukirchen/redo-c/pull/2

KAction commented 3 years ago

Ah, okay.