Skip to content

Commit ca15017

Browse files
committed
Fix Bazel 8 compatibility in scip-java aspect
- Detect Bazel via MODULE.bazel in addition to WORKSPACE - Tokenize compilation.javac_options via ctx.tokenize (depset of shell-quoted strings in Bazel 8) - Replace struct.to_json() (removed in Bazel 8) with json.encode
1 parent 1d320d0 commit ca15017

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

scip-java/src/main/resources/scip-java/scip_java.bzl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,18 @@ def _scip_java(target, ctx):
9797
processorpath += [j.path for j in annotations.processor_classpath.to_list()]
9898
processors = annotations.processor_classnames
9999

100+
# In Bazel 8 compilation.javac_options is a depset of shell-quoted strings;
101+
# ctx.tokenize splits each entry into proper individual flags.
102+
raw_options = compilation.javac_options
103+
if hasattr(raw_options, "to_list"):
104+
raw_options = raw_options.to_list()
105+
100106
launcher_javac_flags = []
101107
compiler_javac_flags = []
102-
103-
# In different versions of bazel javac options are either a nested set or a depset or a list...
104-
javac_options = []
105-
if hasattr(compilation, "javac_options_list"):
106-
javac_options = compilation.javac_options_list
107-
else:
108-
javac_options = compilation.javac_options
109-
110-
for value in javac_options:
111-
# NOTE(Anton): for some bizarre reason I see empty string starting the list of
112-
# javac options - which then gets propagated into the JSON config, and ends up
113-
# crashing the actual javac invokation.
114-
if value != "":
108+
for raw in raw_options:
109+
for value in ctx.tokenize(raw):
110+
if not value:
111+
continue
115112
if value.startswith("-J"):
116113
launcher_javac_flags.append(value)
117114
else:
@@ -134,7 +131,7 @@ def _scip_java(target, ctx):
134131
targetroot = ctx.actions.declare_directory(ctx.label.name + ".semanticdb")
135132
ctx.actions.write(
136133
output = build_config_path,
137-
content = build_config.to_json(),
134+
content = json.encode(build_config),
138135
)
139136

140137
deps = [javac_action.inputs, annotations.processor_classpath]

scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/BazelBuildTool.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class BazelBuildTool(index: IndexCommand) extends BuildTool("Bazel", index) {
2323
override def isHidden: Boolean = true
2424

2525
override def usedInCurrentDirectory(): Boolean = {
26-
Files.isRegularFile(index.workingDirectory.resolve("WORKSPACE"))
26+
val cwd = index.workingDirectory
27+
List("MODULE.bazel", "WORKSPACE", "WORKSPACE.bazel")
28+
.exists(f => Files.isRegularFile(cwd.resolve(f)))
2729
}
2830

2931
private def targetSpecs =

0 commit comments

Comments
 (0)