Skip to content

Commit 58fe96c

Browse files
committed
Remove meta-dependency on DottyPlugin
1 parent 0d2e763 commit 58fe96c

File tree

5 files changed

+58
-19
lines changed

5 files changed

+58
-19
lines changed

project/Bootstrap.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package sbt
2+
3+
import sbt.internal.classpath.ClassLoaderCache
4+
import sbt.internal.inc.ScalaInstance
5+
6+
object Bootstrap {
7+
// copied from https://github.com/sbt/sbt/blob/33e2bfe2810246c8e4e1b37ec110d15e588a4fce/main/src/main/scala/sbt/Defaults.scala#L1120-L1165
8+
def makeScalaInstance(
9+
version: String,
10+
libraryJars: Array[File],
11+
allCompilerJars: Seq[File],
12+
allDocJars: Seq[File],
13+
state: State,
14+
topLoader: ClassLoader
15+
): ScalaInstance = {
16+
val classLoaderCache = state.extendedClassLoaderCache
17+
val compilerJars = allCompilerJars.filterNot(libraryJars.contains).distinct.toArray
18+
val docJars = allDocJars
19+
.filterNot(jar => libraryJars.contains(jar) || compilerJars.contains(jar))
20+
.distinct.toArray
21+
val allJars = libraryJars ++ compilerJars ++ docJars
22+
23+
val libraryLoader = classLoaderCache(libraryJars.toList, topLoader)
24+
val compilerLoader = classLoaderCache(compilerJars.toList, libraryLoader)
25+
val fullLoader =
26+
if (docJars.isEmpty) compilerLoader
27+
else classLoaderCache(docJars.distinct.toList, compilerLoader)
28+
new ScalaInstance(
29+
version = version,
30+
loader = fullLoader,
31+
loaderCompilerOnly = compilerLoader,
32+
loaderLibraryOnly = libraryLoader,
33+
libraryJars = libraryJars,
34+
compilerJars = compilerJars,
35+
allJars = allJars,
36+
explicitActual = Some(version)
37+
)
38+
}
39+
}

project/Build.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import xerial.sbt.pack.PackPlugin
1515
import xerial.sbt.pack.PackPlugin.autoImport._
1616
import xerial.sbt.Sonatype.autoImport._
1717

18-
import dotty.tools.sbtplugin.DottyPlugin.autoImport._
19-
import dotty.tools.sbtplugin.DottyPlugin.makeScalaInstance
2018
import dotty.tools.sbtplugin.DottyIDEPlugin.{ installCodeExtension, prepareCommand, runProcess }
2119
import dotty.tools.sbtplugin.DottyIDEPlugin.autoImport._
2220

@@ -43,7 +41,7 @@ object MyScalaJSPlugin extends AutoPlugin {
4341
_.filter(!_.name.startsWith("junit-interface"))
4442
},
4543
libraryDependencies +=
46-
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion % "test").withDottyCompat(scalaVersion.value),
44+
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion % "test").cross(CrossVersion.for3Use2_13),
4745

