Skip to content

Commit 6c1901e

Browse files
committed
Drop SemanticDB from javac compiler plug-in; emit SCIP shards directly
Rebased onto origin/main (post #899's semanticdb-shared extraction). - semanticdb-javac: replace SemanticDB protobuf emission with SCIP shards (ScipShardWriter/Aggregator/Occurrences/Symbols/Signatures + ScipVisitor). - semanticdb-kotlinc: add the SCIP shard infrastructure alongside the existing SemanticDB code path (dropped fully in stacked PR B). - scip-semanticdb: ScipShardAggregator walks per-source shards, applies SymbolRewriter, and merges into a single Index. - Use the shared semanticdb-shared module's symbol/builder utilities.
1 parent 68ae888 commit 6c1901e

81 files changed

Lines changed: 4056 additions & 2749 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.sbt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ lazy val javacPlugin = project
137137
fatjarPackageSettings,
138138
javaOnlySettings,
139139
moduleName := "semanticdb-javac",
140+
libraryDependencies +=
141+
"org.scip-code" % "scip-java-bindings" % V.scipBindings,
140142
// Scoped to compile so doc tasks (which reject -g) are unaffected.
141143
Compile / compile / javacOptions += "-g",
142144
// JDK 14+ ServiceLoader-scans the classpath for Plugin providers; our
@@ -358,8 +360,14 @@ lazy val semanticdbKotlinc = project
358360
// classpath via Provided so the assembled fat-jar does not bundle it.
359361
libraryDependencies +=
360362
"org.jetbrains.kotlin" % "kotlin-stdlib" % V.kotlinVersion % Provided,
361-
// The SemanticDB proto schema and the generated Java classes live in
362-
// semanticdbShared; we get them transitively via .dependsOn below.
363+
// protobuf java codegen — proto file lives at src/main/proto/...
364+
Compile / PB.protoSources :=
365+
Seq((Compile / sourceDirectory).value / "proto"),
366+
Compile / PB.targets :=
367+
Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value),
368+
libraryDependencies += "com.google.protobuf" % "protobuf-java" % V.protobuf,
369+
libraryDependencies +=
370+
"org.scip-code" % "scip-java-bindings" % V.scipBindings,
363371
// kotlin-compiler-embeddable is supplied by kotlinc at runtime
364372
libraryDependencies +=
365373
"org.jetbrains.kotlin" % "kotlin-compiler-embeddable" % V.kotlinVersion %
@@ -432,7 +440,6 @@ lazy val semanticdbKotlinc = project
432440
Attributed.blank(dir)
433441
}
434442
)
435-
.dependsOn(semanticdbShared)
436443

437444
// `semanticdbKotlincMinimized` mirrors the (still-present) Gradle build at
438445
// semanticdb-kotlinc/minimized/build.gradle.kts. It compiles a small set of
@@ -517,15 +524,19 @@ lazy val semanticdbKotlincMinimized = project
517524
val snapDir =
518525
(baseDirectory.value / "src" / "generatedSnapshots" / "resources")
519526
.getAbsolutePath
520-
val scipOut = s"$tgtRoot/index.scip"
527+
// Write `index.scip` outside the shard-scanned targetroot to avoid re-ingestion.
528+
val scipOut = (target.value / "scip-index" / "index.scip")
529+
.getAbsolutePath
521530
val mainCls = "com.sourcegraph.scip_java.ScipJava"
522531
Def.sequential(
523532
Compile / compile,
524533
(cli / Compile / runMain).toTask(
525-
s" $mainCls index-semanticdb --no-emit-inverse-relationships --cwd $srcRoot --output $scipOut $tgtRoot"
534+
s" $mainCls index-semanticdb --no-emit-inverse-relationships --use-scip-shards --cwd $srcRoot --output $scipOut $tgtRoot"
526535
),
527536
(cli / Compile / runMain).toTask(
528-
s" $mainCls snapshot --cwd $srcRoot --output $snapDir $tgtRoot"
537+
s" $mainCls snapshot --cwd $srcRoot --output $snapDir ${file(
538+
scipOut
539+
).getParentFile.getAbsolutePath}"
529540
)
530541
)
531542
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.sourcegraph.scip_java.buildtools.ClasspathEntry
1212
import com.sourcegraph.scip_semanticdb.ConsoleScipSemanticdbReporter
1313
import com.sourcegraph.scip_semanticdb.ScipSemanticdb
1414
import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions
15+
import com.sourcegraph.scip_semanticdb.ScipShardAggregator
1516
import moped.annotations._
1617
import moped.cli.Application
1718
import moped.cli.Command
@@ -59,6 +60,11 @@ final case class IndexSemanticdbCommand(
5960
"Maven->Maven or Gradle->Gradle projects because those build tools compile sources to classfiles inside directories."
6061
)
6162
allowExportingGlobalSymbolsFromDirectoryEntries: Boolean = true,
63+
@Description(
64+
"If true, aggregate *.scip shards under META-INF/scip/ instead of *.semanticdb files. " +
65+
"Pass --use-scip-shards=false to fall back to the SemanticDB-based aggregator."
66+
)
67+
useScipShards: Boolean = true,
6268
@Inline()
6369
app: Application = Application.default
6470
) extends Command {
@@ -96,7 +102,10 @@ final case class IndexSemanticdbCommand(
96102
allowEmptyIndex,
97103
allowExportingGlobalSymbolsFromDirectoryEntries
98104
)
99-
ScipSemanticdb.run(options)
105+
if (useScipShards)
106+
ScipShardAggregator.run(options)
107+
else
108+
ScipSemanticdb.run(options)
100109
postPackages(packages)
101110
if (!app.reporter.hasErrors()) {
102111
app.info(options.output.toString)

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 = 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 (no project_root); only the aggregator output carries it.
56+
val rawProjectRoot = index.getMetadata.getProjectRoot
57+
if (rawProjectRoot.nonEmpty) {
58+
foundScipFile = true
59+
val projectRoot = URI.create(rawProjectRoot)
60+
index
61+
.getDocumentsList
62+
.asScala
63+
.foreach { doc =>
64+
val sourcepath = Paths.get(
65+
projectRoot.resolve(doc.getRelativePath)
6666
)
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-
}
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
76+
)
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
}

0 commit comments

Comments
 (0)