bugmake - Bugs: bug #55137, $(file …) is executed too early...

 
 

bug #55137: $(file …) is executed too early when used in recipe

Submitted by:  Marcin Kasperski <mekk>
Submitted on:  Fri 30 Nov 2018 10:59:17 AM 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:  POSIX-Based
Fixed Release:  None Triage Status:  None

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 13 May 2019 10:00:17 PM UTC, comment #1: 

It's always been the case that the entire recipe, including all functions and macros on all the recipe lines, is expanded before the first recipe line is run.  The $(file ...) function is just a normal make function and obeys all the same expansion rules as any other function or macro.  Changing that behavior is of course possible but we'd have to think about it very carefully to understand the backward-compatibility ramifications.

To do what you want you'll have to force the directory creation to happen during expansion: you can do this by using the $(shell ...) function.  This is just about the only time I can think of where it's not an anti-pattern to use $(shell ...) in a recipe:

OUTPUT/something :
        $(shell mkdir -p $(@D))
        $(file >$@, $(@F))

Paul D. Smith <psmith>
Project Administrator
Fri 30 Nov 2018 10:59:17 AM UTC, original submission:  

I tried using the following snippet:

    OUTPUT/something :
         mkdir -p OUTPUT
         $(file > $@, something)

It crashes with
     OUTPUT/something: No such file or directory. Stop.

Moreover, looks like file is executed before anything else happens, even if I write:

    OUTPUT/something :
         /such/command/really/does/not/exist
         /neither/that/one
         $(file > $@, something)

I get the same error.

So I suppose file is executed too early, before earlier steps of the recipe are completed. Here this causes failure, in other places it may cause writing incorrect data.

~~~~~~~~

See attached Makefile for full working example – compare
    make good
with
    make bad

Marcin Kasperski <mekk>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #45560:  Makefile added by mekk (201B - application/octet-stream)

 

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 mekk (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-05-13 psmith StatusNone => Not A Bug
        Open/ClosedOpen => Closed
    2018-11-30 mekk Attached File- => Added Makefile, #45560

    Back to the top


    Powered by Savane 3.5