go dep and go generate

时间:2018-02-02 08:35:52

标签: git go dependency-management godeps

如何添加自动生成的依赖项?

我有一个protobuf-repository,其根目录中包含一个go-file,其中包含以下内容:

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

上述脚本遍历"消息/"中的所有.proto个文件。子文件夹,并生成go-sources。

之后,存储库包含许多子包,如

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

我不想将这些文件检入版本控制。

如何将此存储库与go dep一起使用?

我试图切换到de 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发现正确的存储库(vendoring-branch),但丢弃它,因为它无法找到所需的子包。他们只在这里一次" go generate"在根包中调用。

1 个答案:

答案 0 :(得分:-1)

From the godep documentation about migration:

dep assumes that all generated code exists, and has been committed to the source.

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

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.