Skip to content

Commit

Permalink
Filter java_export source jar based on deploy_env
Browse files Browse the repository at this point in the history
The project jar has entries coming from the deploy_env filtered out.
This commit ensures that the same filtering applies to source jars.
  • Loading branch information
fmeum committed Oct 12, 2022
1 parent 9261dd2 commit 598e454
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion private/rules/maven_project_jar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def _maven_project_jar_impl(ctx):
ctx,
ctx.executable._merge_jars,
depset(artifact_srcs),
depset(transitive = [ji.transitive_source_jars for ji in info.dep_infos.to_list()]),
depset(transitive =
[ji.transitive_source_jars for ji in info.dep_infos.to_list()] +
[jar[JavaInfo].transitive_source_jars for jar in ctx.attr.deploy_env]),
src_jar,
)

Expand Down
28 changes: 28 additions & 0 deletions tests/integration/java_export/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,31 @@ sh_test(
"@bazel_tools//tools/bash/runfiles",
],
)

filegroup(
name = "deploy-env-sources",
srcs = [":deploy-env-project"],
output_group = "maven_source",
)

genrule(
name = "list-deploy-env-sources",
srcs = [
":deploy-env-sources",
],
outs = ["sources.txt"],
cmd = "for SRC in $(SRCS); do jar tf $$SRC >> $@; done",
)

sh_test(
name = "check-deploy-env-sources",
srcs = [
"check-deploy-env-sources.sh",
],
data = [
":sources.txt",
],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)
24 changes: 24 additions & 0 deletions tests/integration/java_export/check-deploy-env-sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

set -euox pipefail

sources_file=$(rlocation rules_jvm_external/tests/integration/java_export/sources.txt)

if grep -q Dependency.java "$sources_file"; then
echo "Unexpectedly found dependency source file in jar"
exit 1
fi

if ! grep -q Main.java "$sources_file"; then
echo "Missing main source file from jar"
exit 1
fi

0 comments on commit 598e454

Please sign in to comment.