dontoften8899 2018-10-31 14:49
浏览 11
已采纳

修复go使用的工具版本

I am looking to create reproducible builds with go. For individual projects we are using glide.

So for example I use:

glide get github.com/stretchr/testify

to fix the version of the "testify" package. This does not work for tools however. For example:

glide install github.com/tebeka/go2xunit

returns success but does not actually install go2xunit so I have to use:

go get github.com/tebeka/go2xunit

which installs go2xunit to $GOPATH/bin.

Q How can I fix the version of tools like go2xunit?

I also note that glide says use dep instead and dep says golang has diverged from its implementation and will probably end up using something based on vgo. There are a plethora of dependency management tools for go perhaps one of the less well known ones supports this?

In case its relevant I'm using go 1.7.4 as provided by Debian9.

  • 写回答

1条回答 默认 最新

  • douping6871 2018-10-31 17:45
    关注

    The solution for go1.11 using go modules is to create a fake tools package. You create a tools.go file like the following:

    // +build tools
    
    package tools
    
    import (
            _ "github.com/tebeka/go2xunit"
    )
    

    +build tools is a magic comment which prevents the package being built.

    >go mod init tools
    

    Will create a go.mod file for the fake tools package

    >go install github.com/tebeka/go2xunit
    

    Will install go2xunit and update go.mod as follows.

    module tools
    
    require github.com/tebeka/go2xunit v1.4.8 // indirect
    

    Now if you run go install github.com/tebeka/go2xunit in the future (for a clean build say) its version will be fixed to v1.4 by the go.mod


    For versions of go before 1.11 the tool to use is retool. It works like this:

    bootstrap:

    go get github.com/twitchtv/retool
    

    add tool:

    retool add github.com/jteeuwen/go-bindata/go-bindata origin/master
    

    use tool:

    retool do go-bindata -pkg testdata -o ./testdata/testdata.go ./testdata/data.json
    

    Adding support for this may be on the roadmap to target go 1.12 (https://github.com/golang/go/issues/27653)

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

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上