diff mbox series

Makefile: Correctly propagate failure when removing target

Message ID 20201026131049.17443-1-pali@kernel.org
State Accepted
Delegated to: Tom Rini
Headers show
Series Makefile: Correctly propagate failure when removing target | expand

Commit Message

Pali Rohár Oct. 26, 2020, 1:10 p.m. UTC
On more places is used pattern 'command > $@ || rm -f $@'. But it does not
propagate failure from 'command' as 'rm -f' returns success.

Fix it by calling 'false' to correctly propagate failure after 'rm -f'.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 Makefile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Simon Glass Oct. 28, 2020, 2:10 a.m. UTC | #1
Hi Paul,

On Mon, 26 Oct 2020 at 07:11, Pali Rohár <pali@kernel.org> wrote:
>
> On more places is used pattern 'command > $@ || rm -f $@'. But it does not
> propagate failure from 'command' as 'rm -f' returns success.
>
> Fix it by calling 'false' to correctly propagate failure after 'rm -f'.
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  Makefile | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

But I'm not sure about the use of {}. I would normally use ()


>
> diff --git a/Makefile b/Makefile
> index 5a0ef18668..94feb7d9a5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1005,7 +1005,7 @@ cmd_cat = cat $(filter-out $(PHONY), $^) > $@
>  append = cat $(filter-out $< $(PHONY), $^) >> $@
>
>  quiet_cmd_pad_cat = CAT     $@
> -cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
> +cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
>
>  quiet_cmd_lzma = LZMA    $@
>  cmd_lzma = lzma -c -z -k -9 $< > $@
> @@ -1312,7 +1312,7 @@ endif
>  shell_cmd = { $(echo-cmd) $(cmd_$(1)); }
>
>  quiet_cmd_objcopy_uboot = OBJCOPY $@
> -cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || rm -f $@
> +cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || { rm -f $@; false; }
>
>  u-boot-nodtb.bin: u-boot FORCE
>         $(call if_changed,objcopy_uboot)
> @@ -1584,12 +1584,12 @@ u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
>  ifneq ($(CONFIG_ARCH_SOCFPGA),)
>  quiet_cmd_gensplx4 = GENSPLX4 $@
>  cmd_gensplx4 = cat     spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
> -                       spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || rm -f $@
> +                       spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || { rm -f $@; false; }
>  spl/u-boot-splx4.sfp: spl/u-boot-spl.sfp FORCE
>         $(call if_changed,gensplx4)
>
>  quiet_cmd_socboot = SOCBOOT $@
> -cmd_socboot = cat      spl/u-boot-splx4.sfp u-boot.img > $@ || rm -f $@
> +cmd_socboot = cat      spl/u-boot-splx4.sfp u-boot.img > $@ || { rm -f $@; false; }
>  u-boot-with-spl.sfp: spl/u-boot-splx4.sfp u-boot.img FORCE
>         $(call if_changed,socboot)
>
> @@ -1599,12 +1599,12 @@ cmd_gensplpadx4 =  dd if=/dev/zero of=spl/u-boot-spl.pad bs=64 count=1024 ; \
>                         spl/u-boot-spl.sfp spl/u-boot-spl.pad \
>                         spl/u-boot-spl.sfp spl/u-boot-spl.pad \
>                         spl/u-boot-spl.sfp spl/u-boot-spl.pad > $@ || \
> -                       rm -f $@ spl/u-boot-spl.pad
> +                       { rm -f $@ spl/u-boot-spl.pad; false; }
>  u-boot-spl-padx4.sfp: spl/u-boot-spl.sfp FORCE
>         $(call if_changed,gensplpadx4)
>
>  quiet_cmd_socnandboot = SOCNANDBOOT $@
> -cmd_socnandboot = cat  u-boot-spl-padx4.sfp u-boot.img > $@ || rm -f $@
> +cmd_socnandboot = cat  u-boot-spl-padx4.sfp u-boot.img > $@ || { rm -f $@; false; }
>  u-boot-with-nand-spl.sfp: u-boot-spl-padx4.sfp u-boot.img FORCE
>         $(call if_changed,socnandboot)
>
> --
> 2.20.1
>
Pali Rohár Oct. 28, 2020, 2:25 a.m. UTC | #2
On Tuesday 27 October 2020 20:10:37 Simon Glass wrote:
> Hi Paul,
> 
> On Mon, 26 Oct 2020 at 07:11, Pali Rohár <pali@kernel.org> wrote:
> >
> > On more places is used pattern 'command > $@ || rm -f $@'. But it does not
> > propagate failure from 'command' as 'rm -f' returns success.
> >
> > Fix it by calling 'false' to correctly propagate failure after 'rm -f'.
> >
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > ---
> >  Makefile | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> But I'm not sure about the use of {}. I would normally use ()

