help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to implement safe version of $(shell) without .NOTPARALLEL ?


From: Paul Smith
Subject: Re: how to implement safe version of $(shell) without .NOTPARALLEL ?
Date: Sun, 17 Mar 2019 10:31:45 -0400
User-agent: Evolution 3.30.1-1build1

On Sun, 2019-03-17 at 05:57 -0800, Britton Kerin wrote:
> SHELL_CHECKED =                                                      \
>   $(strip                                                            \
>     $(if $(shell (($1) 1>/tmp/SC_so) || echo nonempty),              \
>       $(error shell command '$1' failed.  Its stderr should be above \
>               somewhere.  Its stdout is in '/tmp/SC_so'),            \
>       $(shell cat /tmp/SC_so && rm -f /tmp/SC_so)))
> 
> Calls can safely be nested but not run in parallel.

Can you show how you're trying to use this?  I have to assume that
you're trying to use this variable within a recipe.

It's an antipattern to use $(shell ...) inside a recipe; it was not
designed to be used there (since a recipe is already running in a shell
there's little reason to do so) and there are many issues with it.

I recommend using real shell commands in your SHELL_CHECKED variable,
rather than using make functions.  That will solve your problem with
status checking.

As for locking, I recommend writing to a unique file for each instance:
maybe using the $$ value to get the current shell's PID--of course in
makefiles you have to write it as $$$$ instead.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]