Skip to content

Commit

Permalink
Pass SemanticDB compiler options in a separate list
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaden Peterson committed Oct 21, 2024
1 parent fcbbbce commit 24e4665
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions rules/private/phases/phase_semanticdb.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def phase_semanticdb(ctx, g):
arguments.add("--compiler_option=-P:semanticdb:failures:error")
arguments.add_all(
[outputs[0]],
format_each = "--compiler_option=-P:semanticdb:targetroot:%s",
format_each = "--compiler_option_referencing_path=-P:semanticdb:targetroot:%s",
map_each = _semanticdb_directory_from_file,
)
else:
arguments.add_all(
[outputs[0]],
format_each = "--compiler_option=-semanticdb-target:%s",
format_each = "--compiler_option_referencing_path=-semanticdb-target:%s",
map_each = _semanticdb_directory_from_file,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ class CommonArguments private (
val compilerBridge: Path,
val compilerClasspath: List[Path],
val compilerOptions: List[String],

/**
* With [[https://bazel.build/remote/multiplex#multiplex_sandboxing multiplex sandboxing]], Bazel generates a separate
* sandbox directory for each worker invocation, which means the paths to build artifacts won't be known until the
* execution phase. However, compiler options are usually generated during the analysis phase.
*
* Some compiler options (currently, only those regarding SemanticDB) reference paths to build artifacts and need to
* be adjusted to be relative to the sandbox directory. It's more performant for those options to be passed in a
* separate list so we don't have to scan through every compiler option and potentially modify it. In our experience,
* this resulted in a ~10% worker speedup.
*/
val compilerOptionsReferencingPaths: List[String],
val classpath: List[Path],
val debug: Boolean,
val javaCompilerOptions: List[String],
Expand Down Expand Up @@ -95,6 +107,11 @@ object CommonArguments {
.help("Compiler option")
.action(ArgumentsImpl.append)
.metavar("option")
parser
.addArgument("--compiler_option_referencing_path")
.help("Compiler option referencing the paths to build artifact(s)")
.action(ArgumentsImpl.append)
.metavar("option")
parser
.addArgument("--classpath")
.help("Compilation classpath")
Expand Down Expand Up @@ -195,9 +212,14 @@ object CommonArguments {
analyses = analyses,
compilerBridge = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("compiler_bridge")),
compilerClasspath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("compiler_classpath")),
compilerOptions = adjustCompilerOptions(
compilerOptions = Option(namespace.getList[String]("compiler_option"))
.map(_.asScala.toList)
.getOrElse(List.empty),
compilerOptionsReferencingPaths = adjustCompilerOptions(
workDir,
Option(namespace.getList[String]("compiler_option")).map(_.asScala.toList).getOrElse(List.empty),
Option(namespace.getList[String]("compiler_option_referencing_path"))
.map(_.asScala.toList)
.getOrElse(List.empty),
),
classpath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("classpath")),
debug = namespace.getBoolean("debug"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] {
.withClassesDirectory(classesOutputDir)
.withJavacOptions(workRequest.javaCompilerOptions.toArray)
.withScalacOptions(
Array.concat(
workRequest.plugins.map(p => s"-Xplugin:$p").toArray,
workRequest.compilerOptions.toArray,
),
(
workRequest.plugins.map(p => s"-Xplugin:$p") ++
workRequest.compilerOptions ++
workRequest.compilerOptionsReferencingPaths,
).toArray,
)

val compilers = {
Expand Down

0 comments on commit 24e4665

Please sign in to comment.