修复go使用的工具版本 [英] fixing versions of tools used by go

查看:154
本文介绍了修复go使用的工具版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用go创建可复制的版本. 对于单个项目,我们使用滑行.

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

例如,我使用:

glide get github.com/stretchr/testify

修复"testify"软件包的版本. 但是,这不适用于工具. 例如:

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

glide install github.com/tebeka/go2xunit

返回成功,但实际上未安装go2xunit 所以我必须使用:

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

go get github.com/tebeka/go2xunit

go2xunit 安装到 $ GOPATH/bin .

问我该如何修复go2xunit之类的工具的版本?

我还注意到 glide表示改用dep ,而dep表示

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?

如果相关,我将使用Debian9提供的go 1.7.4.

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

推荐答案

使用go模块的go1.11解决方案是创建

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 工具是一个神奇的注释,可防止构建软件包.

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

>go mod init tools

将为伪造的 tools 包创建一个 go.mod 文件

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

>go install github.com/tebeka/go2xunit

将按照以下步骤安装go2xunit并更新go.mod.

Will install go2xunit and update go.mod as follows.

module tools

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

现在,如果您以后运行 go install github.com/tebeka/go2xunit (对于干净的版本说),则go.mod会将其版本固定为v1.4

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

对于1.11之前的版本,使用的工具为重新安装. 它是这样的:

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

引导程序:

go get github.com/twitchtv/retool

添加工具:

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

使用工具:

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

可能会在路线图上增加对go 1.12的定位( https://github .com/golang/go/issues/27653 )

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

这篇关于修复go使用的工具版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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