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

Update everything to SCIP #51

Open
wants to merge 4 commits 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
9 changes: 5 additions & 4 deletions .github/workflows/pr-auditor.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name: pr-auditor
on:
pull_request:
types: [ closed, edited, opened ]
types: [closed, edited, opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with: { repository: 'sourcegraph/sourcegraph' }
with: { repository: "sourcegraph/sourcegraph" }
- uses: actions/setup-go@v2
with: { go-version: '1.17' }
with: { go-version: "1.18" }

- run: ./dev/pr-auditor/check-pr.sh
env:
GITHUB_EVENT_PATH: ${{ env.GITHUB_EVENT_PATH }}
GITHUB_TOKEN: ${{ secrets.CODENOTIFY_GITHUB_TOKEN }}
GITHUB_RUN_URL: https://github.com/sourcegraph/infrastructure/actions/runs/${{ github.run_id }}
GITHUB_RUN_URL: |
https://github.com/sourcegraph/infrastructure/actions/runs/${{ github.run_id }}
20 changes: 10 additions & 10 deletions .github/workflows/sourcegraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ on:
- main
pull_request:
jobs:
lsif:
sourcegraph:
runs-on: ubuntu-latest
name: "Upload LSIF"
name: "Upload Sourcegraph Code Intel"
steps:
- uses: actions/checkout@v2
- uses: coursier/[email protected]
with:
jvm: adopt:8
apps: lsif-java
- run: lsif-java index
- name: Upload LSIF data
uses: sourcegraph/lsif-upload-action@master
with:
endpoint: https://sourcegraph.com
github_token: ${{ secrets.GITHUB_TOKEN }}
file: dump.lsif
- name: cs launch scip-java
run: |
cs launch com.sourcegraph:lsif-java_2.13:latest.stable -M com.sourcegraph.lsif_java.LsifJava -- index

Choose a reason for hiding this comment

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

Suggested change
cs launch com.sourcegraph:lsif-java_2.13:latest.stable -M com.sourcegraph.lsif_java.LsifJava -- index
cs launch com.sourcegraph:scip-java_2.13:latest.stable -M com.sourcegraph.scip_java.ScipJava -- index

I confirmed it works in my local environment

- run: yarn install @sourcegraph/src
- run: |
src code-intel upload "-commit=${GITHUB_SHA}" "-github-token=${GITHUB_TOKEN}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ out/
*.hnir
test-report.json
dump.lsif
index.scip
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
19 changes: 11 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ disable the upload job for pull requests and use Java 11.
- main
- pull_request:
jobs:
lsif:
sourcegraph:
steps:
- uses: olafurpg/setup-scala@v10
+ with:
Expand Down Expand Up @@ -129,16 +129,16 @@ sbt sourcegraphUpload

**Environment variables**:

- (required) `GITHUB_TOKEN`: GitHub access token that's used to upload the LSIF
- (required) `GITHUB_TOKEN`: GitHub access token that's used to upload the SCIP
index.
- (optional) `GITHUB_SHA`: the git commit sha that the LSIF index should be
- (optional) `GITHUB_SHA`: the git commit sha that the SCIP index should be
associated with on Sourcegraph.

**Tasks**:

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

**Optional settings**:
Expand All @@ -151,14 +151,17 @@ sbt sourcegraphUpload
[`src`](https://github.com/sourcegraph/src-cli) binary. The `src` binary needs
to be installed separately.
- `sourcegraphExtraUploadArguments: List[String]`: additional arguments to use
for the `src lsif upload` command. Run `src lsif upload --help` for example
flags you may want to configure.
for the `src code-intel upload` command. Run `src code-intel upload --help`
for example 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
`sourcegraphScipJavaVersion`

## 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,42 +1,42 @@
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
override def requires = JvmPlugin
object autoImport {
val sourcegraphUpload: TaskKey[Unit] =
taskKey[Unit](
"Task to upload the LSIF index to Sourcegraph to enable precise code intelligence."
"Task to upload the SCIP 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."
"Task to generate a single SCIP index for all SemanticDB files in this workspace."
)
val sourcegraphTargetRoots: TaskKey[List[String]] =
taskKey[List[String]](
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
"Task to generate a single SCIP index for all SemanticDB files in this workspace."
)
val sourcegraphTargetRootsFile: TaskKey[File] =
taskKey[File](
"Task to generate a single LSIF index for all SemanticDB files in this workspace."
"Task to generate a single SCIP 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 All @@ -51,11 +51,11 @@ object SourcegraphPlugin extends AutoPlugin {
)
val sourcegraphExtraUploadArguments: TaskKey[List[String]] =
taskKey[List[String]](
"Additional arguments to pass to `src lsif upload`. Use this setting to specify flags like --commit, --repo, --github-token, --root or --upload-route."
"Additional arguments to pass to `src code-intel upload`. Use this setting to specify flags like --commit, --repo, --github-token, --root or --upload-route."
)
val sourcegraphRoot: TaskKey[File] =
taskKey[File](
"The --root argument to the 'src lsif upload' command. By default, uses root directory of this build."
"The --root argument to the 'src code-intel upload' command. By default, uses root directory of this build."
)
val sourcegraphScalacTargetroot: TaskKey[File] =
taskKey[File](
Expand All @@ -79,9 +79,9 @@ object SourcegraphPlugin extends AutoPlugin {
import autoImport._

override lazy val buildSettings: Seq[Def.Setting[_]] = List(
sourcegraphLsifJavaVersion := {
sourcegraphScipJavaVersion := {
scala.util.Properties
.propOrElse("lsif-java-version", Versions.semanticdbJavacVersion())
.propOrElse("scip-java-version", Versions.semanticdbJavacVersion())
},
sourcegraphTargetRoots := {
val directories =
Expand All @@ -92,15 +92,15 @@ object SourcegraphPlugin extends AutoPlugin {
.distinct
if (directoryArguments.isEmpty) {
throw new TaskException(
"Can't upload LSIF index to Sourcegraph because there are no SemanticDB directories. " +
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphLsif` like this: sbt sourcegraphEnable sourcegraphLsif"
"Can't upload SCIP index to Sourcegraph because there are no SemanticDB directories. " +
"To fix this problem, run the `sourcegraphEnable` command before `sourcegraphScip` like this: sbt sourcegraphEnable sourcegraphScip"
)
}
directoryArguments
},
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 +110,15 @@ object SourcegraphPlugin extends AutoPlugin {
)
out
},
sourcegraphLsif := {
val out = target.in(Sourcegraph).value / "dump.lsif"
sourcegraphScip := {
val out = (Sourcegraph / target).value / "index.scip"
out.getParentFile.mkdirs()
runProcess(
sourcegraphCoursierBinary.value ::
"launch" ::
"--contrib" ::
s"lsif-java:${sourcegraphLsifJavaVersion.value}" ::
s"com.sourcegraph:scip-java_2.13:${sourcegraphScipJavaVersion.value}" ::
"-M" ::
"com.sourcegraph.scip_java.ScipJava" ::
"--" ::
"index-semanticdb" ::
s"--output=$out" ::
Expand All @@ -134,11 +135,11 @@ 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"),
Some("lsif"),
Some("code-intel"),
Some("upload"),
Option(System.getenv("GITHUB_TOKEN"))
.map(token => s"--github-token=$token"),
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
4 changes: 2 additions & 2 deletions src/main/scala/com/sourcegraph/sbtsourcegraph/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.collection.JavaConverters._
import scala.sys.process._

object Versions {
def scalametaVersion = "4.4.26"
def scalametaVersion = "4.5.9"
private def semanticdbJavacKey = "semanticdb-javac"

def semanticdbJavacVersion(): String =
Expand All @@ -25,7 +25,7 @@ object Versions {
props.asScala.toMap
} else {
Map(
semanticdbJavacKey -> "0.6.3",
semanticdbJavacKey -> "0.8.0",
"2.12.12" -> scalametaVersion,
"2.13.6" -> scalametaVersion,
"2.11.12" -> scalametaVersion
Expand Down
29 changes: 8 additions & 21 deletions src/sbt-test/sbt-sourcegraph/basic/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,14 @@ lazy val a = project
lazy val b = project
.dependsOn(a)

commands += Command.command("checkLsif") { s =>
commands += Command.command("checkSourcegraph") { s =>
val dumpPath =
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "dump.lsif"
val dump = Files.readAllLines(dumpPath.toPath).asScala
val packageInformation =
""".*"name":"(.*)","manager":"jvm-dependencies"}""".r
val jvmDependencies = dump
.collect { case packageInformation(name) =>
name
}
.distinct
.sorted
if (
jvmDependencies != List(
"jdk",
"maven/com.lihaoyi/geny_2.12",
"maven/junit/junit",
"maven/org.scala-lang/scala-library"
)
) {
sys.error(jvmDependencies.toString)
}
(ThisBuild / baseDirectory).value / "target" / "sbt-sourcegraph" / "index.scip"
val index =
lib.codeintel.scip.Scip.Index.parseFrom(Files.readAllBytes(dumpPath.toPath))
val occurrences = index.getDocumentsList.asScala
.flatMap(_.getOccurrencesList.asScala)
.map(_.getSymbol)
println(occurrences)
s
}
Loading