( ... ) spawns new shell and run commands in that new shell
{ ... ; } groups command together and runs them in the current shell

So { ... ; } should be more efficient as it spawns less processes. But
result should be same, return value from 'false', which returns 1.

I'm using { ... ; } when it is not needed to spawns new processes and
running commands in current shell is fine. I think that writing ( ... )
should be equivalent to sh -c '...' (with correctly exported variables).

> 
> >
> > diff --git a/Makefile b/Makefile
> > index 5a0ef18668..94feb7d9a5 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -1005,7 +1005,7 @@ cmd_cat = cat $(filter-out $(PHONY), $^) > $@
> >  append = cat $(filter-out $< $(PHONY), $^) >> $@
> >
> >  quiet_cmd_pad_cat = CAT     $@
> > -cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
> > +cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
> >
> >  quiet_cmd_lzma = LZMA    $@
> >  cmd_lzma = lzma -c -z -k -9 $< > $@
> > @@ -1312,7 +1312,7 @@ endif
> >  shell_cmd = { $(echo-cmd) $(cmd_$(1)); }
> >
> >  quiet_cmd_objcopy_uboot = OBJCOPY $@
> > -cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || rm -f $@
> > +cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || { rm -f $@; false; }
> >
> >  u-boot-nodtb.bin: u-boot FORCE
> >         $(call if_changed,objcopy_uboot)
> > @@ -1584,12 +1584,12 @@ u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
> >  ifneq ($(CONFIG_ARCH_SOCFPGA),)
> >  quiet_cmd_gensplx4 = GENSPLX4 $@
> >  cmd_gensplx4 = cat     spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
> > -                       spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || rm -f $@
> > +                       spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || { rm -f $@; false; }
> >  spl/u-boot-splx4.sfp: spl/u-boot-spl.sfp FORCE
> >         $(call if_changed,gensplx4)
> >
> >  quiet_cmd_socboot = SOCBOOT $@
> > -cmd_socboot = cat      spl/u-boot-splx4.sfp u-boot.img > $@ || rm -f $@
> > +cmd_socboot = cat      spl/u-boot-splx4.sfp u-boot.img > $@ || { rm -f $@; false; }
> >  u-boot-with-spl.sfp: spl/u-boot-splx4.sfp u-boot.img FORCE
> >         $(call if_changed,socboot)
> >
> > @@ -1599,12 +1599,12 @@ cmd_gensplpadx4 =  dd if=/dev/zero of=spl/u-boot-spl.pad bs=64 count=1024 ; \
> >                         spl/u-boot-spl.sfp spl/u-boot-spl.pad \
> >                         spl/u-boot-spl.sfp spl/u-boot-spl.pad \
> >                         spl/u-boot-spl.sfp spl/u-boot-spl.pad > $@ || \
> > -                       rm -f $@ spl/u-boot-spl.pad
> > +                       { rm -f $@ spl/u-boot-spl.pad; false; }
> >  u-boot-spl-padx4.sfp: spl/u-boot-spl.sfp FORCE
> >         $(call if_changed,gensplpadx4)
> >
> >  quiet_cmd_socnandboot = SOCNANDBOOT $@
> > -cmd_socnandboot = cat  u-boot-spl-padx4.sfp u-boot.img > $@ || rm -f $@
> > +cmd_socnandboot = cat  u-boot-spl-padx4.sfp u-boot.img > $@ || { rm -f $@; false; }
> >  u-boot-with-nand-spl.sfp: u-boot-spl-padx4.sfp u-boot.img FORCE
> >         $(call if_changed,socnandboot)
> >
> > --
> > 2.20.1
> >
Simon Glass Oct. 30, 2020, 6:15 p.m. UTC | #3
Hi Paul,

