Skip to content

Don't always provide transitive dependencies' analysis files to ZincRunner #77

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
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: 4 additions & 2 deletions rules/private/phases/phase_zinc_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def phase_zinc_compile(ctx, g):
common_scalacopts = toolchain.scala_configuration.global_scalacopts + ctx.attr.scalacopts

args = ctx.actions.args()
args.add_all(depset(transitive = [zinc.deps for zinc in zincs]), map_each = _compile_analysis)
if toolchain.zinc_configuration.incremental:
args.add_all(depset(transitive = [zinc.deps for zinc in zincs]), map_each = _compile_analysis)

args.add("--compiler_bridge", toolchain.zinc_configuration.compiler_bridge)
args.add_all("--compiler_classpath", g.classpaths.compiler)
args.add_all("--classpath", g.classpaths.compile)
Expand Down Expand Up @@ -69,7 +71,7 @@ def phase_zinc_compile(ctx, g):
g.classpaths.plugin,
g.classpaths.compile,
g.classpaths.compiler,
] + [zinc.deps_files for zinc in zincs],
] + ([zinc.deps_files for zinc in zincs] if toolchain.zinc_configuration.incremental else []),
)

outputs = [
Expand Down
20 changes: 20 additions & 0 deletions tests/ijar/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@rules_scala_annex//rules:scala.bzl", "scala_library")

scala_library(
name = "dependency",
srcs = [
"Dependency.scala",
"DependencyCacheInvalidation.scala",
],
scala_toolchain_name = "test_zinc_2_13",
)

scala_library(
name = "dependent",
srcs = [
"Dependent.scala",
"DependentCacheInvalidation.scala",
],
scala_toolchain_name = "test_zinc_2_13",
deps = [":dependency"],
)
7 changes: 7 additions & 0 deletions tests/ijar/Dependency.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package anx.ijar

object Dependency {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Empty file.
5 changes: 5 additions & 0 deletions tests/ijar/Dependent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package anx.ijar

object Dependent {
def main(args: Array[String]): Unit = Dependency.main(args)
}
Empty file.
32 changes: 32 additions & 0 deletions tests/ijar/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -e
. "$(dirname "$0")"/../common.sh

invalidate_dependency_cache() {
echo "// $(cat /proc/sys/kernel/random/uuid)" > DependencyCacheInvalidation.scala
}

invalidate_dependent_cache() {
echo "// $(cat /proc/sys/kernel/random/uuid)" > DependentCacheInvalidation.scala
}

test_actions_executed() {
scalacompile_runs="$(
bazel build --color no --subcommands "$1" |& \
grep '^SUBCOMMAND: # //ijar:.* \[.*, mnemonic: ScalaCompile\]$' | \
wc -l
)"

if [ "$scalacompile_runs" -ne "$2" ]; then
echo "Expected 1 \`ScalaCompile\` action to be executed, but got $scalacompile_runs"
exit 1
fi
}

trap ": > DependencyCacheInvalidation.scala; : > DependentCacheInvalidation.scala" EXIT

invalidate_dependency_cache
invalidate_dependent_cache
test_actions_executed //ijar:dependent 2

invalidate_dependency_cache
test_actions_executed //ijar:dependent 1