8000 Handle .srcjar inputs in Bazel aspect by antonsviridov-src · Pull Request #754 · sourcegraph/scip-java · GitHub
[go: up one dir, main page]

Skip to content

Handle .srcjar inputs in Bazel aspect #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Unpack .srcjars in Bazel aspect and add them to scip config
  • Loading branch information
antonsviridov-src committed Oct 10, 2024
commit dda90aa64cd056facb1357b3a8dcbee5655a83b9
46 changes: 39 additions & 7 deletions scip-java/src/main/resources/scip-java/scip_java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,36 @@ def _scip_java(target, ctx):
annotations = info.annotation_processing

source_files = []
source_jars = []
for src in ctx.rule.files.srcs:
source_files.append(src.path)
if src.path.endswith(".java"):
source_files.append(src.path)
elif src.path.endswith(".srcjar"):
source_jars.append(src)

if len(source_files) == 0:
return None

output_dir = []

for source_jar in source_jars:
dir = ctx.actions.declare_directory("extracted_" + source_jar.basename)
output_dir.append(dir)

ctx.actions.run_shell(
inputs = javac_action.inputs,
outputs = [dir],
mnemonic = "ExtractSourceJars",
command = """
unzip {input_file} -d {output_dir}
""".format(
output_dir = dir.path,
input_file = source_jar.path,
),
progress_message = "Extracting source jar {jar}".format(jar = source_jar.path),
)

source_files.append(dir.path)

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

launcher_javac_flags = []
compiler_javac_flags = []
for value in compilation.javac_options:
if value.startswith("-J"):
launcher_javac_flags.append(value)
else:
compiler_javac_flags.append(value)

for value in compilation.javac_options_list:
# NOTE(Anton): for some bizarre reason I see empty string starting the list of
# javac options - which then gets propagated into the JSON config, and ends up
# crashing the actual javac invokation.
if value != "":
if value.startswith("-J"):
launcher_javac_flags.append(value)
else:
compiler_javac_flags.append(value)

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

deps = [javac_action.inputs, annotations.processor_classpath]

ctx.actions.run_shell(
command = "\"{}\" index --no-cleanup --index-semanticdb.allow-empty-index --cwd \"{}\" --targetroot {} --scip-config \"{}\" --output \"{}\"".format(
ctx.var["scip_java_binary"],
Expand All @@ -113,7 +145,7 @@ def _scip_java(target, ctx):
"NO_PROGRESS_BAR": "true",
},
mnemonic = "ScipJavaIndex",
inputs = depset([build_config_path], transitive = deps),
inputs = depset([build_config_path] + output_dir, transitive = deps),
outputs = [scip_output, targetroot],
)

Expand Down
0