Skip to content
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

Filter java_export source jar based on deploy_env #767

Merged
merged 1 commit into from
Oct 12, 2022
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
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