Skip to content

Commit

Permalink
Don't always provide transitive dependencies' analysis files to ZincR…
Browse files Browse the repository at this point in the history
…unner

They aren't used if Zinc persistence is disabled. They also contain
hashes of sources, which effectively makes `ijar` useless, since a
target will be always be recompiled if its transitive dependencies
were changed, regardless of whether their ijars changed.
  • Loading branch information
Jaden Peterson committed Dec 23, 2024
1 parent 5b3bd62 commit d9805d7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 2 deletions.
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
14 changes: 14 additions & 0 deletions tests/ijar/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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!")
}
}
1 change: 1 addition & 0 deletions tests/ijar/DependencyCacheInvalidation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 3598ab64-b0e5-49af-b12b-471f8d2dddc1
6 changes: 6 additions & 0 deletions tests/ijar/Dependent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package anx.ijar

//aaaaaaaa
object Dependent {
def main(args: Array[String]): Unit = Dependency.main(args)
}
1 change: 1 addition & 0 deletions tests/ijar/DependentCacheInvalidation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 630feaca-0178-4771-864d-18e932b4b10a
30 changes: 30 additions & 0 deletions tests/ijar/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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
}

invalidate_dependency_cache
invalidate_dependent_cache
test_actions_executed //ijar:dependent 2

invalidate_dependency_cache
test_actions_executed //ijar:dependent 1

0 comments on commit d9805d7

Please sign in to comment.