Skip to content

Commit f8498b7

Browse files
committed
Generate config for IDE tests with sbt-buildinfo
1 parent 1fa3a93 commit f8498b7

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

language-server/test/dotty/tools/languageserver/util/server/TestServer.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ import scala.collection.JavaConverters._
1212

1313
class TestServer(testFolder: Path) {
1414

15-
// TODO initialise config file from DottyIDEPlugin
16-
private val baseDir = java.nio.file.Paths.get("..").toAbsolutePath
17-
private val ivyDir = java.nio.file.Paths.get("~/.ivy2").toAbsolutePath
18-
private val javaHome = System.getProperty("java.home")
15+
// Fill the configuration with values populated by sbt
16+
private def showSeq[T](lst: Seq[T]): String = lst.map(elem => '"' + elem.toString + '"').mkString("[ ", ", ", " ]")
1917
private val dottyIdeJson: String =
2018
s"""[ {
2119
| "id" : "dotty-ide-test",
22-
| "compilerVersion" : "0.6.0-bin-SNAPSHOT-nonbootstrapped",
23-
| "compilerArguments" : [ "-feature", "-deprecation", "-unchecked", "-Xfatal-warnings", "-encoding", "UTF8", "-language:existentials,higherKinds,implicitConversions" ],
24-
| "sourceDirectories" : [ "$baseDir/out/ide-tests/src" ],
25-
| "dependencyClasspath" : [ "$baseDir/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.7/classes", "$ivyDir/cache/org.scala-lang/scala-library/jars/scala-library-2.12.4.jar" ],
26-
| "classDirectory" : "$baseDir/out/ide-tests/out"
20+
| "compilerVersion" : "${BuildInfo.ideTestsCompilerVersion}",
21+
| "compilerArguments" : ${showSeq(BuildInfo.ideTestsCompilerArguments)},
22+
| "sourceDirectories" : ${showSeq(BuildInfo.ideTestsSourceDirectories)},
23+
| "dependencyClasspath" : ${showSeq(BuildInfo.ideTestsDependencyClasspath)},
24+
| "classDirectory" : "${BuildInfo.ideTestsClassDirectory}"
2725
|}
2826
|]
2927
""".stripMargin

project/Build.scala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import dotty.tools.sbtplugin.DottyPlugin.autoImport._
1818
import dotty.tools.sbtplugin.DottyIDEPlugin.{ prepareCommand, runProcess }
1919
import dotty.tools.sbtplugin.DottyIDEPlugin.autoImport._
2020

21+
import sbtbuildinfo.BuildInfoPlugin
22+
import sbtbuildinfo.BuildInfoPlugin.autoImport._
23+
2124
/* In sbt 0.13 the Build trait would expose all vals to the shell, where you
2225
* can use them in "set a := b" like expressions. This re-exposes them.
2326
*/
@@ -85,6 +88,13 @@ object Build {
8588
// Only available in vscode-dotty
8689
lazy val unpublish = taskKey[Unit]("Unpublish a package")
8790

91+
// Settings used to configure the test language server
92+
lazy val ideTestsCompilerVersion = taskKey[String]("Compiler version to use in IDE tests")
93+
lazy val ideTestsCompilerArguments = taskKey[Seq[String]]("Compiler arguments to use in IDE tests")
94+
lazy val ideTestsSourceDirectories = taskKey[Seq[File]]("Source directories to use in IDE tests")
95+
lazy val ideTestsDependencyClasspath = taskKey[Seq[File]]("Dependency classpath to use in IDE tests")
96+
lazy val ideTestsClassDirectory = taskKey[File]("Class directory to use in IDE tests")
97+
8898
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
8999
lazy val thisBuildSettings = Def.settings(
90100
organization := dottyOrganization,
@@ -789,6 +799,32 @@ object Build {
789799

790800
runTask(Runtime, mainClass, allArgs: _*)
791801
}.dependsOn(compile in (`vscode-dotty`, Compile)).evaluated
802+
).
803+
settings(
804+
ideTestsCompilerVersion := (version in `dotty-compiler`).value,
805+
ideTestsCompilerArguments := (scalacOptions in `dotty-compiler`).value,
806+
ideTestsSourceDirectories := Seq((baseDirectory in ThisBuild).value / "out" / "ide-tests" / "src"),
807+
ideTestsDependencyClasspath := {
808+
val dottyLib = (classDirectory in `dotty-library-bootstrapped` in Compile).value
809+
val scalaLib =
810+
(dependencyClasspath in `dotty-library-bootstrapped` in Compile)
811+
.value
812+
.map(_.data)
813+
.filter(_.getName.matches("scala-library.*\\.jar"))
814+
.toList
815+
dottyLib :: scalaLib
816+
},
817+
ideTestsClassDirectory := (baseDirectory in ThisBuild).value / "out" / "ide-tests" / "out",
818+
buildInfoKeys in Test := Seq[BuildInfoKey](
819+
ideTestsCompilerVersion,
820+
ideTestsCompilerArguments,
821+
ideTestsSourceDirectories,
822+
ideTestsDependencyClasspath,
823+
ideTestsClassDirectory
824+
),
825+
buildInfoPackage in Test := "dotty.tools.languageserver.util.server",
826+
BuildInfoPlugin.buildInfoScopedSettings(Test),
827+
BuildInfoPlugin.buildInfoDefaultSettings
792828
).disablePlugins(ScriptedPlugin)
793829

794830
lazy val `dotty-bench` = project.in(file("bench")).asDottyBench(NonBootstrapped)

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
1414
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.10.1")
1515

1616
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.2")
17+
18+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")

0 commit comments

Comments
 (0)