Skip to content

Commit 7b09e86

Browse files
authored
Enable semanticdb phase during plugin bootstrapping (#1830)
* Enable semanticdb phase during plugin bootstrapping scala_library_for_plugin_bootstrapping skipped phase_semanticdb, so when a toolchain sets enable_semanticdb=True and includes a -P:semanticdb:... scalacopt (e.g. -P:semanticdb:synthetics:on), the bootstrap compilation of the dep analyzer plugin received the flag but had no semanticdb plugin loaded, causing scalac to fail with "bad option: -P:semanticdb:synthetics:on". Unconditionally run phase_semanticdb in the bootstrap phase list so the plugin jar is loaded whenever the toolchain enables semanticdb. Adds a regression test that builds with a synthetics-enabled semanticdb toolchain to verify the bootstrap path handles these scalacopts.
1 parent 3d7cbe2 commit 7b09e86

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

scala/private/rules/scala_library.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _scala_library_for_plugin_bootstrapping_impl(ctx):
163163
("dependency", phase_dependency_library_for_plugin_bootstrapping),
164164
("collect_jars", phase_collect_jars_common),
165165
("scalacopts", phase_scalacopts),
166-
#("semanticdb", phase_semanticdb), noneed for semanticdb in bootstrap
166+
("semanticdb", phase_semanticdb), # enable semanticdb during bootstrap since toolchain scalacopts may include flags for it
167167
("compile", phase_compile_library_for_plugin_bootstrapping),
168168
("merge_jars", phase_merge_jars),
169169
("runfiles", phase_runfiles_library),

test/semanticdb/BUILD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ toolchain(
3030
visibility = ["//visibility:public"],
3131
)
3232

33+
scala_toolchain(
34+
name = "semanticdb_synthetics_toolchain_impl",
35+
enable_semanticdb = True,
36+
scalacopts = ["-P:semanticdb:synthetics:on"],
37+
semanticdb_bundle_in_jar = False,
38+
visibility = ["//visibility:public"],
39+
)
40+
41+
toolchain(
42+
name = "semanticdb_synthetics_toolchain",
43+
toolchain = ":semanticdb_synthetics_toolchain_impl",
44+
toolchain_type = "//scala:toolchain_type",
45+
visibility = ["//visibility:public"],
46+
)
47+
3348
scala_library(
3449
name = "all_lib",
3550
srcs = glob(["*.scala"]),

test/shell/test_semanticdb.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ test_semanticdb_handles_removed_sourcefiles() {
177177

178178
}
179179

180+
test_semanticdb_synthetics_toolchain_scalaopt() {
181+
# Regression test: building with a toolchain that sets enable_semanticdb=True and
182+
# includes -P:semanticdb:synthetics:on in scalacopts should succeed. Previously it
183+
# failed because scala_library_for_plugin_bootstrapping (which compiles the dep
184+
# analyzer plugin) skipped phase_semanticdb, so the semanticdb plugin was never
185+
# loaded but the -P:semanticdb:... flag was still forwarded to scalac.
186+
set -e
187+
bazel build \
188+
--extra_toolchains="//test/semanticdb:semanticdb_synthetics_toolchain" \
189+
//test/semanticdb:all_lib
190+
}
191+
180192
run_semanticdb_tests() {
181193
local bundle=1; local nobundle=0
182194
local scala3=3; local scala2=2
@@ -191,6 +203,7 @@ run_semanticdb_tests() {
191203

192204
$runner test_no_semanticdb
193205
$runner test_semanticdb_handles_removed_sourcefiles
206+
$runner test_semanticdb_synthetics_toolchain_scalaopt
194207
}
195208

196209
run_semanticdb_tests

0 commit comments

Comments
 (0)