简体   繁体   English

去 dep 去生成

[英]go dep and go generate

How can I add go dependencies that are auto-generated?如何添加自动生成的 go 依赖项?

I have a protobuf-repository with a single go-file in its root, which contains the following:我有一个 protobuf 存储库,其根目录中有一个 go-file,其中包含以下内容:

//go:generate ./scripts/generate_go_sources.sh    
package protobuf

The mentioned script goes through all .proto files in a "message/" subfolder, and generates the go-sources.提到的脚本遍历“message/”子文件夹中的所有.proto文件,并生成 go-sources。

Afterwards, the repository contains a lot of subpackages like之后,存储库包含很多子包,如

ptyes/package1/file.go
ptyes/package2/file.go

I do not want to check these files in to version control.我不想将这些文件签入版本控制。

How can I use this repository with go dep?如何通过 go dep 使用此存储库?

I'm trying to switch to go dep for dependency-management, but I cannot convince it to download this repository and execute "go generate".我正在尝试切换到 go dep 进行依赖项管理,但我无法说服它下载此存储库并执行“go generate”。

Solving failure: No versions of github.com/company/protobuf met constraints:
        master: Could not introduce github.com/company/protobuf@master, as it is not allowed by constraint vendoring from project github.com/company/myProject.
        develop: Could not introduce github.com/company/protobuf@develop, as it is not allowed by constraint vendoring from project github.com/company/myProject.
        vendoring: Could not introduce github.com/company/protobuf@vendoring due to multiple problematic subpackages:
        Subpackage github.com/company/protobuf/ptypes/package1 is missing. (Package is required by (root).)      
        Subpackage github.com/company/protobuf/ptypes/package2 is missing. Package is required by: (root)

go dep discovers the correct repository (vendoring-branch), but discards it because it cannot find the required sub-packages. go dep 发现了正确的存储库(vendoring-branch),但由于找不到所需的子包而将其丢弃。 They are only here once "go generate" was called in the root package.它们仅在根包中调用“go generate”时才出现。

From the godep documentation about migration :从关于迁移的godep文档:

dep assumes that all generated code exists, and has been committed to the source. dep 假设所有生成的代码都存在,并且已经提交给源代码。

Therefore, it seems to be impossible to do what I want.因此,似乎不可能做我想做的事。 The solution is to create a repository which contains the generated sources, and make sure these sources are automatically generated and kept in-sync with the actual source data (in my case the raw *.proto files).解决方案是创建一个包含生成源的存储库,并确保这些源自动生成并与实际源数据(在我的情况下是原始 *.proto 文件)保持同步。

Since I cannot put the generated sources into the same repository as the source data, it is neccessary to completely synchronise these two repositories (same branches, same tags), so that the versions used by go dep are somehow useful when comparing with the actual repository, that only contains declarations.由于我无法将生成的源和源数据放在同一个仓库中,所以需要完全同步这两个仓库(相同的分支,相同的标签),这样 go dep 使用的版本在与实际存储库进行比较时在某种程度上是有用的, 只包含声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM