Skip to content
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ lazy val javacPlugin = project
.inAll
)
)
.dependsOn(semanticdb)
.dependsOn(semanticdb, scipProto)

lazy val scipProto = project
.in(file("scip-java-proto"))
Expand Down Expand Up @@ -693,6 +693,11 @@ lazy val fatjarPackageSettings = List[Def.Setting[_]](
MergeStrategy.discard
case PathList("META-INF", "versions", "9", "module-info.class") =>
MergeStrategy.discard
// Bazel BUILD files live next to *.proto sources in our subprojects; they are
// not needed at runtime and would conflict when multiple proto modules are
// merged into the same fat jar.
case PathList("BUILD") =>
MergeStrategy.discard
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.sourcegraph.scip_semanticdb.ConsoleScipSemanticdbReporter
import com.sourcegraph.scip_semanticdb.ScipOutputFormat
import com.sourcegraph.scip_semanticdb.ScipSemanticdb
import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions
import com.sourcegraph.scip_semanticdb.ScipShardAggregator
import moped.annotations._
import moped.cli.Application
import moped.cli.Command
Expand Down Expand Up @@ -60,6 +61,13 @@ final case class IndexSemanticdbCommand(
"Maven->Maven or Gradle->Gradle projects because those build tools compile sources to classfiles inside directories."
)
allowExportingGlobalSymbolsFromDirectoryEntries: Boolean = true,
@Description(
"If true, walk targetroots for *.scip shards (META-INF/scip/...) emitted by the " +
"compiler plugin instead of *.semanticdb files. The aggregator rewrites placeholder " +
"symbols into the final 'scip-java' scheme and merges per-source shards into the " +
"output index."
)
useScipShards: Boolean = false,
@Inline()
app: Application = Application.default
) extends Command {
Expand Down Expand Up @@ -108,7 +116,10 @@ final case class IndexSemanticdbCommand(
allowEmptyIndex,
allowExportingGlobalSymbolsFromDirectoryEntries
)
ScipSemanticdb.run(options)
if (useScipShards)
ScipShardAggregator.run(options)
else
ScipSemanticdb.run(options)
postPackages(packages)
if (!app.reporter.hasErrors()) {
app.info(options.output.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,37 @@ case class SnapshotCommand(
attrs: BasicFileAttributes
): FileVisitResult = {
if (scipPattern.matches(file)) {
foundScipFile = true
val index = Scip.Index.parseFrom(Files.readAllBytes(file))
val root = URI.create(index.getMetadata.getProjectRoot)
index
.getDocumentsList
.asScala
.foreach { doc =>
val sourcepath = Paths.get(root.resolve(doc.getRelativePath))
val source =
new String(
Files.readAllBytes(sourcepath),
StandardCharsets.UTF_8
// Skip per-source shards emitted by the compiler plugin (those don't have a
// project_root). The aggregator produces a single top-level index file that
// carries the project_root and is the canonical input for snapshot rendering.
val rawProjectRoot = index.getMetadata.getProjectRoot
if (rawProjectRoot.nonEmpty) {
foundScipFile = true
val projectRoot = URI.create(rawProjectRoot)
index
.getDocumentsList
.asScala
.foreach { doc =>
val sourcepath = Paths.get(projectRoot.resolve(doc.getRelativePath))
val source =
new String(
Files.readAllBytes(sourcepath),
StandardCharsets.UTF_8
)
val document = ScipPrinters.printTextDocument(
doc,
source,
CommentSyntax.default
)
val document = ScipPrinters.printTextDocument(
doc,
source,
CommentSyntax.default
)
val snapshotOutput = output.resolve(doc.getRelativePath)
Files.createDirectories(snapshotOutput.getParent)
Files.write(
snapshotOutput,
document.getBytes(StandardCharsets.UTF_8)
)
}
val snapshotOutput = output.resolve(doc.getRelativePath)
Files.createDirectories(snapshotOutput.getParent)
Files.write(
snapshotOutput,
document.getBytes(StandardCharsets.UTF_8)
)
}
}
}
super.visitFile(file, attrs)
}
Expand Down
Loading
Loading