4846
// Typecheck the Scala.js IR found on the classpath
4947
scalaJSLinkerConfig ~= (_.withCheckIR(true)),
@@ -329,16 +327,17 @@ object Build {
329327
val dottyCompiler = packageBin.in(`scala3-compiler`, Compile).value
330328
val scaladoc = packageBin.in(`scaladoc-nonBootstrapped`, Compile).value
331329

330+
val allCompilerJars = Seq(tastyCore, dottyLibrary, dottyInterfaces, dottyCompiler) ++ externalNonBootstrappedDeps.map(_.data)
331+
val allDocJars = Seq(scaladoc)
332332
val allJars = Seq(tastyCore, dottyLibrary, dottyInterfaces, dottyCompiler, scaladoc) ++ externalNonBootstrappedDeps.map(_.data)
333333

334-
makeScalaInstance(
335-
state.value,
334+
sbt.Bootstrap.makeScalaInstance(
336335
scalaVersion.value,
337-
scalaLibrary,
338-
dottyLibrary,
339-
dottyCompiler,
340-
allJars,
341-
appConfiguration.value
336+
Array(scalaLibrary, dottyLibrary),
337+
allCompilerJars,
338+
Seq(scaladoc),
339+
state.value,
340+
scalaInstanceTopLoader.value
342341
)
343342
},
344343
// sbt-dotty defines `scalaInstance in doc` so we need to override it manually
@@ -542,7 +541,7 @@ object Build {
542541
ivyConfigurations += SourceDeps.hide,
543542
transitiveClassifiers := Seq("sources"),
544543
libraryDependencies +=
545-
("org.scala-js" %% "scalajs-ir" % scalaJSVersion % "sourcedeps").withDottyCompat(scalaVersion.value),
544+
("org.scala-js" %% "scalajs-ir" % scalaJSVersion % "sourcedeps").cross(CrossVersion.for3Use2_13),
546545
sourceGenerators in Compile += Def.task {
547546
val s = streams.value
548547
val cacheDir = s.cacheDirectory
@@ -705,7 +704,7 @@ object Build {
705704
enablePlugins(MyScalaJSPlugin).
706705
settings(
707706
libraryDependencies +=
708-
("org.scala-js" %% "scalajs-library" % scalaJSVersion).withDottyCompat(scalaVersion.value),
707+
("org.scala-js" %% "scalajs-library" % scalaJSVersion).cross(CrossVersion.for3Use2_13),
709708
unmanagedSourceDirectories in Compile :=
710709
(unmanagedSourceDirectories in (`scala3-library-bootstrapped`, Compile)).value,
711710

@@ -1038,7 +1037,7 @@ object Build {
10381037

10391038
// We need JUnit in the Compile configuration
10401039
libraryDependencies +=
1041-
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion).withDottyCompat(scalaVersion.value),
1040+
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion).cross(CrossVersion.for3Use2_13),
10421041

10431042
sourceGenerators in Compile += Def.task {
10441043
import org.scalajs.linker.interface.CheckedBehavior
@@ -1688,7 +1687,7 @@ object Build {
16881687
settings(
16891688
fork in Test := false,
16901689
scalaJSUseMainModuleInitializer := true,
1691-
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").withDottyCompat(scalaVersion.value)
1690+
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
16921691
)
16931692

16941693

project/build.sbt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
// Used by VersionUtil to get gitHash and commitDate
22
libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "4.11.0.201803080745-r"
33

4-
// Include the sources of the sbt-dotty plugin in the project build,
4+
// Include the source of DottyIDEPlugin in the project build,
55
// so that we can use the current in-development version of the plugin
66
// in our build instead of a released version.
7+
// We do not add SbtDottyPlugin to show that it is not usefull anymore
8+
// However, adding one source but not the others is very fragile
79

8-
unmanagedSourceDirectories in Compile += baseDirectory.value / "../sbt-dotty/src"
10+
unmanagedSources in Compile += baseDirectory.value / "../sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala"
911

1012
// Keep in sync with `sbt-dotty` config in Build.scala
1113
libraryDependencies ++= Seq(
12-
Dependencies.`jackson-databind`,
13-
Dependencies.newCompilerInterface
14+
Dependencies.`jackson-databind`
1415
)
1516
unmanagedSourceDirectories in Compile +=
1617
baseDirectory.value / "../language-server/src/dotty/tools/languageserver/config"

project/project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.4.4

sbt-dotty/src/dotty/tools/sbtplugin/DottyIDEPlugin.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import dotty.tools.languageserver.config.ProjectConfig
1313

1414
import com.fasterxml.jackson.databind.ObjectMapper
1515
import scala.collection.mutable.ListBuffer
16-
import DottyPlugin.autoImport._
1716

1817
object DottyIDEPlugin extends AutoPlugin {
1918
object autoImport {

0 commit comments

Comments
 (0)