Skip to content

Commit

Permalink
Merge pull request #77 from lucidsoftware/do-not-always-provide-trans…
Browse files Browse the repository at this point in the history
…itive-analysis-files

Don't always provide transitive dependencies' analysis files to ZincRunner
  • Loading branch information
jadenPete authored Jan 15, 2025
2 parents 5b3bd62 + 9d28e81 commit 782f590
Show file tree
Hide file tree
Showing 7 changed files with 68 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
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

0 comments on commit 782f590

Please sign in to comment.