bugmake - Bugs: bug #28092, $(shell false) should break build

 
 

bug #28092: $(shell false) should break build

Submitter:  Stepan Koltsov <yozh>
Submitted:  Wed 25 Nov 2009 06:06:02 PM UTC
   
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  Fixed Privacy:  Public
Assigned to:  psmith Open/Closed:  Closed
Component Version:  3.81 Operating System:  None
Fixed Release:  4.2 Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 13 Jul 2015 04:10:37 AM UTC, comment #7: 

I'm not willing to add the suggested -e option or a new function.  I did add (in Git now) a new variable .SHELLSTATUS which is set to the exit code from the most recent shell function, so you can test it to see if there was an error and do whatever you like.


VAR := $(shell somecommand)
ifneq ($(.SHELLSTATUS),0)
  $(error somecommand failed)
endif


Paul D. Smith <psmith>
Group administrator
Thu 26 Nov 2009 06:37:52 PM UTC, comment #6: 

Timothy, you've proven that you can work around make limitations.

Stepan Koltsov <yozh>
Thu 26 Nov 2009 06:28:25 PM UTC, comment #5: 

Hi, 

Ok, Mk2 then:

a:=$(shell echo "don't mess up this output"; echo  " $$?")

code:=$(lastword $(a))
output:=$(strip $(patsubst %$(code),%,$(a)))
$(info exit code='$(code)')
$(info output='$(output)')

[tnmurphy@4GBL06592 ~]$ make -f t4.mk
exit code='0'
output='don't mess up this output'
make: * No targets.  Stop.

I think that the $(strip) is a bit of a cheat but it's pretty close to what should be done.  This could probably be done completely properly with another patsubst.

Timothy N Murphy <tnmurphy>
Thu 26 Nov 2009 03:27:05 PM UTC, comment #4: 

Timothy, echo $$? mixes up command output and exit code in single variable, it is not acceptable.

Stepan Koltsov <yozh>
Thu 26 Nov 2009 10:50:14 AM UTC, comment #3: 

To get the exit code:


a:=$(shell cat fred.txt; echo $$?)
$(info exit=$(a))

make -f t.mk
cat: fred.txt: No such file or directory
exit=1

Timothy N Murphy <tnmurphy>
Wed 25 Nov 2009 07:28:33 PM UTC, comment #2: 

Alternative requests then:

1. Add -e modifier to $(shell)

$(shell -e cat version.txt)

could break build. It mimics -e switch of /bin/sh. This shouldn't be a problem since there is no "-e" command.

2. Add another "shelle" command:

$(shelle cat version.txt)



Stepan Koltsov <yozh>
Wed 25 Nov 2009 06:38:28 PM UTC, comment #1: 

There's no way $(shell ...) failing can or should cause make to stop.  There are many legitimate reasons why the shell exiting with an error should not cause make to fail, and adding this would be an enormous backward-compatibility break.

For your situation, you can just check to see whether the result of the variable was valid; this will also catch the situation where there's an empty file as well as a non-existent one:

a := $(shell cat version.txt)
ifeq (,$(a))
$(error version.txt does not contain a valid version)
endif


I agree it might be useful to find out the exit code of the last $(shell ...) function invocation, so I'm leaving this open as an enhancement request to create a variable containing the exit code of the last $(shell ...) invocation.

Paul D. Smith <psmith>
Group administrator
Wed 25 Nov 2009 06:06:02 PM UTC, original submission:  

Currently,

$(shell false) does not break build:

===
a := $(shell false)

x:
        echo $(a)
===

completes successfully. Should fail, because in scenario:

a := $(shell cat version.txt)

it is hard to catch a situation if version.txt file does not exist.

Seen on gmake 3.81.

Stepan Koltsov <yozh>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tnmurphy (Posted a comment)
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by yozh (Submitted the item)
  •  

    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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-07-13 psmith StatusNone Fixed
        Assigned toNone psmith
        Open/ClosedOpen Closed
        Fixed ReleaseNone 4.2
    2009-11-25 psmith Item GroupNone Enhancement

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code