On Tue, 27 Oct 2020 at 20:25, Pali Rohár <pali@kernel.org> wrote:
>
> On Tuesday 27 October 2020 20:10:37 Simon Glass wrote:
> > Hi Paul,
> >
> > On Mon, 26 Oct 2020 at 07:11, Pali Rohár <pali@kernel.org> wrote:
> > >
> > > On more places is used pattern 'command > $@ || rm -f $@'. But it does not
> > > propagate failure from 'command' as 'rm -f' returns success.
> > >
> > > Fix it by calling 'false' to correctly propagate failure after 'rm -f'.
> > >
> > > Signed-off-by: Pali Rohár <pali@kernel.org>
> > > ---
> > >  Makefile | 12 ++++++------
> > >  1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > Reviewed-by: Simon Glass <sjg@chromium.org>
> >
> > But I'm not sure about the use of {}. I would normally use ()
>
> ( ... ) spawns new shell and run commands in that new shell
> { ... ; } groups command together and runs them in the current shell
>
> So { ... ; } should be more efficient as it spawns less processes. But
> result should be same, return value from 'false', which returns 1.
>
> I'm using { ... ; } when it is not needed to spawns new processes and
> running commands in current shell is fine. I think that writing ( ... )
> should be equivalent to sh -c '...' (with correctly exported variables).

OK thank you.

Regards,
Simon
Pali Rohár Nov. 17, 2020, 9:44 p.m. UTC | #4
Hello! I would like to remind this patch. I do not know who is maintainer
of Makefile and therefore who can take this patch but Simon has already
reviewed it.

On Tuesday 27 October 2020 20:10:37 Simon Glass wrote:
> On Mon, 26 Oct 2020 at 07:11, Pali Rohár <pali@kernel.org> wrote:
> >
> > On more places is used pattern 'command > $@ || rm -f $@'. But it does not
> > propagate failure from 'command' as 'rm -f' returns success.
> >
> > Fix it by calling 'false' to correctly propagate failure after 'rm -f'.
> >
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > ---
> >  Makefile | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> But I'm not sure about the use of {}. I would normally use ()
> 
> 
> >
> > diff --git a/Makefile b/Makefile
> > index 5a0ef18668..94feb7d9a5 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -1005,7 +1005,7 @@ cmd_cat = cat $(filter-out $(PHONY), $^) > $@
> >  append = cat $(filter-out $< $(PHONY), $^) >> $@
> >
> >  quiet_cmd_pad_cat = CAT     $@
> > -cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
> > +cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
> >
> >  quiet_cmd_lzma = LZMA    $@
> >  cmd_lzma = lzma -c -z -k -9 $< > $@
> > @@ -1312,7 +1312,7 @@ endif
> >  shell_cmd = { $(echo-cmd) $(cmd_$(1)); }
> >
> >  quiet_cmd_objcopy_uboot = OBJCOPY $@
> > -cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || rm -f $@
> > +cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || { rm -f $@; false; }
> >
> >  u-boot-nodtb.bin: u-boot FORCE
> >         $(call if_changed,objcopy_uboot)
> > @@ -1584,12 +1584,12 @@ u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
> >  ifneq ($(CONFIG_ARCH_SOCFPGA),)
> >  quiet_cmd_gensplx4 = GENSPLX4 $@
> >  cmd_gensplx4 = cat     spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
> > -                       spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || rm -f $@
> > +                       spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || { rm -f $@; false; }
> >  spl/u-boot-splx4.sfp: spl/u-boot-spl.sfp FORCE
> >         $(call if_changed,gensplx4)
> >
> >  quiet_cmd_socboot = SOCBOOT $@
> > -cmd_socboot = cat      spl/u-boot-splx4.sfp u-boot.img > $@ || rm -f $@
> > +cmd_socboot = cat      spl/u-boot-splx4.sfp u-boot.img > $@ || { rm -f $@; false; }
> >  u-boot-with-spl.sfp: spl/u-boot-splx4.sfp u-boot.img FORCE
> >         $(call if_changed,socboot)
> >
> > @@ -1599,12 +1599,12 @@ cmd_gensplpadx4 =  dd if=/dev/zero of=spl/u-boot-spl.pad bs=64 count=1024 ; \
> >                         spl/u-boot-spl.sfp spl/u-boot-spl.pad \
> >                         spl/u-boot-spl.sfp spl/u-boot-spl.pad \
> >                         spl/u-boot-spl.sfp spl/u-boot-spl.pad > $@ || \
> > -                       rm -f $@ spl/u-boot-spl.pad
> > +                       { rm -f $@ spl/u-boot-spl.pad; false; }
> >  u-boot-spl-padx4.sfp: spl/u-boot-spl.sfp FORCE
> >         $(call if_changed,gensplpadx4)
> >
> >  quiet_cmd_socnandboot = SOCNANDBOOT $@
> > -cmd_socnandboot = cat  u-boot-spl-padx4.sfp u-boot.img > $@ || rm -f $@
> > +cmd_socnandboot = cat  u-boot-spl-padx4.sfp u-boot.img > $@ || { rm -f $@; false; }
> >  u-boot-with-nand-spl.sfp: u-boot-spl-padx4.sfp u-boot.img FORCE
> >         $(call if_changed,socnandboot)
> >
> > --
> > 2.20.1
> >
Tom Rini Nov. 18, 2020, 4 a.m. UTC | #5
On Tue, Nov 17, 2020 at 10:44:52PM +0100, Pali Rohár wrote:

