@@ -675,80 +675,6 @@ object Build {
675675 recur(lines)
676676 }
677677
678- val shadedSourceGenerator = (Compile / sourceGenerators) += Def .task {
679- val s = streams.value
680- val cacheDir = s.cacheDirectory
681- val dest = (Compile / sourceManaged).value / " downloaded"
682- val lm = dependencyResolution.value
683-
684- val dependencies = Seq (
685- (" com.lihaoyi" , " pprint_3" , " 0.9.3" ),
686- (" com.lihaoyi" , " fansi_3" , " 0.5.1" ),
687- (" com.lihaoyi" , " sourcecode_3" , " 0.4.4" ),
688- )
689-
690- // Create a marker file that tracks the dependencies for cache invalidation
691- val markerFile = cacheDir / " shaded-sources-marker"
692- val markerContent = dependencies.map { case (org, name, version) => s " $org: $name: $version:sources " }.mkString(" \n " )
693- if (! markerFile.exists || IO .read(markerFile) != markerContent) {
694- IO .write(markerFile, markerContent)
695- }
696-
697- FileFunction .cached(cacheDir / " fetchShadedSources" ,
698- FilesInfo .lastModified, FilesInfo .exists) { _ =>
699- s.log.info(s " Downloading and processing shaded sources to $dest... " )
700-
701- if (dest.exists) {
702- IO .delete(dest)
703- }
704- IO .createDirectory(dest)
705-
706- for ((org, name, version) <- dependencies) {
707- import sbt .librarymanagement ._
708-
709- // Retrieve sources jar using dependencyResolution
710- val moduleId = ModuleID (org, name, version).sources()
711- val retrieveDir = cacheDir / " retrieved" / s " $org- $name- $version-sources "
712-
713- s.log.info(s " Retrieving $org: $name: $version:sources... " )
714- val retrieved = lm.retrieve(moduleId, scalaModuleInfo = None , retrieveDir, s.log)
715- val jarFiles = retrieved.fold(
716- w => throw w.resolveException,
717- files => files.filter(_.getName.contains(" -sources.jar" ))
718- )
719-
720- // Extract each retrieved jar
721- jarFiles.foreach { jarFile =>
722- s.log.info(s " Extracting ${jarFile.getName}... " )
723- IO .unzip(jarFile, dest)
724- }
725- }
726-
727- val scalaFiles = (dest ** " *.scala" ).get
728- scalaFiles.foreach { file =>
729- val text = IO .read(file)
730- if (! file.getName.equals(" CollectionName.scala" )) {
731- val processedText = " package dotty.shaded\n " +
732- text
733- .replace(" import scala" , " import _root_.scala" )
734- .replace(" scala.collection." , " _root_.scala.collection." )
735- .replace(" _root_.pprint" , " _root_.dotty.shaded.pprint" )
736- .replace(" _root_.fansi" , " _root_.dotty.shaded.fansi" )
737- .replace(" def apply(c: Char): Trie[T]" , " def apply(c: Char): Trie[T] | Null" )
738- .replace(" var head: Iterator[T] = null" , " var head: Iterator[T] | Null = null" )
739- .replace(" if (head != null && head.hasNext) true" , " if (head != null && head.nn.hasNext) true" )
740- .replace(" head.next()" , " head.nn.next()" )
741- .replace(" abstract class Walker" , " @scala.annotation.nowarn abstract class Walker" )
742- .replace(" object TPrintLowPri" , " @scala.annotation.nowarn object TPrintLowPri" )
743- .replace(" x.toString match{" , " scala.runtime.ScalaRunTime.stringOf(x) match{" )
744-
745- IO .write(file, processedText)
746- }
747- }
748- scalaFiles.toSet
749- } (Set (markerFile)).toSeq
750-
751- }.taskValue
752678 // Settings shared between scala3-compiler and scala3-compiler-bootstrapped
753679 lazy val commonDottyCompilerSettings = Seq (
754680 // Note: bench/profiles/projects.yml should be updated accordingly.
@@ -795,7 +721,7 @@ object Build {
795721 (" io.get-coursier" %% " coursier" % " 2.0.16" % Test ).cross(CrossVersion .for3Use2_13),
796722 ),
797723
798- shadedSourceGenerator ,
724+ ( Compile / sourceGenerators) += ShadedSourceGenerator .task.taskValue ,
799725
800726 // For convenience, change the baseDirectory when running the compiler
801727 Compile / forkOptions := (Compile / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
@@ -2217,7 +2143,7 @@ object Build {
22172143
22182144 Seq (file)
22192145 }.taskValue,
2220- shadedSourceGenerator ,
2146+ ( Compile / sourceGenerators) += ShadedSourceGenerator .task.taskValue ,
22212147 // sbt adds all the projects to scala-tool config which breaks building the scalaInstance
22222148 // as a workaround, I build it manually by only adding the compiler
22232149 scalaInstance := {
@@ -2407,7 +2333,7 @@ object Build {
24072333 sjsSources
24082334 } (Set (scalaJSIRSourcesJar)).toSeq
24092335 }.taskValue,
2410- shadedSourceGenerator
2336+ ( Compile / sourceGenerators) += ShadedSourceGenerator .task.taskValue
24112337 )
24122338
24132339 // ==============================================================================================
0 commit comments