bugmake - Bugs: bug #55242, Included Makefile not found, no...

 
 

bug #55242: Included Makefile not found, no rule to build it but make does not fail

Submitter:  None
Submitted:  Wed 19 Dec 2018 12:37:06 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Not A Bug Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.2.1 Operating System:  Any
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 29 Nov 2021 04:10:12 PM UTC, comment #5: 

Thanks for your thoughts on this Dmitry.  I'm going to close this issue; anyone who wants to comment further can still do so.

Paul D. Smith <psmith>
Group administrator
Mon 29 Nov 2021 02:38:31 AM UTC, comment #4: 

i agree that the makefile in question is incorrect.
i don't think the patch should be applied. i should not have provided the patch to begin with.

i'd just gave the 'a.mk: b' rule a proper recipe which builds 'a.mk', rather than an empty recipe.
With an empty recipe when 'b' is present, but 'a.mk' is missing, 'a.mk' won't be created.

Dmitry Goncharov <dgoncharov>
Sun 28 Nov 2021 09:42:28 PM UTC, comment #3: 

I tried these patches (some updates were needed as remake.c has changed slightly).  They do fix the original issue but I thought of a new test to add:

# Allow included files to be updated as side-effects of prereqs.  Here a.mk
# already exists, but b (which is rebuilt) updates it so we should re-exec.

touch('a.mk');
unlink('b');

run_make_test(q!
all:; @echo hello=$(hello)
include a.mk
a.mk: b
b: ; @echo hello=world >a.mk
!, '', "touch b\nhello=world");


This does not pass; even though a.mk was rebuilt we don't re-exec because a.mk was pre-existing, we don't look to see if it's timestamp has changed.

We could continue on to fix this too, but I'm not convinced we should do that.

In general, make doesn't actually check timestamps of targets unless make believes that they've been updated.  I'm not sure that it's correct to break this general rule and do something unique and special for rebuilt makefiles in particular (or, I guess, this patch does something special for goal targets).

The way to "correct" the original makefile provided in the bug is the same as when you run into this situation in any other target which is not an included makefile: it is to add a recipe to the a.mk rule.  The recipe can be a "do nothing" empty recipe: as long as make sees there is SOME recipe then it will consider the target updated.

So for example, instead of this:

all:; @echo hello=$(hello)
include a.mk
a.mk: b
b: ; @echo hello=world >a.mk

if you added a semicolon (empty recipe) to a.mk like this:

all:; @echo hello=$(hello)
include a.mk
a.mk: b ;
b: ; @echo hello=world >a.mk

then it would work fine.

My inclination is to close this as "Not a Bug".

Comments welcome.

Paul D. Smith <psmith>
Group administrator
Sat 11 Apr 2020 12:27:54 PM UTC, comment #2: 

Here is a test.

diff --git a/tests/scripts/features/include b/tests/scripts/features/include
index 0c63c06..f39e5ec 100644
--- a/tests/scripts/features/include
+++ b/tests/scripts/features/include
@@ -260,4 +260,16 @@ inc1:; @%s $@ && echo FOO := bar > $@
     rmfiles('inc1');
 }
 
+unlink('b');
+unlink('a.mk');
+run_make_test(q!
+all:; @echo hello=$(hello)
+include a.mk
+a.mk: b
+b:
+       @echo hello=world >a.mk
+!, '', 'hello=world');
+unlink('a.mk');
+unlink('b');
+
 1;

Dmitry Goncharov <dgoncharov>
Sat 11 Apr 2020 12:26:57 PM UTC, comment #1: 

Here is a patch against the current master (0c326a66c9eb3a3b5e4ab7892578b016b0590b1f).

This patch causes make to re-execute itself to read the included makefile.

diff --git a/src/remake.c b/src/remake.c
index fb237c5..4dc91d8 100644
--- a/src/remake.c
+++ b/src/remake.c
@@ -175,24 +175,30 @@ update_goal_chain (struct goaldep *goaldeps)
                     }
                   else
                     {
-                      FILE_TIMESTAMP mtime = MTIME (file);
+                      struct file *oldfile = file;
                       check_renamed (file);
 
-                      if (file->updated && g->changed &&
-                           mtime != file->mtime_before_update)
+                      if (file->updated && g->changed)
                         {
-                          /* Updating was done.  If this is a makefile and
-                             just_print_flag or question_flag is set (meaning
-                             -n or -q was given and this file was specified
-                             as a command-line target), don't change STATUS.
-                             If STATUS is changed, we will get re-exec'd, and
-                             enter an infinite loop.  */
-                          if (!rebuilding_makefiles
-                              || (!just_print_flag && !question_flag))
-                            status = us_success;
-                          if (rebuilding_makefiles && file->dontcare)
-                            /* This is a default makefile; stop remaking.  */
-                            stop = 1;
+                          FILE_TIMESTAMP lm = oldfile->last_mtime;
+                          FILE_TIMESTAMP mtime =
+                            lm == UNKNOWN_MTIME || lm == NONEXISTENT_MTIME ?
+                            f_mtime (oldfile, 0) : lm;
+                          if (mtime != file->mtime_before_update)
+                            {
+                              /* Updating was done.  If this is a makefile and
+                                 just_print_flag or question_flag is set (meaning
+                                 -n or -q was given and this file was specified
+                                 as a command-line target), don't change STATUS.
+                                 If STATUS is changed, we will get re-exec'd, and
+                                 enter an infinite loop.  */
+                              if (!rebuilding_makefiles
+                                  || (!just_print_flag && !question_flag))
+                                status = us_success;
+                              if (rebuilding_makefiles && file->dontcare)
+                                /* This is a default makefile; stop remaking.  */
+                                stop = 1;
+                            }
                         }
                     }
                 }

Dmitry Goncharov <dgoncharov>
Wed 19 Dec 2018 12:37:06 PM UTC, original submission:  

With the following Makefile:


.PHONY: all clean

all:;

include a.mk

a.mk: b

b:
        @touch $@
        @printf '$$(info a.mk included)' > a.mk

clean:
        @rm -f a.mk b


The first make invocation produces:


$ make
make: Nothing to be done for 'all'.


And the second make invocation:


make
a.mk included
make: Nothing to be done for 'all'.


So we are in a situation where:

  1. a makefile is included with the include directive (no -include),
  2. the included makefile is not found,
  3. make finds no rule to produce it and decides not to include it,
  4. make executes a recipe for a prerequisite of the included makefile that incidentally also produces the included makefile,
  5. as the included makefile is finally found make does not fail... but it does not read the included makefile.


This could be considered as contradictory with the documentation:

After all makefiles have been checked, if any have actually been changed, make starts with a clean slate and reads all the makefiles over again.

make should either fail or include the included makefile.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by dgoncharov (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-29 psmith StatusNone Not A Bug
        Open/ClosedOpen Closed
    2020-04-11 dgoncharov Attached File- Added sv_55242_let_included_files_be_byproduct_of_unrelated_rules.diff, #48811
        Attached File- Added sv_55242_let_included_files_be_byproduct_of_unrelated_rules_test.diff, #48812

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code