forked from spotify/sourcekit-bazel-bsp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_sourcekit_bsp.bzl
More file actions
120 lines (119 loc) · 5.5 KB
/
setup_sourcekit_bsp.bzl
File metadata and controls
120 lines (119 loc) · 5.5 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def _setup_sourcekit_bsp_impl(ctx):
rendered_bsp_config = ctx.actions.declare_file("skbsp.json")
bsp_config_argv = [
".bsp/sourcekit-bazel-bsp",
"serve",
]
for target in ctx.attr.targets:
bsp_config_argv.append("--target")
bsp_config_argv.append(target)
bsp_config_argv.append("--bazel-wrapper")
bsp_config_argv.append(ctx.attr.bazel_wrapper)
bsp_config_argv.append("--build-test-suffix")
bsp_config_argv.append(ctx.attr.build_test_suffix)
bsp_config_argv.append("--build-test-platform-placeholder")
bsp_config_argv.append(ctx.attr.build_test_platform_placeholder)
if ctx.attr.separate_aquery_output:
bsp_config_argv.append("--separate-aquery-output")
if ctx.attr.index_build_batch_size:
bsp_config_argv.append("--index-build-batch-size")
bsp_config_argv.append(ctx.attr.index_build_batch_size)
for index_flag in ctx.attr.index_flags:
bsp_config_argv.append("--index-flag")
bsp_config_argv.append(index_flag)
for top_level_rule in ctx.attr.top_level_rules_to_discover:
bsp_config_argv.append("--top-level-rule-to-discover")
bsp_config_argv.append(top_level_rule)
files_to_watch = ",".join(ctx.attr.files_to_watch)
if files_to_watch:
bsp_config_argv.append("--files-to-watch")
bsp_config_argv.append(files_to_watch)
ctx.actions.expand_template(
template = ctx.file._bsp_config_template,
output = rendered_bsp_config,
substitutions = {
"%argv%": ",\n ".join(["\"%s\"" % arg for arg in bsp_config_argv]),
},
)
executable = ctx.actions.declare_file("setup_sourcekit_bsp.sh")
ctx.actions.expand_template(
template = ctx.file._setup_sourcekit_bsp_script,
is_executable = True,
output = executable,
substitutions = {
"%bsp_config_path%": rendered_bsp_config.short_path,
"%sourcekit_bazel_bsp_path%": ctx.executable.sourcekit_bazel_bsp.short_path,
},
)
tools_runfiles = ctx.runfiles(
files = [
ctx.executable.sourcekit_bazel_bsp,
rendered_bsp_config,
],
)
return DefaultInfo(
executable = executable,
files = depset(direct = [executable]),
runfiles = tools_runfiles,
)
setup_sourcekit_bsp = rule(
implementation = _setup_sourcekit_bsp_impl,
executable = True,
doc = "Configures sourcekit-bazel-bsp in the current workspace using the provided configuration.",
attrs = {
"_bsp_config_template": attr.label(
doc = "The template for the sourcekit-bazel-bsp configuration.",
default = "//rules:bsp_config.json.tpl",
allow_single_file = True,
),
"_setup_sourcekit_bsp_script": attr.label(
doc = "The script for setting up the sourcekit-bazel-bsp.",
default = "//rules:setup_sourcekit_bsp.sh.tpl",
allow_single_file = True,
),
"sourcekit_bazel_bsp": attr.label(
doc = "The path to the sourcekit-bazel-bsp binary. Will compile from source if not provided.",
default = "//Sources:sourcekit-bazel-bsp",
allow_single_file = True,
cfg = "exec",
executable = True,
),
# We avoid using label_list here to not trigger unnecessary bazel dependency graph checks.
"targets": attr.string_list(
doc = "The *top level* Bazel applications or test targets that this should serve a BSP for. It's best to keep this list small if possible for performance reasons. If not specified, the server will try to discover top-level targets automatically",
mandatory = True,
),
"bazel_wrapper": attr.string(
doc = "The name of the Bazel CLI to invoke (e.g. 'bazelisk').",
default = "bazel",
),
"index_flags": attr.string_list(
doc = "Flags that should be passed to all indexing-related Bazel invocations. Do not include the -- prefix.",
default = [],
),
"files_to_watch": attr.string_list(
doc = "A list of file globs to watch for changes.",
default = [],
),
"top_level_rules_to_discover": attr.string_list(
doc = "A list of top-level rule types to discover targets for (e.g. 'ios_application', 'ios_unit_test'). Only applicable when not specifying targets directly. If not specified, all supported top-level rule types will be used for target discovery.",
default = [],
),
"build_test_suffix": attr.string(
doc = "The expected suffix format for build_test targets. Use the value of `build_test_platform_placeholder` as a platform placeholder.",
default = "_(PLAT)_skbsp",
),
"build_test_platform_placeholder": attr.string(
doc = "The expected platform placeholder for build_test targets.",
default = "(PLAT)",
),
"separate_aquery_output": attr.bool(
doc = "Whether to use a separate output base for compiler arguments requests. This greatly increases the performance of the server at the cost of more disk usage.",
default = False,
),
"index_build_batch_size": attr.int(
doc = "The number of targets to prepare in parallel. If not specified, SourceKit-LSP will calculate an appropriate value based on the environment. Requires using the pre-built SourceKit-LSP binary from the release archive.",
mandatory = False,
)
},
)