Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gazelle inconsistent proto dep referencing #1629

Closed
hsyed opened this issue Aug 5, 2018 · 2 comments
Closed

Gazelle inconsistent proto dep referencing #1629

hsyed opened this issue Aug 5, 2018 · 2 comments

Comments

@hsyed
Copy link

hsyed commented Aug 5, 2018

Firstly, the proto support and the fact that gogo is abstracted is awesome ! thanks !

I working on a build for lyft/protoc-gen-star proto code generation framework. Please see comment in snippet below (original file).

go_library(
    name = "go_default_library",
    srcs = [...],
    importpath = "github.com/lyft/protoc-gen-star",
    visibility = ["//visibility:public"],
    # Keep referencing the plugin and descriptor libraries directly. using the WKT's declared in `io_bazel_rules_go`
    # causes problems.
    # gazelle will prefer these by default.
    #   "@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
    #   "@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
    #keep
    deps = [
        "@com_github_golang_protobuf//descriptor:go_default_library",
        "@com_github_golang_protobuf//proto:go_default_library",
        "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library",
        "@com_github_golang_protobuf//protoc-gen-go/generator:go_default_library",
        "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library",
        "@com_github_spf13_afero//:go_default_library",
        "@org_golang_x_sync//errgroup:go_default_library",
    ],
)

if I remove the #keep from the library I get a warning (tests still pass):

GoLink: warning: package "github.com/golang/protobuf/protoc-gen-go/descriptor" is provided by more than one rule:
    @io_bazel_rules_go//proto/wkt:descriptor_go_proto
    @com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library

if I remove the #keep from the tests I get a failure:

