@@ -675,80 +675,6 @@ object Build {
675
675
recur(lines)
676
676
}
677
677
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
752
678
// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
753
679
lazy val commonDottyCompilerSettings = Seq (
754
680
// Note: bench/profiles/projects.yml should be updated accordingly.
@@ -795,7 +721,7 @@ object Build {
795
721
(" io.get-coursier" %% " coursier" % " 2.0.16" % Test ).cross(CrossVersion .for3Use2_13),
796
722
),
797
723
798
- shadedSourceGenerator ,
724
+ ( Compile / sourceGenerators) += ShadedSourceGenerator .task.taskValue ,
799
725
800
726
// For convenience, change the baseDirectory when running the compiler
801
727
Compile / forkOptions := (Compile / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
@@ -2217,7 +2143,7 @@ object Build {
2217
2143
2218
2144
Seq (file)
2219
2145
}.taskValue,
2220
- shadedSourceGenerator ,
2146
+ ( Compile / sourceGenerators) += ShadedSourceGenerator .task.taskValue ,
2221
2147
// sbt adds all the projects to scala-tool config which breaks building the scalaInstance
2222
2148
// as a workaround, I build it manually by only adding the compiler
2223
2149
scalaInstance := {
@@ -2407,7 +2333,7 @@ object Build {
2407
2333
sjsSources
2408
2334
} (Set (scalaJSIRSourcesJar)).toSeq
2409
2335
}.taskValue,
2410
- shadedSourceGenerator
2336
+ ( Compile / sourceGenerators) += ShadedSourceGenerator .task.taskValue
2411
2337
)
2412
2338
2413
2339
// ==============================================================================================
0 commit comments