blob: dfdb3e45b02a60ef0fe3835431063fc317ff33cc [file] [log] [blame]
Copyright 2020 The Monogon Project Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# We need to patch the IntelliJ Bazel aspect that is injected via the @intellij_bazel repository
# to:
# - properly resolve go_library rules that have both source files and embeds.
# - allow running test/sync against //... which contains cc_toolchain rules
# (see https://github.com/bazelbuild/intellij/issues/1344 )
--- a/intellij_info_impl.bzl
+++ b/intellij_info_impl.bzl
@@ -13,6 +13,7 @@
":make_variables.bzl",
"expand_make_variables",
)
+load("@io_bazel_rules_go//go:def.bzl", "GoLibrary")
# 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
@@ -350,6 +351,8 @@
"go_appengine_test",
]:
sources = [f for src in getattr(ctx.rule.attr, "srcs", []) for f in src.files.to_list()]
+ sources += [f for embed in getattr(ctx.rule.attr, "embed", []) for f in _collect_generated_go_sources(embed) or []]
+
generated = [f for f in sources if not f.is_source]
elif ctx.rule.kind == "go_wrap_cc":
genfiles = target.files.to_list()
@@ -372,6 +375,10 @@
if go_semantics:
import_path = go_semantics.get_import_path(ctx)
+ if import_path == None and getattr(ctx.rule.attr, "embed", None) != None and ctx.rule.kind == "go_library":
+ embed_attr = getattr(ctx.rule.attr, "embed", None)
+ import_path = embed_attr[0][GoLibrary].importpath
+
library_labels = []
if ctx.rule.kind == "go_test" or ctx.rule.kind == "go_appengine_test":
if getattr(ctx.rule.attr, "library", None) != None:
@@ -457,6 +464,8 @@
return False
if cc_common.CcToolchainInfo not in target:
return False
+ if type(target[cc_common.CcToolchainInfo]) != 'CcToolchainInfo':
+ return False
# cc toolchain to access compiler flags
cpp_toolchain = target[cc_common.CcToolchainInfo]