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

Cross-build sbt-metals for sbt2 #7045

Merged
merged 5 commits into from
Dec 19, 2024
Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
os: macOS-latest
java: "17"
- type: sbt
command: bin/test.sh 'slow/testOnly -- tests.sbt.*'
command: bin/test.sh '+sbt-metals/publishLocal; slow/testOnly -- tests.sbt.*'
name: Sbt integration
os: ubuntu-latest
java: "17"
Expand All @@ -72,6 +72,11 @@ jobs:
name: Sbt-metals/scripted jdk11
os: ubuntu-latest
java: "11"
- type: sbt-metals Sbt 2
command: bin/test.sh '++3.6.2; sbt-metals/scripted'
name: sbt-metals/scripted (Sbt 2)
os: ubuntu-latest
java: "17"
- type: maven
command: bin/test.sh 'slow/testOnly -- tests.maven.*'
name: Maven integration
Expand Down Expand Up @@ -145,6 +150,7 @@ jobs:
- name: ${{ matrix.command }}
run: ${{ matrix.command }}
env:
METALS_TEST: true
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
GOOGLE_APPLICATION_CREDENTIALS_JSON: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}
- name: "test download dependencies"
Expand Down
16 changes: 15 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Global / resolvers += "scala-integration" at

def localSnapshotVersion = "1.4.3-SNAPSHOT"
def isCI = System.getenv("CI") != null
def isTest = System.getenv("METALS_TEST") != null

def isScala211(v: Option[(Long, Long)]): Boolean = v.contains((2, 11))
def isScala212(v: Option[(Long, Long)]): Boolean = v.contains((2, 12))
Expand Down Expand Up @@ -41,7 +42,7 @@ ThisBuild / semanticdbVersion := V.semanticdb(scalaVersion.value)
inThisBuild(
List(
version ~= { dynVer =>
if (isCI) dynVer
if (isCI && !isTest) dynVer
else localSnapshotVersion // only for local publishing
},
scalaVersion := V.scala213,
Expand Down Expand Up @@ -526,7 +527,20 @@ lazy val `sbt-metals` = project
"lastSupportedSemanticdb" -> SemanticDbSupport.last,
),
scalaVersion := V.scala212,
crossScalaVersions := Seq(V.scala212, V.scala3ForSBT2),
scriptedLaunchOpts ++= Seq(s"-Dplugin.version=${version.value}"),
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.5.8"
case _ => "2.0.0-M3"
}
},
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.12" => "-Xsource:3" :: Nil
case _ => Nil
}
},
)
.settings(sharedScalacOptions)
.enablePlugins(BuildInfoPlugin, SbtPlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,26 @@ object SbtBuildTool {
def writeSbtMetalsPlugins(projectRoot: AbsolutePath): Boolean = {
val mainMeta = projectRoot.resolve("project")
val metaMeta = projectRoot.resolve("project").resolve("project")
val writtenPlugin =
writePlugins(mainMeta, metalsPluginDetails, debugAdapterPluginDetails)
val writtenMeta =
writePlugins(metaMeta, metalsPluginDetails, jdiToolsPluginDetails)
writtenPlugin || writtenMeta

val isSbt2 =
SbtBuildTool.loadVersion(projectRoot).exists(_.startsWith("2."))
if (isSbt2) {
val writtenPlugin = writePlugins(mainMeta, metalsPluginDetails)
val writtenMeta = writePlugins(
metaMeta,
metalsPluginDetails,
)
writtenMeta || writtenPlugin
} else {
val writtenPlugin = writePlugins(
mainMeta,
metalsPluginDetails,
debugAdapterPluginDetails,
)
val writtenMeta =
writePlugins(metaMeta, metalsPluginDetails, jdiToolsPluginDetails)
writtenMeta || writtenPlugin
}
}

private case class PluginDetails(
Expand Down
1 change: 1 addition & 0 deletions project/V.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object V {
val scala213 = "2.13.15"
val lastPublishedScala3 = "3.3.3"
val scala3 = "3.3.4"
val scala3ForSBT2 = "3.6.2"

// When you can add to removedScalaVersions in MtagsResolver.scala with the last released version
val sbtScala = "2.12.18"
Expand Down
28 changes: 20 additions & 8 deletions sbt-metals/src/sbt-test/sbt-metals/semanticdb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ def assertSemanticdbForScala2 = Def.task {

assert(enabled, s"semanticdb is disabled in ${project.id}/${config.id}")
assertPlugin(sOptions, s"semanticdb-scalac", sv, BuildInfo.semanticdbVersion)
assertOption(sOptions, "-Yrangepos")
assertOption(sOptions, "-P:semanticdb:synthetics:on")
assertOption(sOptions, "-P:semanticdb:failures:warning")
assertOptionValue(sOptions, "-P:semanticdb:sourceroot", sourceRoot.toString)
assertOptionValue(sOptions, "-P:semanticdb:targetroot", targetRoot.toString)

// currently option added twice for test scope
if (!sbtVersion.value.startsWith("2") && !config.name.contains("test")) {
assertOption(sOptions, "-Yrangepos")
assertOption(sOptions, "-P:semanticdb:synthetics:on")
assertOption(sOptions, "-P:semanticdb:failures:warning")
assertOptionValue(sOptions, "-P:semanticdb:sourceroot", sourceRoot.toString)
assertOptionValue(sOptions, "-P:semanticdb:targetroot", targetRoot.toString)
}

assert(
jOptions.exists(_.startsWith("-Xplugin:semanticdb")),
Expand All @@ -97,10 +101,18 @@ def assertSemanticdbForScala3 = Def.taskDyn {
val targetRoot = semanticdbTargetRoot.value
val project = thisProject.value
val config = configuration.value

assert(enabled, s"semanticdb is disabled in ${project.id}/${config.id}")
assertOption(sOptions, "-Xsemanticdb")
assertOptionValue(sOptions, s"-semanticdb-target", targetRoot.toString)
// currently option added twice for test scope
if (
!sbtVersion.value.startsWith("2") && !config.name.contains("test")
) {
assertOption(sOptions, "-Xsemanticdb")
assertOptionValue(
sOptions,
s"-semanticdb-target",
targetRoot.toString,
)
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/slow/src/test/scala/tests/sbt/SbtServerSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,47 @@ class SbtServerSuite
}
}

test("sbt-2.0.0") {
cleanWorkspace()
client.importBuildChanges = ImportBuildChanges.yes
for {
_ <- initialize(
s"""|/project/build.properties
|sbt.version=2.0.0-M3
|/build.sbt
|
|scalaVersion := "$scalaVersion"
|val a = project.in(file("a"))
|val b = project.in(file("b"))
|/a/src/main/scala/A.scala
|
|object A{
| val foo = 1
| foo + foo
|}
|""".stripMargin
)
_ <- server.server.indexingPromise.future
references <- server.references("a/src/main/scala/A.scala", "foo")
_ = assertEmpty(client.workspaceDiagnostics)
_ = assertNoDiff(
references,
"""|a/src/main/scala/A.scala:3:7: info: reference
| val foo = 1
| ^^^
|a/src/main/scala/A.scala:4:3: info: reference
| foo + foo
| ^^^
|a/src/main/scala/A.scala:4:9: info: reference
| foo + foo
| ^^^
|""".stripMargin,
)
_ = assertEmpty(client.workspaceShowMessages)
} yield ()

}

test("reload") {
cleanWorkspace()
client.importBuildChanges = ImportBuildChanges.yes
Expand Down
Loading