➜  protoc-gen-star git:(bazel_dep) ✗ bazel test all_tests
INFO: Analysed target //:go_default_test (1 packages loaded).
INFO: Found 1 test target...
ERROR: /Volumes/work/src/github.com/lyft/protoc-gen-star/BUILD.bazel:72:1: GoCompile darwin_amd64_stripped/go_default_test~/github.com/lyft/protoc-gen-star.a failed (Exit 1)
external/com_github_golang_protobuf/protoc-gen-go/descriptor/descriptor.pb.go:1265:0: inconsistent definition for type descriptor.FileOptions during import
        struct { JavaPackage *string "protobuf:\"bytes,1,opt,name=java_package,json=javaPackage\" json:\"java_package,omitempty\""; JavaOuterClassname *string "protobuf:\"bytes,8,opt,name=java_outer_classname,json=javaOuterClassname\" json:\"java_outer_classname,omitempty\""; JavaMultipleFiles *bool "protobuf:\"varint,10,opt,name=java_multiple_files,json=javaMultipleFiles,def=0\" json:\"java_multiple_files,omitempty\""; JavaGenerateEqualsAndHash *bool "protobuf:\"varint,20,opt,name=java_generate_equals_and_hash,json=javaGenerateEqualsAndHash\" json:\"java_generate_equals_and_hash,omitempty\""; JavaStringCheckUtf8 *bool "protobuf:\"varint,27,opt,name=java_string_check_utf8,json=javaStringCheckUtf8,def=0\" json:\"java_string_check_utf8,omitempty\""; OptimizeFor *descriptor.FileOptions_OptimizeMode "protobuf:\"varint,9,opt,name=optimize_for,json=optimizeFor,enum=google.protobuf.FileOptions_OptimizeMode,def=1\" json:\"optimize_for,omitempty\""; GoPackage *string "protobuf:\"bytes,11,opt,name=go_package,json=goPackage\" json:\"go_package,omitempty\""; CcGenericServices *bool "protobuf:\"varint,16,opt,name=cc_generic_services,json=ccGenericServices,def=0\" json:\"cc_generic_services,omitempty\""; JavaGenericServices *bool "protobuf:\"varint,17,opt,name=java_generic_services,json=javaGenericServices,def=0\" json:\"java_generic_services,omitempty\""; PyGenericServices *bool "protobuf:\"varint,18,opt,name=py_generic_services,json=pyGenericServices,def=0\" json:\"py_generic_services,omitempty\""; PhpGenericServices *bool "protobuf:\"varint,42,opt,name=php_generic_services,json=phpGenericServices,def=0\" json:\"php_generic_services,omitempty\""; Deprecated *bool "protobuf:\"varint,23,opt,name=deprecated,def=0\" json:\"deprecated,omitempty\""; CcEnableArenas *bool "protobuf:\"varint,31,opt,name=cc_enable_arenas,json=ccEnableArenas,def=0\" json:\"cc_enable_arenas,omitempty\""; ObjcClassPrefix *string "protobuf:\"bytes,36,opt,name=objc_class_prefix,json=objcClassPrefix\" json:\"objc_class_prefix,omitempty\""; CsharpNamespace *string "protobuf:\"bytes,37,opt,name=csharp_namespace,json=csharpNamespace\" json:\"csharp_namespace,omitempty\""; SwiftPrefix *string "protobuf:\"bytes,39,opt,name=swift_prefix,json=swiftPrefix\" json:\"swift_prefix,omitempty\""; PhpClassPrefix *string "protobuf:\"bytes,40,opt,name=php_class_prefix,json=phpClassPrefix\" json:\"php_class_prefix,omitempty\""; PhpNamespace *string "protobuf:\"bytes,41,opt,name=php_namespace,json=phpNamespace\" json:\"php_namespace,omitempty\""; PhpMetadataNamespace *string "protobuf:\"bytes,44,opt,name=php_metadata_namespace,json=phpMetadataNamespace\" json:\"php_metadata_namespace,omitempty\""; RubyPackage *string "protobuf:\"bytes,45,opt,name=ruby_package,json=rubyPackage\" json:\"ruby_package,omitempty\""; UninterpretedOption []*descriptor.UninterpretedOption "protobuf:\"bytes,999,rep,name=uninterpreted_option,json=uninterpretedOption\" json:\"uninterpreted_option,omitempty\""; XXX_NoUnkeyedLiteral struct {} "json:\"-\""; proto.XXX_InternalExtensions "json:\"-\""; XXX_unrecognized []byte "json:\"-\""; XXX_sizecache int32 "json:\"-\"" } (in "github.com/golang/protobuf/protoc-gen-go/plugin")
        struct { JavaPackage *string "protobuf:\"bytes,1,opt,name=java_package,json=javaPackage\" json:\"java_package,omitempty\""; JavaOuterClassname *string "protobuf:\"bytes,8,opt,name=java_outer_classname,json=javaOuterClassname\" json:\"java_outer_classname,omitempty\""; JavaMultipleFiles *bool "protobuf:\"varint,10,opt,name=java_multiple_files,json=javaMultipleFiles,def=0\" json:\"java_multiple_files,omitempty\""; JavaGenerateEqualsAndHash *bool "protobuf:\"varint,20,opt,name=java_generate_equals_and_hash,json=javaGenerateEqualsAndHash\" json:\"java_generate_equals_and_hash,omitempty\""; JavaStringCheckUtf8 *bool "protobuf:\"varint,27,opt,name=java_string_check_utf8,json=javaStringCheckUtf8,def=0\" json:\"java_string_check_utf8,omitempty\""; OptimizeFor *descriptor.FileOptions_OptimizeMode "protobuf:\"varint,9,opt,name=optimize_for,json=optimizeFor,enum=google.protobuf.FileOptions_OptimizeMode,def=1\" json:\"optimize_for,omitempty\""; GoPackage *string "protobuf:\"bytes,11,opt,name=go_package,json=goPackage\" json:\"go_package,omitempty\""; CcGenericServices *bool "protobuf:\"varint,16,opt,name=cc_generic_services,json=ccGenericServices,def=0\" json:\"cc_generic_services,omitempty\""; JavaGenericServices *bool "protobuf:\"varint,17,opt,name=java_generic_services,json=javaGenericServices,def=0\" json:\"java_generic_services,omitempty\""; PyGenericServices *bool "protobuf:\"varint,18,opt,name=py_generic_services,json=pyGenericServices,def=0\" json:\"py_generic_services,omitempty\""; PhpGenericServices *bool "protobuf:\"varint,42,opt,name=php_generic_services,json=phpGenericServices,def=0\" json:\"php_generic_services,omitempty\""; Deprecated *bool "protobuf:\"varint,23,opt,name=deprecated,def=0\" json:\"deprecated,omitempty\""; CcEnableArenas *bool "protobuf:\"varint,31,opt,name=cc_enable_arenas,json=ccEnableArenas,def=0\" json:\"cc_enable_arenas,omitempty\""; ObjcClassPrefix *string "protobuf:\"bytes,36,opt,name=objc_class_prefix,json=objcClassPrefix\" json:\"objc_class_prefix,omitempty\""; CsharpNamespace *string "protobuf:\"bytes,37,opt,name=csharp_namespace,json=csharpNamespace\" json:\"csharp_namespace,omitempty\""; SwiftPrefix *string "protobuf:\"bytes,39,opt,name=swift_prefix,json=swiftPrefix\" json:\"swift_prefix,omitempty\""; PhpClassPrefix *string "protobuf:\"bytes,40,opt,name=php_class_prefix,json=phpClassPrefix\" json:\"php_class_prefix,omitempty\""; PhpNamespace *string "protobuf:\"bytes,41,opt,name=php_namespace,json=phpNamespace\" json:\"php_namespace,omitempty\""; UninterpretedOption []*descriptor.UninterpretedOption "protobuf:\"bytes,999,rep,name=uninterpreted_option,json=uninterpretedOption\" json:\"uninterpreted_option,omitempty\""; XXX_NoUnkeyedLiteral struct {} "json:\"-\""; proto.XXX_InternalExtensions "json:\"-\""; XXX_unrecognized []byte "json:\"-\""; XXX_sizecache int32 "json:\"-\"" } (in "github.com/golang/protobuf/protoc-gen-go/generator")
GoCompile: error running subcommand: exit status 2
Target //:go_default_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.790s, Critical Path: 0.25s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
@jayconrod
Copy link
Contributor

Hey @hsyed, you should be able to resolve this by adding the comment # gazelle proto:disable_global to your root build file. That will prevent Gazelle from depending on go_proto_library rules for the Well Known Types, and it will disable special cases for frequently used proto libraries like ptypes.

See #1548 for some more background on this.

This is not documented well enough (which is why #1548 is still open). I'll add some information on this later today.

@hsyed
Copy link
Author

hsyed commented Aug 7, 2018

Thanks Jay !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants