8000 Bazel aspects: allow sharing source jars and allow empty sourcejars by antonsviridov-src · Pull Request #757 · sourcegraph/scip-java · GitHub
[go: up one dir, main page]

Skip to content

Bazel aspects: allow sharing source jars and allow empty sourcejars #757

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
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions examples/bazel-example/src/main/java/srcjar_example/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ genrule(
cmd = "echo 'package com.testing; public class Bar {};' > Bar.java && jar cf $(@) Bar.java",
)

genrule(
name = "empty-srcjar",
outs = ["empty.srcjar"],
cmd = "touch test.txt && zip $(@) test.txt && zip -d $(@) test.txt",
)

java_library(
name = "testing",
srcs = [
"Foo.java",
":generated-srcjar",
":empty-srcjar"
],
)

java_library(
name = "other_library",
srcs = [
"Baz.java", # create a new file in source at test/Baz.java, alongside test/Foo.java
":generated-srcjar",
],
)
7 changes: 7 additions & 0 deletions examples/bazel-example/src/main/java/srcjar_example/Baz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.testing;

public class Baz {
public Bar baz(Bar value) {
return value;
}
}
4 changes: 2 additions & 2 deletions scip-java/src/main/resources/scip-java/scip_java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def _scip_java(target, ctx):
output_dir = []

for source_jar in source_jars:
dir = ctx.actions.declare_directory("extracted_srcjar/" + source_jar.short_path)
dir = ctx.actions.declare_directory(ctx.label.name + "/extracted_srcjar/" + source_jar.short_path)
output_dir.append(dir)

ctx.actions.run_shell(
inputs = javac_action.inputs,
outputs = [dir],
mnemonic 8A18 = "ExtractSourceJars",
command = """
unzip {input_file} -d {output_dir}
[ "$(unzip -q -l {input_file} | wc -l)" -eq 0 ] || unzip {input_file} -d {output_dir}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inexplicably, unzip returns a 1 exit code if there are any warnings (see Diagnostics on https://linux.die.net/man/1/unzip) with no way to turn it off.

So we just literally count the number of files..

""".format(
output_dir = dir.path,
input_file = source_jar.path,
Expand Down
Loading
0