Skip to content

exposing java jar to BEP from all binary rules #943

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 4 commits into from
Jan 20, 2020
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
6 changes: 3 additions & 3 deletions scala/private/phases/phase_final.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
def phase_binary_final(ctx, p):
defaultInfo = DefaultInfo(
executable = p.declare_executable,
files = depset([p.declare_executable, ctx.outputs.jar]),
files = depset([p.declare_executable] + p.compile.full_jars),
runfiles = p.runfiles.runfiles,
)
return [defaultInfo, p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers

def phase_library_final(ctx, p):
defaultInfo = DefaultInfo(
files = depset([ctx.outputs.jar] + p.compile.full_jars), # Here is the default output
files = depset(p.compile.full_jars),
runfiles = p.runfiles.runfiles,
)
return [defaultInfo, p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers

def phase_scalatest_final(ctx, p):
defaultInfo = DefaultInfo(
executable = p.declare_executable,
files = depset([p.declare_executable, ctx.outputs.jar]),
files = depset([p.declare_executable] + p.compile.full_jars),
runfiles = ctx.runfiles(p.coverage_runfiles.coverage_runfiles, transitive_files = p.runfiles.runfiles.files),
)
return [defaultInfo, p.compile.merged_provider, p.collect_jars.jars2labels] + p.compile.coverage.providers
32 changes: 32 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,38 @@ sh_test(
data = ["MixJavaScalaLibTestOutputs"],
)

scala_binary(
name = "MixJavaScalaBinary",
srcs = ["src/main/scala/scalarules/test/MixJavaScalaLibBinary.scala"] + glob([
"src/main/scala/scalarules/test/mix_java_scala/*.scala",
]) + glob([
"src/main/scala/scalarules/test/mix_java_scala/*.java",
]),
main_class = "scalarules.test.JavaBinary",
)

scala_test(
name = "MixJavaScalaScalaTest",
size = "small",
srcs = [
"HelloLibTest.scala",
"OtherJavaLib.java",
],
deps = [
":HelloLib",
],
)

scala_junit_test(
name = "MixJavaScalaJunitTest",
size = "small",
srcs = [
"OtherJavaLib.java",
"src/main/scala/scalarules/test/junit/HelloWorldJunitTest.scala",
],
suffixes = ["Test"],
)

#needed to test java sources are compiled
scala_binary(
name = "MixJavaScalaLibBinary",
Expand Down
25 changes: 23 additions & 2 deletions test/shell/test_build_event_protocol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ runner=$(get_test_runner "${1:-local}")

scala_binary_common_jar_is_exposed_in_build_event_protocol() {
local target=$1
local target_suffix=${2:-""}
set +e
bazel build test:$target --build_event_text_file=$target_bes.txt
cat $target_bes.txt | grep "test/$target.jar"
cat $target_bes.txt | grep "test/$target$target_suffix.jar"
if [ $? -ne 0 ]; then
echo "test/$target.jar was not found in build event protocol:"
echo "test/$target$target_suffix.jar was not found in build event protocol:"
cat $target_bes.txt
rm $target_bes.txt
exit 1
Expand All @@ -31,6 +32,26 @@ scala_junit_test_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol JunitTestWithDeps
}

scala_binary_java_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol MixJavaScalaBinary _java
}

scala_library_java_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol MixJavaScalaLib _java
}

scala_test_java_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol MixJavaScalaScalaTest _java
}

junit_test_java_jar_is_exposed_in_build_event_protocol() {
scala_binary_common_jar_is_exposed_in_build_event_protocol MixJavaScalaJunitTest _java
}

$runner scala_binary_jar_is_exposed_in_build_event_protocol
$runner scala_test_jar_is_exposed_in_build_event_protocol
$runner scala_junit_test_jar_is_exposed_in_build_event_protocol
$runner scala_binary_java_jar_is_exposed_in_build_event_protocol
$runner scala_library_java_jar_is_exposed_in_build_event_protocol
$runner scala_test_java_jar_is_exposed_in_build_event_protocol
$runner junit_test_java_jar_is_exposed_in_build_event_protocol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package scalarules.test.junit

import org.junit.Test

class HelloWorldJunitTest {

@Test
def helloWorld: Unit = {
println("hello world")
}

}