doujianzi8521 2016-07-26 18:10
浏览 54
已采纳

如何处理Go软件包中的嵌套“供应商”目录?

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.

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).

How to avoid that?

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) Or, how to make glide properly handle the nested vendor directories?

Edit

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

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

  • 写回答

1条回答 默认 最新

  • duanji5116 2016-07-27 09:36
    关注

    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) flat.go needs to import "github.com/orloffm/toy" because of new(toy.RubberToy) - otherwise it doesn't compile

    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) 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 go install && ./flat produces

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

    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.

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

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。