Skip to content

Commit

Permalink
feat: add in ability to specify the output type
Browse files Browse the repository at this point in the history
This allows the user to pass in `--output dump.lsif` or just `dump.lsif`
or another valid output type to output other types than the default scip
which was happening before. If used the same way as before with no
argument the behavior is the same.

Refs: sourcegraph/scip-java#482
  • Loading branch information
ckipp01 committed Aug 24, 2022
1 parent 994abc8 commit d42a0b1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
8 changes: 7 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ object itest extends MillIntegrationTestModule {
T {
Seq(
PathRef(testBase / "minimal") -> Seq(
TestInvocation.Targets(Seq("generate"), noServer = true)
TestInvocation.Targets(Seq("generate"), noServer = true),
TestInvocation.Targets(Seq("lsif"), noServer = true),
TestInvocation.Targets(
Seq("fail"),
noServer = true,
expectedExitCode = 1
)
)
)
}
Expand Down
9 changes: 9 additions & 0 deletions itest/src/minimal/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ def generate(ev: Evaluator) = T.command {
// Then we ensure that the index.scip file was actually created
assertEquals(os.exists(scipFile), true)
}

def lsif(ev: Evaluator) = T.command {
val scipFile = Scip.generate(ev, "dump.lsif")()
assertEquals(os.exists(scipFile), true)
}

def fail(ev: Evaluator) = T.command {
Scip.generate(ev, "wrong.format")
}
51 changes: 44 additions & 7 deletions plugin/src/io/kipp/mill/scip/Scip.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import com.sourcegraph.scip_semanticdb.ScipSemanticdb
import com.sourcegraph.scip_semanticdb.ScipSemanticdbOptions
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
Expand All @@ -26,9 +28,12 @@ object Scip extends ExternalModule {
* producing semanticDB. Once we fully have all the semanticDB we call
* ScipSemanticdb to slurp it all up and create a SCIP index.
*/
def generate(ev: Evaluator) = T.command {
def generate(ev: Evaluator, output: String = "index.scip") = T.command {

val log = T.ctx().log

val outputFormat = validateFormat(output)()

val semanticdbVersion = ScipBuildInfo.semanticDBVersion

val modules = computeModules(ev)
Expand Down Expand Up @@ -200,8 +205,33 @@ object Scip extends ExternalModule {
}
.map(_.path)

createScip(log, T.dest, T.workspace, projects)
T.dest / "index.scip"
createScip(log, T.dest, T.workspace, projects, output, outputFormat)
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
Expand All @@ -215,14 +245,21 @@ object Scip extends ExternalModule {
* The current workspace root
* @param projects
* 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,
projects: Seq[Path]
projects: Seq[Path],
output: String,
outputFormat: ScipOutputFormat
): Unit = {
val scipFile = dest / "index.scip"

val scipFile = dest / output
val reporter = new ScipReporter(log)
val toolInfo =
LsifToolInfo
Expand All @@ -233,7 +270,7 @@ object Scip extends ExternalModule {
.setVersion(ScipBuildInfo.semanticDBJavaVersion)
.build()

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

// So this is maybe a bit opinionated here, but we're only writing this to
// disk for easier debugging. Normally scip-java can read this up to when
Expand All @@ -260,7 +297,7 @@ object Scip extends ExternalModule {
reporter,
toolInfo,
"java",
ScipOutputFormat.TYPED_PROTOBUF,
outputFormat,
true, // parallel -- this is fine
classPathEntries
.map(_.toPackageInformation)
Expand Down

0 comments on commit d42a0b1

Please sign in to comment.