git - 去 dep 去生成

标签 git go dependency-management godeps

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

我有一个 protobuf 存储库,其根目录中有一个 go 文件,其中包含以下内容:

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

上述脚本遍历“message/”子文件夹中的所有 .proto 文件,并生成 go-sources。

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

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

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

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

我正在尝试切换到 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 发现了正确的存储库(vendoring-branch),但由于找不到所需的子包而将其丢弃。只有在根包中调用“go generate”后,它们才会出现。

最佳答案

来自关于 migration 的 godep 文档:

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

因此,似乎不可能如我所愿。解决方案是创建一个包含生成源的存储库,并确保这些源自动生成并与实际源数据(在我的例子中是原始 *.proto 文件)保持同步。

由于我无法将生成的源与源数据放在同一个存储库中,因此有必要将这两个存储库完全同步(相同的分支,相同的标签),这样 go dep 使用的版本在与实际的存储库,仅包含声明。

关于git - 去 dep 去生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48578729/

相关文章:

git - 如果分支不存在,如何在没有错误消息的情况下删除分支?

multithreading - Go 中使用哪种数据类型进行并发读/写操作

Javascript require() 函数给出 ReferenceError : require is not defined

git - 如何只显示修改的文件名并排除已删除的文件名?

git - 如何调试 git svn fetch 无效的 XML

go - 构建命令行参数 : cannot load go-sql-driver/mysql

google-app-engine - 从 google go 中重命名的类型进行转换

intellij-idea - 为什么 Gradle 没有在 IntelliJ 2016 的 sourceSets 下正确应用依赖范围?

apache - 使用 Gradle 访问 Apache Authentication 后面的 Maven Repo

Git:如何从改变的历史中恢复?