How to make GNU Make fail if a shell command assigned to a variable failed?

后端 未结 3 1355
别跟我提以往
别跟我提以往 2020-12-20 08:55

I have a Make variable:

PASSWORD:=$(shell vault read -field=password test/password)

If vault is not installed, make

3条回答
  •  隐瞒了意图╮
    2020-12-20 09:11

    In case you are intending to use a call function, and want to abort at one central place (so that future users of GET_SECRET do not forget to check e.g. .SHELLSTATUS), I found this hack practical:

    GET_SECRET = $(shell vault read -field=$(1) $(2) || { echo >&2 "Error reading field $(1) from vault path $(2), aborting"; kill $$PPID; })
    

    The parent make process is killed of shell error. See also 225542/how-to-make-a-failing-shell-command-interrupt-make and 50958731/assign-shell-output-to-variable-or-exit-terminate-makefile

提交回复
热议问题