Skip to content

Commit dda90aa

Browse files
Unpack .srcjars in Bazel aspect and add them to scip config
1 parent e2d6e7e commit dda90aa

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,36 @@ def _scip_java(target, ctx):
5757
annotations = info.annotation_processing
5858

5959
source_files = []
60+
source_jars = []
6061
for src in ctx.rule.files.srcs:
61-
source_files.append(src.path)
62+
if src.path.endswith(".java"):
63+
source_files.append(src.path)
64+
elif src.path.endswith(".srcjar"):
65+
source_jars.append(src)
66+
6267
if len(source_files) == 0:
6368
return None
69+
70+
output_dir = []
71+
72+
for source_jar in source_jars:
73+
dir = ctx.actions.declare_directory("extracted_" + source_jar.basename)
74+
output_dir.append(dir)
75+
76+
ctx.actions.run_shell(
77+
inputs = javac_action.inputs,
78+
outputs = [dir],
79+
mnemonic = "ExtractSourceJars",
80+
command = """
81+
unzip {input_file} -d {output_dir}
82+
""".format(
83+
output_dir = dir.path,
84+
input_file = source_jar.path,
85+
),
86+
progress_message = "Extracting source jar {jar}".format(jar = source_jar.path),
87+
)
88+
89+
source_files.append(dir.path)
6490

6591
classpath = [j.path for j in compilation.compilation_classpath.to_list()]
6692
bootclasspath = [j.path for j in compilation.boot_classpath]
@@ -73,11 +99,16 @@ def _scip_java(target, ctx):
7399

74100
launcher_javac_flags = []
75101
compiler_javac_flags = []
76-
for value in compilation.javac_options:
77-
if value.startswith("-J"):
78-
launcher_javac_flags.append(value)
79-
else:
80-
compiler_javac_flags.append(value)
102+
103+
for value in compilation.javac_options_list:
104+
# NOTE(Anton): for some bizarre reason I see empty string starting the list of
105+
# javac options - which then gets propagated into the JSON config, and ends up
106+
# crashing the actual javac invokation.
107+
if value != "":
108+
if value.startswith("-J"):
109+
launcher_javac_flags.append(value)
110+
else:
111+
compiler_javac_flags.append(value)
81112

82113
build_config = struct(**{
83114
"javaHome": ctx.var["java_home"],
@@ -100,6 +131,7 @@ def _scip_java(target, ctx):
100131
)
101132

102133
deps = [javac_action.inputs, annotations.processor_classpath]
134+
103135
ctx.actions.run_shell(
104136
command = "\"{}\" index --no-cleanup --index-semanticdb.allow-empty-index --cwd \"{}\" --targetroot {} --scip-config \"{}\" --output \"{}\"".format(
105137
ctx.var["scip_java_binary"],
@@ -113,7 +145,7 @@ def _scip_java(target, ctx):
113145
"NO_PROGRESS_BAR": "true",
114146
},
115147
mnemonic = "ScipJavaIndex",
116-
inputs = depset([build_config_path], transitive = deps),
148+
inputs = depset([build_config_path] + output_dir, transitive = deps),
117149
outputs = [scip_output, targetroot],
118150
)
119151

0 commit comments

Comments
 (0)