drrqwokuz71031449 2016-06-27 14:34
浏览 135
已采纳

是否可以使用`go install`而不是`go test -c`来编译测试二进制文件

I would like to build test binary whenever it is need (only if the package or it's dependencies changed) - something like go install vs go build.

The only option option to speed up building test binaries is -i (go test -c -i).

Any idea if this is supported by the go tool? Is there any other go like tool to do it (I would like to use a tool with native support on go packages instead of a file based system like make).

  • 写回答

1条回答 默认 最新

  • douzong5057 2018-03-13 13:20
    关注

    Before go 1.10

    For go < 1.10, the go build doesn't store the package compiled object files. The go install does. One solution is to call go install in the right package. It will go through all package dependencies, compile them if the timestamp of the file in the dependency package changed, store the object file and then link them all. Example:

    GOBIN="my project build directory" go install ./cmd/mycmd
    

    Another solution is to use -i flag, which is supported by build and test commands.

    After go 1.10

    go 1.10 adds new flag to go build which does the "smart" caching.

    The go build command now detects out-of-date packages purely based on the content of source files, specified build flags, and metadata stored in the compiled packages. Modification times are no longer consulted or relevant. The old advice to add -a to force a rebuild in cases where the modification times were misleading for one reason or another (for example, changes in build flags) is no longer necessary: builds now always detect when packages must be rebuilt. (If you observe otherwise, please file a bug.)

    Read release notes for more information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重