Skip to content

Commit a244bfe

Browse files
committed
PR1 (M8): Make compiler-side SCIP shard emission the default
After M3-M7 the per-source SCIP shard format is stable and the ScipShardAggregator produces equivalent output to the legacy SemanticDB->SCIP path. This commit promotes the cheap compiler-side half of the dual-emission to be on by default so that: - any javac plugin invocation (sbt, Maven, Bazel, ad-hoc) writes a *.scip shard under META-INF/scip/ alongside the *.semanticdb file without needing an explicit -emit-scip:on flag; - users (or build tools) that want to consume the new path only need to flip the CLI switch (--use-scip-shards) once the indexer runs; - legacy callers that only read *.semanticdb files are unaffected. The CLI default for index-semanticdb's --use-scip-shards remains false because the broader ecosystem (notably the Kotlin compiler and the existing snapshot/build tool integrations) still produces only *.semanticdb. That flip is deferred to a follow-up PR. semanticdb-javac: - SemanticdbJavacOptions.emitScip defaults to true. -emit-scip:off is now the explicit opt-out and is documented as the legacy path. scip-java: - SnapshotCommand: skip per-source shards (those without a metadata.project_root) so 'scip-java snapshot' continues to render only the top-level aggregator output. Per-source shards have no project_root and would otherwise crash with 'missing scheme' when their relative paths are resolved into a URI. build.sbt: - Drop the now-redundant -emit-scip:on flag from the minimized project; the plugin default already emits shards. tests/unit: - ScipShardEmissionSuite: invert the off-path test so it explicitly passes -emit-scip:off; the previous test relied on the old default of false. Full snapshot suite (102 tests) and unit suite (30 tests) green.
1 parent eab3f1c commit a244bfe

4 files changed

Lines changed: 42 additions & 30 deletions

File tree

build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ lazy val minimizedSettings = List[Def.Setting[_]](
550550
s"-build-tool:sbt",
551551
s"-text:on",
552552
s"-verbose",
553-
s"-emit-scip:on",
554553
s"-sourceroot:${(ThisBuild / baseDirectory).value}",
555554
s"-targetroot:${(Compile / semanticdbTargetRoot).value}",
556555
s"-randomtimestamp=${System.nanoTime()}"

scip-java/src/main/scala/com/sourcegraph/scip_java/commands/SnapshotCommand.scala

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,37 @@ case class SnapshotCommand(
5151
attrs: BasicFileAttributes
5252
): FileVisitResult = {
5353
if (scipPattern.matches(file)) {
54-
foundScipFile = true
5554
val index = Scip.Index.parseFrom(Files.readAllBytes(file))
56-
val root = URI.create(index.getMetadata.getProjectRoot)
57-
index
58-
.getDocumentsList
59-
.asScala
60-
.foreach { doc =>
61-
val sourcepath = Paths.get(root.resolve(doc.getRelativePath))
62-
val source =
63-
new String(
64-
Files.readAllBytes(sourcepath),
65-
StandardCharsets.UTF_8
55+
// Skip per-source shards emitted by the compiler plugin (those don't have a
56+
// project_root). The aggregator produces a single top-level index file that
57+
// carries the project_root and is the canonical input for snapshot rendering.
58+
val rawProjectRoot = index.getMetadata.getProjectRoot
59+
if (rawProjectRoot.nonEmpty) {
60+
foundScipFile = true
61+
val projectRoot = URI.create(rawProjectRoot)
62+
index
63+
.getDocumentsList
64+
.asScala
65+
.foreach { doc =>
66+
val sourcepath = Paths.get(projectRoot.resolve(doc.getRelativePath))
67+
val source =
68+
new String(
69+
Files.readAllBytes(sourcepath),
70+
StandardCharsets.UTF_8
71+
)
72+
val document = ScipPrinters.printTextDocument(
73+
doc,
74+
source,
75+
CommentSyntax.default
6676
)
67-
val document = ScipPrinters.printTextDocument(
68-
doc,
69-
source,
70-
CommentSyntax.default
71-
)
72-
val snapshotOutput = output.resolve(doc.getRelativePath)
73-
Files.createDirectories(snapshotOutput.getParent)
74-
Files.write(
75-
snapshotOutput,
76-
document.getBytes(StandardCharsets.UTF_8)
77-
)
78-
}
77+
val snapshotOutput = output.resolve(doc.getRelativePath)
78+
Files.createDirectories(snapshotOutput.getParent)
79+
Files.write(
80+
snapshotOutput,
81+
document.getBytes(StandardCharsets.UTF_8)
82+
)
83+
}
84+
}
7985
}
8086
super.visitFile(file, attrs)
8187
}

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ public class SemanticdbJavacOptions {
2525
public boolean includeText = false;
2626
public boolean verboseEnabled = false;
2727
/**
28-
* When {@code true}, the plugin also emits {@code *.scip} shards under {@code META-INF/scip/...}
29-
* alongside the existing {@code *.semanticdb} files. Defaults to {@code false} during the
30-
* SemanticDB→SCIP transition.
28+
* Controls whether the plugin emits {@code *.scip} shards under {@code META-INF/scip/...}
29+
* alongside the existing {@code *.semanticdb} files. Defaults to {@code true}: producing the
30+
* extra shard is cheap and lets the {@code scip-java index-semanticdb --use-scip-shards}
31+
* pipeline run without any additional compiler-side configuration. Legacy users that only
32+
* consume {@code .semanticdb} are unaffected. Pass {@code -emit-scip:off} to disable.
3133
*/
32-
public boolean emitScip = false;
34+
public boolean emitScip = true;
3335

3436
public final ArrayList<String> errors;
3537
public boolean alreadyReportedErrors = false;

tests/unit/src/test/scala/tests/ScipShardEmissionSuite.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,17 @@ class ScipShardEmissionSuite extends FunSuite {
103103
assert(barText.contains("int bar("), s"unexpected bar signature: $barText")
104104
}
105105

106-
test("compiler does not emit SCIP shards when -emit-scip is off") {
106+
test("compiler does not emit SCIP shards when -emit-scip:off is set") {
107107
val targetroot = Files.createTempDirectory("scip-shard-off-")
108108
val sourceroot = Files.createTempDirectory("scip-shard-off-src-")
109109
val compiler =
110110
new TestCompiler(TestCompiler.PROCESSOR_PATH, Nil, targetroot, sourceroot)
111-
val result = compiler.compileSemanticdb(Seq(source))
111+
val result = compiler.compile(
112+
Seq(source),
113+
List(
114+
s"-Xplugin:semanticdb -emit-scip:off -text:on -sourceroot:$sourceroot -targetroot:$targetroot"
115+
)
116+
)
112117
assert(result.isSuccess, s"javac failed:\n${result.stdout}")
113118

114119
val scipPath = targetroot.resolve("META-INF/scip/example/Foo.java.scip")

0 commit comments

Comments
 (0)