Skip to content

Commit

Permalink
Made ZincRunner relativize SemanticDB paths to the sandbox directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaden Peterson committed Aug 27, 2024
1 parent 6566565 commit 7c1824d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 1 addition & 2 deletions rules/private/phases/phase_zinc_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ def phase_zinc_compile(ctx, g):
]

zincs = [dep[_ZincInfo] for dep in ctx.attr.deps if _ZincInfo in dep]
common_scalacopts = ctx.attr.scalacopts + g.semanticdb.scalacopts
common_scalacopts = scala_configuration.global_scalacopts + ctx.attr.scalacopts + g.semanticdb.scalacopts

args = ctx.actions.args()

args.add_all(depset(transitive = [zinc.deps for zinc in zincs]), map_each = _compile_analysis)
args.add("--compiler_bridge", zinc_configuration.compiler_bridge)
args.add_all("--compiler_classpath", g.classpaths.compiler)
args.add_all("--classpath", g.classpaths.compile)
args.add_all(scala_configuration.global_scalacopts, format_each = "--compiler_option=%s")
args.add_all(common_scalacopts, format_each = "--compiler_option=%s")
args.add_all(javacopts, format_each = "--java_compiler_option=%s")
args.add(ctx.label, format = "--label=%s")
Expand Down
2 changes: 1 addition & 1 deletion rules/scala/private/provider.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def configure_zinc_scala_implementation(ctx):
),
_ScalaRulePhase(
phases = [
("+", "classpaths", "semanticdb", _phase_semanticdb),
("=", "compile", "compile", _phase_zinc_compile),
("-", "compile", "semanticdb", _phase_semanticdb),
("+", "compile", "depscheck", _phase_zinc_depscheck),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ object Analysis {
}

object CommonArguments {
private def adjustCompilerOptions(workDir: Path, options: List[String]) = {
def adjustStringPath(path: String) = SandboxUtil.getSandboxPath(workDir, Paths.get(path)).toString

options.flatMap {
case s"-P:semanticdb:targetroot:$path" =>
List(s"-P:semanticdb:sourceroot:${workDir.toString}", s"-P:semanticdb:targetroot:${adjustStringPath(path)}")

case s"-semanticdb-target:$path" =>
List(s"-semanticdb-target:${adjustStringPath(path)}", s"-sourceroot:${workDir.toString}")

case option => List(option)
}
}

/**
* Adds argument parsers for CommonArguments to the given ArgumentParser and then returns the mutated ArgumentParser.
Expand Down Expand Up @@ -178,8 +191,10 @@ object CommonArguments {
analyses = analyses,
compilerBridge = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("compiler_bridge")),
compilerClasspath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("compiler_classpath")),
compilerOptions =
compilerOptions = adjustCompilerOptions(
workDir,
Option(namespace.getList[String]("compiler_option")).map(_.asScala.toList).getOrElse(List.empty),
),
classpath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("classpath")),
debug = namespace.getBoolean("debug"),
javaCompilerOptions = namespace.getList[String]("java_compiler_option").asScala.toList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ object ZincRunnerWorkerConfig {
}
}

// The list in this docstring gets clobbered by the formatter, unfortunately.
//format: off
/**
* <strong>Caching</strong>
*
* Zinc has two caches:
* 1. a ClassLoaderCache which is a soft reference cache for classloaders of Scala compilers.
* 2. a CompilerCache which is a hard reference cache for (I think) Scala compiler instances.
* 1. a CompilerCache which is a hard reference cache for (I think) Scala compiler instances.
*
* The CompilerCache has reproducibility issues, so it needs to be a no-op. The ClassLoaderCache needs to be reused else
* JIT reuse (i.e. the point of the worker strategy) doesn't happen.
Expand All @@ -75,7 +73,6 @@ object ZincRunnerWorkerConfig {
* that Zinc caches. We do so to prevent non-determinism in Zinc's analysis store files. Check the comments in
* AnnexScalaInstance for more info.
*/
//format: on
object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] {

private[this] val classloaderCache = new ClassLoaderCache(new URLClassLoader(Array()))
Expand Down

0 comments on commit 7c1824d

Please sign in to comment.