Skip to content

Commit 9024792

Browse files
committed
Add the sources of scalajs-ir to dotty instead of its binaries.
This guarantees that we can bootstrap dotty without depending on the binaries of scalajs-ir compiled by another Scala compiler.
1 parent 18505cb commit 9024792

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

project/Build.scala

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ object DottyBuild extends Build {
8383
"org.scala-lang.modules" %% "scala-partest" % "1.0.11" % "test",
8484
"com.novocode" % "junit-interface" % "0.11" % "test",
8585
"jline" % "jline" % "2.12"),
86-
libraryDependencies +=
87-
"org.scala-js" %% "scalajs-ir" % scalaJSVersion,
8886

8987
// enable improved incremental compilation algorithm
9088
incOptions := incOptions.value.withNameHashing(true),
@@ -116,6 +114,38 @@ object DottyBuild extends Build {
116114
runTask(Test, "dotty.partest.DPConsoleRunner", dottyJars + " " + args.mkString(" "))
117115
},
118116

117+
/* Add the sources of scalajs-ir.
118+
* To guarantee that dotty can bootstrap without depending on a version
119+
* of scalajs-ir built with a different Scala compiler, we add its
120+
* sources instead of depending on the binaries.
121+
*/
122+
ivyConfigurations += config("sourcedeps").hide,
123+
libraryDependencies +=
124+
"org.scala-js" %% "scalajs-ir" % scalaJSVersion % "sourcedeps",
125+
sourceGenerators in Compile += Def.task {
126+
val s = streams.value
127+
val cacheDir = s.cacheDirectory
128+
val trgDir = (sourceManaged in Compile).value / "scalajs-ir-src"
129+
130+
val report = updateClassifiers.value
131+
val scalaJSIRSourcesJar = report.select(
132+
configuration = Set("sourcedeps"),
133+
module = (_: ModuleID).name.startsWith("scalajs-ir_"),
134+
artifact = artifactFilter(`type` = "src")).headOption.getOrElse {
135+
sys.error(s"Could not fetch scalajs-ir sources")
136+
}
137+
138+
FileFunction.cached(cacheDir / s"fetchScalaJSIRSource",
139+
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
140+
s.log.info(s"Unpacking scalajs-ir sources to $trgDir...")
141+
if (trgDir.exists)
142+
IO.delete(trgDir)
143+
IO.createDirectory(trgDir)
144+
IO.unzip(scalaJSIRSourcesJar, trgDir)
145+
(trgDir ** "*.scala").get.toSet
146+
} (Set(scalaJSIRSourcesJar)).toSeq
147+
}.taskValue,
148+
119149
// Adjust classpath for running dotty
120150
mainClass in (Compile, run) := Some("dotty.tools.dotc.Main"),
121151
fork in run := true,

0 commit comments

Comments
 (0)