> Hello! I would like to remind this patch. I do not know who is maintainer
> of Makefile and therefore who can take this patch but Simon has already
> reviewed it.

I'll take it, at some point.  Unless this is missing a Fixes tag, I'm
going to grab it for -next, when I start collecting there.  Thanks.
Tom Rini Dec. 2, 2020, 9:21 p.m. UTC | #6
On Mon, Oct 26, 2020 at 02:10:49PM +0100, Pali Rohár wrote:

> On more places is used pattern 'command > $@ || rm -f $@'. But it does not
> propagate failure from 'command' as 'rm -f' returns success.
> 
> Fix it by calling 'false' to correctly propagate failure after 'rm -f'.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 5a0ef18668..94feb7d9a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1005,7 +1005,7 @@  cmd_cat = cat $(filter-out $(PHONY), $^) > $@
 append = cat $(filter-out $< $(PHONY), $^) >> $@
 
 quiet_cmd_pad_cat = CAT     $@
-cmd_pad_cat = $(cmd_objcopy) && $(append) || rm -f $@
+cmd_pad_cat = $(cmd_objcopy) && $(append) || { rm -f $@; false; }
 
 quiet_cmd_lzma = LZMA    $@
 cmd_lzma = lzma -c -z -k -9 $< > $@
@@ -1312,7 +1312,7 @@  endif
 shell_cmd = { $(echo-cmd) $(cmd_$(1)); }
 
 quiet_cmd_objcopy_uboot = OBJCOPY $@
-cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || rm -f $@
+cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || { rm -f $@; false; }
 
 u-boot-nodtb.bin: u-boot FORCE
 	$(call if_changed,objcopy_uboot)
@@ -1584,12 +1584,12 @@  u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
 ifneq ($(CONFIG_ARCH_SOCFPGA),)
 quiet_cmd_gensplx4 = GENSPLX4 $@
 cmd_gensplx4 = cat	spl/u-boot-spl.sfp spl/u-boot-spl.sfp	\
-			spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || rm -f $@
+			spl/u-boot-spl.sfp spl/u-boot-spl.sfp > $@ || { rm -f $@; false; }
 spl/u-boot-splx4.sfp: spl/u-boot-spl.sfp FORCE
 	$(call if_changed,gensplx4)
 
 quiet_cmd_socboot = SOCBOOT $@
-cmd_socboot = cat	spl/u-boot-splx4.sfp u-boot.img > $@ || rm -f $@
+cmd_socboot = cat	spl/u-boot-splx4.sfp u-boot.img > $@ || { rm -f $@; false; }
 u-boot-with-spl.sfp: spl/u-boot-splx4.sfp u-boot.img FORCE
 	$(call if_changed,socboot)
 
@@ -1599,12 +1599,12 @@  cmd_gensplpadx4 =  dd if=/dev/zero of=spl/u-boot-spl.pad bs=64 count=1024 ; \
 			spl/u-boot-spl.sfp spl/u-boot-spl.pad \
 			spl/u-boot-spl.sfp spl/u-boot-spl.pad \
 			spl/u-boot-spl.sfp spl/u-boot-spl.pad > $@ || \
-			rm -f $@ spl/u-boot-spl.pad
+			{ rm -f $@ spl/u-boot-spl.pad; false; }
 u-boot-spl-padx4.sfp: spl/u-boot-spl.sfp FORCE
 	$(call if_changed,gensplpadx4)
 
 quiet_cmd_socnandboot = SOCNANDBOOT $@
-cmd_socnandboot = cat	u-boot-spl-padx4.sfp u-boot.img > $@ || rm -f $@
+cmd_socnandboot = cat	u-boot-spl-padx4.sfp u-boot.img > $@ || { rm -f $@; false; }
 u-boot-with-nand-spl.sfp: u-boot-spl-padx4.sfp u-boot.img FORCE
 	$(call if_changed,socnandboot)