forked from bazelbuild/intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintellij_info.bzl
71 lines (60 loc) · 2.17 KB
/
intellij_info.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Bazel-specific intellij aspect."""
load(
":intellij_info_impl.bzl",
"intellij_info_aspect_impl",
"make_intellij_info_aspect",
)
EXTRA_DEPS = [
"embed", # From go rules (bazel only)
"_cc_toolchain", # From rules_cc (bazel only)
"_kt_toolchain", # From rules_kotlin (bazel only)
]
def tool_label(tool_name):
"""Returns a label that points to a tool target in the bundled aspect workspace."""
return Label("//aspect/tools:" + tool_name)
def get_go_import_path(ctx):
"""Returns the import path for a go target."""
import_path = getattr(ctx.rule.attr, "importpath", None)
if import_path:
return import_path
prefix = None
if hasattr(ctx.rule.attr, "_go_prefix"):
prefix = ctx.rule.attr._go_prefix.go_prefix
if not prefix:
return None
import_path = prefix
if ctx.label.package:
import_path += "/" + ctx.label.package
if ctx.label.name != "go_default_library":
import_path += "/" + ctx.label.name
return import_path
def is_go_proto_library(target, _ctx):
return hasattr(target[OutputGroupInfo], "go_generated_srcs")
def get_go_proto_library_generated_srcs(target):
files = target[OutputGroupInfo].go_generated_srcs.to_list()
return [f for f in files if f.basename.endswith(".go")]
def get_py_launcher(target, ctx):
"""Returns the python launcher for a given rule."""
# Used by other implementations of get_launcher
_ = target # @unused
attr = ctx.rule.attr
if hasattr(attr, "_launcher") and attr._launcher != None:
return str(attr._launcher.label)
return None
semantics = struct(
tool_label = tool_label,
extra_deps = EXTRA_DEPS,
extra_required_aspect_providers = [],
go = struct(
get_import_path = get_go_import_path,
is_proto_library = is_go_proto_library,
get_proto_library_generated_srcs = get_go_proto_library_generated_srcs,
),
py = struct(
get_launcher = get_py_launcher,
),
flag_hack_label = "//aspect:flag_hack",
)
def _aspect_impl(target, ctx):
return intellij_info_aspect_impl(target, ctx, semantics)
intellij_info_aspect = make_intellij_info_aspect(_aspect_impl, semantics)