简体   繁体   English

为什么我的 Makefile 不在命令中插入表达式

[英]Why doesn't my Makefile interpolate an expression in a command

I'm trying to write a super simple Makefile to run the tests in a Go project.我正在尝试编写一个超级简单的Makefile来在 Go 项目中运行测试。 The project's dependencies are vendored, but I want to skip these tests.该项目的依赖项是供应商的,但我想跳过这些测试。 When running this from the command line I simply do从命令行运行时,我只是这样做

$ go test $(go list ./... | grep -v /vendor/)

Yet, when I put this into a Makefile like this:然而,当我把它放到这样的Makefile

test:
    go test $(go list ./... | grep -v /vendor/)

.PHONY: test

the expression will not be evaluated:表达式不会被评估:

$ make
go test 
?       github.com/m90/some-repo    [no test files]

How do I get make to interpolate the expression in a shell-like manner?我如何让 make 以类似 shell 的方式插入表达式?

In a Makefile recipe section you will need to escape the $ using a second $ :在一个Makefile配方部分,你需要躲避$使用第二$

test:
    go test $$(go list ./... | grep -v /vendor/)

.PHONY: test

Depending on the circumstance, it might be more useful to evaluate the command during the expansion of the recipe using shell function:根据情况,在使用shell函数扩展配方期间评估命令可能更有用:

test:
    go test $(shell go list ./... | grep -v /vendor/)

.PHONY: test

This will make the package names part of the recipe, and will normally print the result of the subcommand when executed.这将使包名称成为配方的一部分,并且通常会在执行时打印子命令的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM