Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor implementation to use public scip-java API #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ out/
.bsp/
.bloop/
index.scip
.vscode/
79 changes: 7 additions & 72 deletions plugin/src-mill0.10/io/kipp/mill/scip/Scip.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package io.kipp.mill.scip

import com.sourcegraph.lsif_protocol.LsifToolInfo
import com.sourcegraph.scip_semanticdb.ScipOutputFormat
import com.sourcegraph.scip_semanticdb.ScipSemanticdb
import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions
import com.sourcegraph.scip_java.ScipJava
import mill._
import mill.api.Logger
import mill.api.Result
import mill.define.ExternalModule
import mill.define.Task
import mill.eval.Evaluator
import mill.main.EvaluatorScopt
import mill.scalalib.JavaModule
import mill.scalalib.ScalaModule
import mill.scalalib.api.ZincWorkerUtil.isScala3
import os.Path

import scala.jdk.CollectionConverters._
import scala.util.Properties

object Scip extends ExternalModule {
Expand All @@ -33,8 +27,6 @@ object Scip extends ExternalModule {

val log = T.ctx().log

val outputFormat = validateFormat(output)()

val semanticdbVersion = ScipBuildInfo.semanticDBVersion

val modules = computeModules(ev)
Expand Down Expand Up @@ -231,35 +223,10 @@ object Scip extends ExternalModule {
}
.map(_.path)

createScip(log, T.dest, T.workspace, classpath, output, outputFormat)
createScip(log, T.dest, T.workspace, classpath, output)
T.dest / output
}

/** Given an output string, determine that a ScipOutputFormat can be
* determined from it.
*
* @param output
* the given output from the user
* @return
* the parsed output format to be generated
*/
private def validateFormat(output: String): Task[ScipOutputFormat] = T.task {
val format = ScipOutputFormat.fromFilename(output)
if (format == ScipOutputFormat.UNKNOWN) {
val msg =
s"""Detected an unknown output type. You'll want to use one of the following:
|
| - *.lsif
| - *.lsif-protobuf
| - *.scip
| - *.scip.ndjson
|""".stripMargin
Result.Failure(msg)
} else {
format
}
}

/** After all the semanticDB has been produced we can create the SCIP index
* from it.
*
Expand All @@ -273,28 +240,16 @@ object Scip extends ExternalModule {
* Full classpath of the project to be used for cross-project navigation.
* @param output
* The name out of the output file
* @param outputFormat
* The format of the output
*/
private def createScip(
log: Logger,
dest: Path,
workspace: Path,
classpath: Seq[Path],
output: String,
outputFormat: ScipOutputFormat
output: String
): Unit = {

val scipFile = dest / output
val reporter = new ScipReporter(log)
val toolInfo =
LsifToolInfo
.newBuilder()
.setName(
"scip-java"
) // Make sure this stays a recognized name by src or it won't index deps. Don't use mill-scip.
.setVersion(ScipBuildInfo.semanticDBJavaVersion)
.build()

log.info(s"Creating a ${output} in ${scipFile}")

Expand All @@ -311,30 +266,10 @@ object Scip extends ExternalModule {
createFolders = true
)

val classPathEntries =
classpath.flatMap(project => ClasspathEntry.fromPom(project.toNIO))

log.info(s"Including ${classPathEntries.size} classpath entries")

val options = new ScipSemanticdbOptions(
List(dest).map(_.toNIO).asJava,
scipFile.toNIO,
workspace.toNIO,
reporter,
toolInfo,
"java",
outputFormat,
true, // parallel -- this is fine
classPathEntries
.map(_.toPackageInformation)
.asJava,
"", // BuildKind here is fine being ""
true, // emit inverse releationships,
false, // we want to fail with mill if no documents have been indexed
false // we're only dealing with jar files here
)

ScipSemanticdb.run(options)
val exit = ScipJava.app.run(List("index-semanticdb", "--cwd", workspace.toString, "--output", scipFile.toString, dest.toString))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the classpath entries aren't being included here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classpath is automatically inferred from javacopts.txt, which is written to the targetroot

if (exit != 0) {
sys.error("Failed to create SCIP index")
}
}

private def computeModules(ev: Evaluator) =
Expand Down
75 changes: 6 additions & 69 deletions plugin/src-mill0.11/io/kipp/mill/scip/Scip.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package io.kipp.mill.scip

import com.sourcegraph.lsif_protocol.LsifToolInfo
import com.sourcegraph.scip_semanticdb.ScipOutputFormat
import com.sourcegraph.scip_semanticdb.ScipSemanticdb
import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions
import com.sourcegraph.scip_java.ScipJava
import mill._
import mill.api.BuildInfo
import mill.api.Logger
import mill.api.Result
import mill.define.ExternalModule
import mill.define.Task
import mill.eval.Evaluator
import mill.scalalib.JavaModule
import mill.scalalib.ScalaModule
import mill.scalalib.api.ZincWorkerUtil.isScala3
import os.Path

import scala.jdk.CollectionConverters._
import scala.util.Properties

object Scip extends ExternalModule {
Expand All @@ -33,8 +27,6 @@ object Scip extends ExternalModule {

val log = T.ctx().log

val outputFormat = validateFormat(output)()

val semanticdbVersion = ScipBuildInfo.semanticDBVersion

val modules = computeModules(ev)
Expand Down Expand Up @@ -229,35 +221,10 @@ object Scip extends ExternalModule {
}
.map(_.path)

createScip(log, T.dest, T.workspace, classpath, output, outputFormat)
createScip(log, T.dest, T.workspace, classpath, output)
T.dest / output
}

/** Given an output string, determine that a ScipOutputFormat can be
* determined from it.
*
* @param output
* the given output from the user
* @return
* the parsed output format to be generated
*/
private def validateFormat(output: String): Task[ScipOutputFormat] = T.task {
val format = ScipOutputFormat.fromFilename(output)
if (format == ScipOutputFormat.UNKNOWN) {
val msg =
s"""Detected an unknown output type. You'll want to use one of the following:
|
| - *.lsif
| - *.lsif-protobuf
| - *.scip
| - *.scip.ndjson
|""".stripMargin
Result.Failure(msg)
} else {
format
}
}

/** After all the semanticDB has been produced we can create the SCIP index
* from it.
*
Expand All @@ -280,19 +247,9 @@ object Scip extends ExternalModule {
workspace: Path,
classpath: Seq[Path],
output: String,
outputFormat: ScipOutputFormat
): Unit = {

val scipFile = dest / output
val reporter = new ScipReporter(log)
val toolInfo =
LsifToolInfo
.newBuilder()
.setName(
"scip-java"
) // Make sure this stays a recognized name by src or it won't index deps. Don't use mill-scip.
.setVersion(ScipBuildInfo.semanticDBJavaVersion)
.build()

log.info(s"Creating a ${output} in ${scipFile}")

Expand All @@ -309,30 +266,10 @@ object Scip extends ExternalModule {
createFolders = true
)

val classPathEntries =
classpath.flatMap(project => ClasspathEntry.fromPom(project.toNIO))

log.info(s"Including ${classPathEntries.size} classpath entries")

val options = new ScipSemanticdbOptions(
List(dest).map(_.toNIO).asJava,
scipFile.toNIO,
workspace.toNIO,
reporter,
toolInfo,
"java",
outputFormat,
true, // parallel -- this is fine
classPathEntries
.map(_.toPackageInformation)
.asJava,
"", // BuildKind here is fine being ""
true, // emit inverse releationships
false, // we want to fail with mill if no documents have been indexed
false // we're only dealing with jar files here
)

ScipSemanticdb.run(options)
val exit = ScipJava.app.run(List("index-semanticdb", "--cwd", workspace.toString, "--output", scipFile.toString, dest.toString))
if (exit != 0) {
sys.error("Failed to create SCIP index")
}
}

private def computeModules(ev: Evaluator) =
Expand Down
45 changes: 0 additions & 45 deletions plugin/src/io/kipp/mill/scip/ClasspathEntry.scala

This file was deleted.

31 changes: 0 additions & 31 deletions plugin/src/io/kipp/mill/scip/ScipReporter.scala

This file was deleted.