Skip to content

Commit

Permalink
Merge pull request #49 from ckipp01/sbtVersion
Browse files Browse the repository at this point in the history
chore: bump sbt to 1.6.2 and move to unified slash syntax
  • Loading branch information
olafurpg authored Jun 9, 2022
2 parents 9909418 + 653f9cf commit 2281a9b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/sourcegraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
- uses: coursier/[email protected]
with:
jvm: adopt:8
apps: lsif-java
- run: lsif-java index
- run: cs launch --contrib scip-java -- index
- name: Upload LSIF data
uses: sourcegraph/lsif-upload-action@master
with:
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.2
sbt.version=1.6.2
9 changes: 6 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ sbt sourcegraphUpload

**Tasks**:

- `sourcegraphLsif`: compiles all projects in the build and generates an LSIF
- `sourcegraphScip`: compiles all projects in the build and generates an LSIF
index from the compiled SemanticDB files.
- `sourcegraphUpload`: uploads the LSIF index from `sourcegraphLsif` to
- `sourcegraphUpload`: uploads the LSIF index from `sourcegraphScip` to
Sourcegraph.

**Optional settings**:
Expand All @@ -155,10 +155,13 @@ sbt sourcegraphUpload
flags you may want to configure.
- `sourcegraphRoot: String`: root directory of this sbt build.

**Removed settings**:
**Removed settings and tasks**:

- (no longer used) `sourcegraphLsifSemanticdbBinary: String`: path to the
[`lsif-semanticdb`](https://github.com/sourcegraph/lsif-semanticdb/) binary.
- `sourcegraphLsif` which has now been replaced with `sourcegraphScip`
- `sourcegraphLsifVersion` which has now been replaced with
`sourcegraphScipVersion`

## Disable plugin for specific project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ object SourcegraphEnable {
enableSemanticdbPlugin =
List(
Option(
allDependencies.in(p) +=
(p / allDependencies) +=
"com.sourcegraph" % "semanticdb-javac" % semanticdbJavacVersion
),
Option(
javacOptions.in(p) += s"-Xplugin:semanticdb " +
(p / javacOptions) += s"-Xplugin:semanticdb " +
s"-build-tool:sbt " +
s"-sourceroot:${baseDirectory.in(ThisBuild).value} " +
s"-targetroot:${classDirectory.in(p, Compile).value.toPath().resolveSibling("semanticdb-classes")}"
s"-sourceroot:${(ThisBuild / baseDirectory).value} " +
s"-targetroot:${(p / Compile / classDirectory).value.toPath().resolveSibling("semanticdb-classes")}"
),
overriddenScalaVersion.map(v => scalaVersion.in(p) := v),
Option(SemanticdbPlugin.semanticdbEnabled.in(p) := true),
Option(SemanticdbPlugin.semanticdbVersion.in(p) := semanticdbVersion)
overriddenScalaVersion.map(v => (p / scalaVersion) := v),
Option((p / SemanticdbPlugin.semanticdbEnabled) := true),
Option((p / SemanticdbPlugin.semanticdbVersion) := semanticdbVersion)
).flatten
settings <-
inScope(ThisScope.in(p))(
Expand Down Expand Up @@ -78,17 +78,16 @@ object SourcegraphEnable {
extracted
)
isSemanticdbEnabled =
libraryDependencies
.in(p)
(p / libraryDependencies)
.get(extracted.structure.data)
.exists(_.exists(_.name == "semanticdb-scalac"))
if !isSemanticdbEnabled
addSemanticdbCompilerPlugin = List(
overriddenScalaVersion.map { v =>
scalaVersion.in(p) := v
(p / scalaVersion) := v
},
Option(
allDependencies.in(p) += compilerPlugin(
(p / allDependencies) += compilerPlugin(
SourcegraphPlugin.autoImport.sourcegraphSemanticdb(
semanticdbVersion
)
Expand All @@ -105,8 +104,8 @@ object SourcegraphEnable {

private val semanticdbConfigSettings: Seq[Def.Setting[_]] =
Seq(
scalacOptions.in(compile) := {
val old = scalacOptions.in(compile).value
(compile / scalacOptions) := {
val old = (compile / scalacOptions).value
val options = List(
"-Yrangepos",
"-Xplugin-require:semanticdb"
Expand All @@ -121,8 +120,7 @@ object SourcegraphEnable {
extracted: Extracted
): Seq[(ProjectRef, String, Option[String])] = for {
p <- extracted.structure.allProjectRefs
projectScalaVersion <- scalaVersion
.in(p)
projectScalaVersion <- (p / scalaVersion)
.get(extracted.structure.data)
.toList
overriddenScalaVersion =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.sourcegraph.sbtsourcegraph

import sbt._
import sbt.Keys._
import sbt._
import sbt.internal.sbtsourcegraph.Compat
import sbt.plugins.JvmPlugin
import scala.collection.JavaConverters._

import java.io.File
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.nio.file.StandardOpenOption
import sbt.internal.sbtsourcegraph.Compat
import scala.collection.JavaConverters._

object SourcegraphPlugin extends AutoPlugin {
override def trigger = allRequirements
Expand All @@ -18,7 +19,7 @@ object SourcegraphPlugin extends AutoPlugin {
taskKey[Unit](
"Task to upload the LSIF index to Sourcegraph to enable precise code intelligence."
)
val sourcegraphLsif: TaskKey[File] =
val sourcegraphScip: TaskKey[File] =
taskKey[File](
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
)
Expand All @@ -30,13 +31,12 @@ object SourcegraphPlugin extends AutoPlugin {
taskKey[File](
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
)
val sourcegraphLsifJavaVersion: SettingKey[String] =
settingKey[String]("The version of the `lsif-java` command-line tool.")
val sourcegraphScipJavaVersion: SettingKey[String] =
settingKey[String]("The version of the `scip-java` command-line tool.")
val sourcegraphSemanticdbDirectories: TaskKey[List[File]] =
taskKey[List[File]](
"Task to compile all projects in this build and aggregate all SemanticDB directories."
)

val sourcegraphEndpoint: TaskKey[Option[String]] =
taskKey[Option[String]](
"URL of your Sourcegraph instance. By default, uploads to https://sourcegraph.com."
Expand Down Expand Up @@ -79,9 +79,8 @@ object SourcegraphPlugin extends AutoPlugin {
import autoImport._

override lazy val buildSettings: Seq[Def.Setting[_]] = List(
sourcegraphLsifJavaVersion := {
scala.util.Properties
.propOrElse("lsif-java-version", Versions.semanticdbJavacVersion())
sourcegraphScipJavaVersion := {
scala.util.Properties.propOrElse("scip-java-version", Versions.semanticdbJavacVersion())
},
sourcegraphTargetRoots := {
val directories =
Expand All @@ -100,7 +99,7 @@ object SourcegraphPlugin extends AutoPlugin {
},
sourcegraphTargetRootsFile := {
val roots = sourcegraphTargetRoots.value
val out = target.in(Sourcegraph).value / "targetroots.txt"
val out = (Sourcegraph / target).value / "targetroots.txt"
Files.createDirectories(out.toPath().getParent())
Files.write(
out.toPath(),
Expand All @@ -110,14 +109,16 @@ object SourcegraphPlugin extends AutoPlugin {
)
out
},
sourcegraphLsif := {
val out = target.in(Sourcegraph).value / "dump.lsif"
sourcegraphScip := {
val out = (Sourcegraph / target).value / "dump.lsif"
out.getParentFile.mkdirs()
runProcess(
sourcegraphCoursierBinary.value ::
"launch" ::
"--contrib" ::
s"lsif-java:${sourcegraphLsifJavaVersion.value}" ::
s"scip-java:${sourcegraphScipJavaVersion.value}" ::
"-M" ::
"com.sourcegraph.scip_java.ScipJava" ::
"--" ::
"index-semanticdb" ::
s"--output=$out" ::
Expand All @@ -134,7 +135,7 @@ object SourcegraphPlugin extends AutoPlugin {
"in https://github.com/sourcegraph/sbt-sourcegraph/blob/main/README.md"
)
}
val in = sourcegraphLsif.value
val in = sourcegraphScip.value
val uploadCommand = List[Option[String]](
Some(sourcegraphSrcBinary.value),
sourcegraphEndpoint.value.map(url => s"--endpoint=$url"),
Expand All @@ -157,11 +158,11 @@ object SourcegraphPlugin extends AutoPlugin {
sourcegraphSrcBinary := "src",
sourcegraphEndpoint := None,
sourcegraphExtraUploadArguments := Nil,
sourcegraphRoot := baseDirectory.in(ThisBuild).value,
target.in(Sourcegraph) := baseDirectory.in(ThisBuild).value /
sourcegraphRoot := (ThisBuild / baseDirectory).value,
(Sourcegraph / target) := (ThisBuild / baseDirectory).value /
"target" / "sbt-sourcegraph",
sourcegraphCoursierBinary := createCoursierBinary(
target.in(Sourcegraph).value
(Sourcegraph / target).value
)
)

Expand Down Expand Up @@ -258,8 +259,8 @@ object SourcegraphPlugin extends AutoPlugin {

val relaxScalacOptionsConfigSettings: Seq[Def.Setting[_]] =
Seq(
scalacOptions.in(compile) := {
val options = scalacOptions.in(compile).value
(compile / scalacOptions) := {
val options = (compile / scalacOptions).value
options.filterNot { option =>
scalacOptionsToRelax.exists(_.matcher(option).matches)
}
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-sourcegraph/basic/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
> sourcegraphEnable
> sourcegraphLsif
> sourcegraphScip
> checkLsif

0 comments on commit 2281a9b

Please sign in to comment.