代码之家  ›  专栏  ›  技术社区  ›  Zeth

从生成目标重命名带有日期时间戳的文件(如果存在)

  •  0
  • Zeth  · 技术社区  · 3 年前

    我正在努力写一个超级简单的 Makefile 以在Go项目中运行测试。该项目的依赖项已出售,但我想跳过这些测试。当从命令行运行时,我只需要

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

    然而,当我把这个放进 Makefile 像这样:

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

    将不计算表达式:

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

    如何使表达式以类似shell的方式插入?

    0 回复  |  直到 9 年前
        1
  •  13
  •   m90    5 年前

    在Makefile配方部分,您需要退出 $ 使用第二个 $ :

    test:
        go test $$(go list ./... | grep -v /vendor/)
    
    .PHONY: test
    
        2
  •  6
  •   eush77    9 年前

    根据具体情况,在配方扩展过程中使用 shell 功能:

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

    这将使包名称成为配方的一部分,并且在执行时通常会打印子命令的结果。

    推荐文章