Skip to content

Commit

Permalink
Add executable as a direct dependency (#1082)
Browse files Browse the repository at this point in the history
* Add executable as a direct dependency

This fixes a bug introduced by
#958. Before #958,
`rootpath` on a Scala binary resolved to the wrapper binary so other
rules could treat it as an opaque executable. After that PR `rootpath`
now resolves to the JAR instead of the wrapper binary.

Adding the executable back as a direct dependency fixes that.

* Add a testcase
  • Loading branch information
cocreature authored Aug 14, 2020
1 parent 041138f commit 3b51ba7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scala/private/phases/phase_default_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
def phase_default_info(ctx, p):
executable = None
files = []
direct = None
runfiles = []

phase_names = dir(p)
Expand All @@ -18,6 +19,7 @@ def phase_default_info(ctx, p):
if hasattr(phase, "executable"):
if executable == None:
executable = phase.executable
direct = [executable]
else:
fail("only one executable may be provided")

Expand All @@ -31,11 +33,11 @@ def phase_default_info(ctx, p):
external_providers = {
"DefaultInfo": DefaultInfo(
executable = executable,
files = depset(transitive = files),
files = depset(direct = direct, transitive = files),
# TODO:
# Per Bazel documentation, we should avoid using collect_data. The core phases need to be updated
# before we can make the adjustment.
runfiles = ctx.runfiles(transitive_files = depset(transitive = runfiles), collect_data = True),
runfiles = ctx.runfiles(transitive_files = depset(direct = direct, transitive = runfiles), collect_data = True),
),
},
)
20 changes: 20 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,26 @@ scala_specs2_junit_test(
"//test:test_scala_proto_server",
]]

# Generate a file containing the rootpaths of a Scala binary.
genrule(
name = "rootpath-script",
srcs = [":ScalaBinary"],
outs = ["rootpath-script.out"],
cmd = """
rootpaths=($(rootpaths {}))
(IFS='\n'; echo "$${{rootpaths[*]}}") | sort > $@
""".format(":ScalaBinary"),
)

# Validate that the rootpaths point to both the binary
# and the JAR.
sh_test(
name = "ScalaBinaryRootpaths",
srcs = ["rootpaths_binary.sh"],
args = ["$(location :rootpath-script.out)"],
data = [":rootpath-script.out"],
)

sh_test(
name = "test_binary_run_with_large_classpath",
srcs = ["test_binary_run_with_large_classpath.sh"],
Expand Down
11 changes: 11 additions & 0 deletions test/rootpaths_binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -eou pipefail

content="$(cat $1)"
expected=$'test/ScalaBinary\ntest/ScalaBinary.jar'
if [ "$content" != "$expected" ]; then
echo "Unexpected rootpaths: $content"
echo "$expected"
exit 1
fi

0 comments on commit 3b51ba7

Please sign in to comment.