Skip to content

Commit

Permalink
Include generated protobuf sources on sync.
Browse files Browse the repository at this point in the history
This fixes the unresolved import error in the editor for generated protobufs.
  • Loading branch information
mtsgrd committed Sep 30, 2018
1 parent 369ec09 commit bfe82b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
13 changes: 13 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,16 @@ load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories")

kotlin_repositories()
# END-EXTERNAL-KOTLIN

# BEGIN-EXTERNAL-GO
# LICENSE: The Apache Software License, Version 2.0
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.15.3/rules_go-0.15.3.tar.gz"],
sha256 = "97cf62bdef33519412167fd1e4b0810a318a7c234f5f8dc4f53e2da86241c492",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
# END-EXTERNAL-GO
22 changes: 5 additions & 17 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ load(
"to_artifact_location",
)

load("@io_bazel_rules_go//go:def.bzl", "GoSource")

# Defensive list of features that can appear in the C++ toolchain, but which we
# definitely don't want to enable (when enabled, they'd contribute command line
# flags that don't make sense in the context of intellij info).
Expand Down Expand Up @@ -211,21 +213,6 @@ def collect_py_info(target, ctx, ide_info, ide_info_file, output_groups):
update_set_in_dict(output_groups, "intellij-resolve-py", transitive_sources)
return True

def _get_go_proto_info(target):
if hasattr(target, "aspect_proto_go_api_info"):
return target.aspect_proto_go_api_info
if hasattr(target, "proto_go_api_info"):
return target.proto_go_api_info
return None

def _collect_generated_proto_go_sources(target):
"""Returns a depset of proto go source files generated by this target."""
go_proto_info = _get_go_proto_info(target)
if not go_proto_info:
return None
files = getattr(go_proto_info, "files_to_build", [])
return [f for f in files if f.basename.endswith(".pb.go")]

def collect_go_info(target, ctx, semantics, ide_info, ide_info_file, output_groups):
"""Updates Go-specific output groups, returns false if not a recognized Go target."""
sources = []
Expand All @@ -248,8 +235,9 @@ def collect_go_info(target, ctx, semantics, ide_info, ide_info_file, output_grou
# then manually construct the .go file in the sync plugin
# TODO(chaorenl): change this if we ever get the .go file from a provider
generated += target.files.to_list()
else:
proto_sources = _collect_generated_proto_go_sources(target)
elif ctx.rule.kind == 'go_proto_library':
proto_files = getattr(target[GoSource], "srcs", [])
proto_sources = [f for f in proto_files if f.basename.endswith(".pb.go")]
if not proto_sources:
return False
sources += proto_sources
Expand Down

0 comments on commit bfe82b3

Please sign in to comment.