如何处理嵌套的“供应商"消息.包中的目录? [英] How to handle nested "vendor" directories in Go packages?

查看:30
本文介绍了如何处理嵌套的“供应商"消息.包中的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,并导入一些程序包 B .该程序包具有 vendor 目录,在该目录中又包含程序包 C .我也想直接在我的应用程序中使用该包 C .

I'm writing an application and import some package B. This package has the vendor directory inside which, in turn, contains package C. I also want to use that package C in my app directly.

因此,我决定使用 glide 包管理器.它将 B C 都下载到 myapp/vendor 目录中,但保留 myapp/vendor/B/vendor/C 里面.因此,当我构建我的应用程序时,它会使用两个不同的C版本(也使用 myapp/vendor/C )来构建.

So I decided to use glide package manager. It downloads both B and C into myapp/vendor directory, but keeps myapp/vendor/B/vendor/C inside. So when I build my app, it builds with two different versions of C (also with myapp/vendor/C).

如何避免这种情况?

1)要么,有处理该问题的软件包管理器? govend 似乎带有其-prune 参数,但是它不尊重这些 C 软件包的版本.

1) Either, is there a package manager that handles that? govend seems to with its --prune argument, but it doesn't respect the versions of these C packages.

2)或者,如何使 glide 正确处理嵌套的 vendor 目录?

2) Or, how to make glide properly handle the nested vendor directories?

修改

我的示例是 https://github.com/orloffm/flat .它使用 cat 和-间接- toy 包. cat 具有一些 toy 的旧版本,并已提交并提交到存储库中.我做 glide create&&glide install 并最终得到:

My example is https://github.com/orloffm/flat. It uses cat and - indirectly - toy packages. cat has some older version of toy vendored and commited into repository. I do glide create && glide install and end up with this:

.
├── flat.go
├── glide.lock
├── glide.yaml
└── vendor
    └── github.com
        └── orloffm
            ├── cat
            │   ├── cat.go
            │   ├── vendor
            │   │   └── github.com
            │   │       └── orloffm
            │   │           └── toy
            │   │               └── toy.go
            │   └── vendor.yml
            └── toy
                └── toy.go

我不想将 vendor 目录与 toy 嵌套在一起.

I don't want to have nested vendor directory with toy.

推荐答案

通过以下更改,我能够安装并运行您的 flat 程序(还向您发送了PR

I was able to install and run your flat program by making the following changes (also sent you a PR https://github.com/orloffm/flat/pull/1):

1)由于 new(toy.RubberToy),flat.go需要导入"github.com/orloffm/toy"-否则它将无法编译

1) flat.go needs to import "github.com/orloffm/toy" because of new(toy.RubberToy) - otherwise it doesn't compile

2)添加 glide.yaml 文件,该文件将"cat"和玩具"库都列为依赖项:

2) add glide.yaml file that list both "cat" and "toy" libraries as dependencies:

package: github.com/orloffm/flat
import:
- package: github.com/orloffm/cat
- package: github.com/orloffm/toy

3)运行 glide install --strip-vcs --strip-vendor (或等效的快捷方式 glide install -s -v )以安装软件包并删除嵌套的 vendor/目录(我正在使用安装了 go get -u github.com/Masterminds/glide 的glide版本0.11.0-dev; glide install-帮助显示-strip-vendor 选项).

3) run glide install --strip-vcs --strip-vendor (or the equivalent shortcut glide install -s -v) to install packages and remove nested vendor/ directories (I'm using glide version 0.11.0-dev installed with go get -u github.com/Masterminds/glide; glide install --help shows the --strip-vendor option).

4)GOBIN = $ PWD转到install&&./flat产生

4) GOBIN=$PWD go install && ./flat produces

Cat pushes the toy.
The toy makes a very loud noise.

我认为最好是 vendor 目录包含到您的中-这会使事情变得混乱,并使人们的生活更加困难库用户(例如,需要记住使用其他选项进行 glide ).让那些库的客户端"( package main 软件包)供应商所有依赖项(包括可传递的依赖项),或以诸如 glide.yaml 和让该工具(滑动)正确地获取并安装它们.

I think the best would be not to include the vendor directory into your libraries - this messes things up and makes life more difficult for the library users (for example, need to remember to use additional options to glide). Let the "clients" of those libraries - package main packages - either to vendor all the dependencies (including transitive ones) or specify them in a configuration such as glide.yaml and let the tool (glide) to fetch and install them properly.

这篇关于如何处理嵌套的“供应商"消息.包中的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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