什么时候应该在制作配方中评估对* eval *的调用 [英] When should a call to *eval* be evaluated in a make recipe

查看:65
本文介绍了什么时候应该在制作配方中评估对* eval *的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些作为RPM分发的软件项目.使用语义版本控制对其进行版本控制,并为其附加一个发行版本.使用常规约定,这是 MAJOR.MINOR.PATCH-REL_NUM .尽管超出了本文的范围,但发行版号存储在git中. makefile中的发布目标看起来像这样:

I have a few software projects which are distributed as RPMs. They are versioned using semantic versioning to which we affix a release number. Using the regular conventions, this is MAJOR.MINOR.PATCH-REL_NUM. Though beyond the scope of this article, the release numbers are stored in git. The release target in the makefile looks something like this:

release:
    make clean
    $(BLD_ROOT)/tools/incr_rel_num
# Although the third step, this was re-ordered to step 1
    $(eval RELEASE_NUMBER=$(shell cat $(BLD_ROOT)/path/to/rel_num.txt))
    make rpm RPM_RELEASE_NUM=$(RELEASE_NUMBER)

在调试过程中,我最终发现,尽管对 eval 的调用是配方的第三步,但实际上是对其进行评估的 first !这就是为什么RPM的发行号总是比我正在观看的发行号少一个的原因.

While debugging, I eventually discovered that, although the call to eval was the third step in the recipe, it was actually being evaluated first! This is why the RPM always had a release number one less than the number I was watching get pushed to the remote.

我对此进行了很多搜索,没有发现任何能解释食谱中使用 eval 的评估顺序的命中.也许甚至与 eval 无关,但总体上起作用.此外,我还没有在make的GNU手册中发现这句话(如果有的话,请指出哪一章).我已经解决了这个问题,所以这并不麻烦,我只是想知道,这是预期的吗?如果是这样,为什么?

I have done much googling on this and I haven't found any hits that explain the order of evaluation with regard to eval when used in recipes. Perhaps it isn't even with respect to eval but functions in general. Furthermore, I haven't found verbiage on this in the GNU manuals for make either (if it's there, kindly point out what chapter). I've worked around the problem so it's not a bother, I'm just wondering, is this expected and if so, why?

推荐答案

上面没有人得到的缺失位很简单:当make要运行一个配方时,它首先扩展配方的所有行,在开始第一行之前.所以:

The missing bit, that no one above is getting, is simple: when make is going to run a recipe it expands all lines of the recipe first, before it starts the first line. So:

release:
        make clean
        $(BLD_ROOT)/tools/incr_rel_num
# Although the third step, this was re-ordered to step 1
        $(eval RELEASE_NUMBER=$(shell $(BLD_ROOT)/path/to/rel_num.txt))
        make rpm RPM_RELEASE_NUM=$(RELEASE_NUMBER)

当make决定运行release目标时,它首先扩展配方中的所有行,这意味着eval被扩展,然后运行结果行.这就是为什么您得到所看到的行为.

when make decides to run the release target it first expands all the lines in the recipe, which means the eval is expanded, then it runs the resulting lines. That's why you're getting the behavior you're seeing.

我真的不明白您为什么需要在这里使用eval.为什么不只是使用:

I don't really see why you need to use eval here at all; why not just use:

release:
        $(MAKE) clean
        $(BLD_ROOT)/tools/incr_rel_num
        $(MAKE) rpm RPM_RELEASE_NUM='$$(cat $(BLD_ROOT)/path/to/rel_num.txt))'

(顺便说一句,您永远不要在makefile中使用裸露的make;应该始终使用$(MAKE)(或${MAKE}相同).

(BTW, you should never use bare make inside your makefiles; you should always use $(MAKE) (or ${MAKE}, same thing).

这篇关于什么时候应该在制作配方中评估对* eval *的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