doudou7361 2018-02-02 08:35
浏览 49
已采纳

去生成并去生成

How can I add go dependencies that are auto-generated?

I have a protobuf-repository with a single go-file in its root, which contains the following:

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

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?

I'm trying to switch to go dep for dependency-management, but I cannot convince it to download this repository and execute "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. They are only here once "go generate" was called in the root package.

  • 写回答

1条回答 默认 最新

  • duangu1878 2018-02-03 10:14
    关注

    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.

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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探