Skip to content

Commit 2562be1

Browse files
committed
.
1 parent 1be063a commit 2562be1

File tree

1 file changed

+45
-43
lines changed

1 file changed

+45
-43
lines changed

project/Build.scala

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,49 @@ object Build {
675675
recur(lines)
676676
}
677677

678+
val shadedSourceGenerator = (Compile / sourceGenerators) += Def.task {
679+
val downloads = Seq(
680+
"https://repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.3/pprint_3-0.9.3-sources.jar",
681+
"https://repo1.maven.org/maven2/com/lihaoyi/fansi_3/0.5.1/fansi_3-0.5.1-sources.jar",
682+
"https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_3/0.4.3-M5/sourcecode_3-0.4.3-M5-sources.jar",
683+
)
684+
val sourceManagedPath = os.Path((Compile / sourceManaged).value / "downloaded")
685+
os.remove.all(sourceManagedPath)
686+
os.makeDir.all(sourceManagedPath)
687+
for(download <- downloads) {
688+
os.unzip.stream(requests.get.stream(download), dest = sourceManagedPath)
689+
}
690+
for {
691+
file <- os.walk(sourceManagedPath)
692+
if file.ext == "scala"
693+
if file.last != "CollectionName.scala"
694+
} yield {
695+
val text = os.read(file)
696+
os.write.over(
697+
file,
698+
"package dotty.shaded\n" +
699+
text
700+
.replace("import scala", "import _root_.scala")
701+
.replace(" scala.collection.", " _root_.scala.collection.")
702+
.replace("_root_.pprint", "_root_.dotty.shaded.pprint")
703+
.replace("_root_.fansi", "_root_.dotty.shaded.fansi")
704+
.replace("def apply(c: Char): Trie[T]", "def apply(c: Char): Trie[T] | Null")
705+
.replace("var head: Iterator[T] = null", "var head: Iterator[T] | Null = null")
706+
.replace("if (head != null && head.hasNext) true", "if (head != null && head.nn.hasNext) true")
707+
.replace("head.next()", "head.nn.next()")
708+
.replace(
709+
"_root_.scala.collection.internal.pprint.CollectionName.get(i)",
710+
"import scala.reflect.Selectable.reflectiveSelectable\n" +
711+
" i.asInstanceOf[{def collectionClassName: String}].collectionClassName"
712+
)
713+
.replace("abstract class Walker", "@scala.annotation.nowarn abstract class Walker")
714+
.replace("object TPrintLowPri", "@scala.annotation.nowarn object TPrintLowPri")
715+
// .replace("_root_.scala.collection.internal.pprint.CollectionName.get(i)", "head.nn.next()")
716+
// .replace("_root_.scala.collection.internal.pprint.CollectionName.get(i)", "head.nn.next()")
717+
)
718+
file.toIO
719+
}
720+
}.taskValue
678721
// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
679722
lazy val commonDottyCompilerSettings = Seq(
680723
// Note: bench/profiles/projects.yml should be updated accordingly.
@@ -721,49 +764,7 @@ object Build {
721764
("io.get-coursier" %% "coursier" % "2.0.16" % Test).cross(CrossVersion.for3Use2_13),
722765
),
723766

724-
(Compile / sourceGenerators) += Def.task {
725-
val downloads = Seq(
726-
"https://repo1.maven.org/maven2/com/lihaoyi/pprint_3/0.9.3/pprint_3-0.9.3-sources.jar",
727-
"https://repo1.maven.org/maven2/com/lihaoyi/fansi_3/0.5.1/fansi_3-0.5.1-sources.jar",
728-
"https://repo1.maven.org/maven2/com/lihaoyi/sourcecode_3/0.4.3-M5/sourcecode_3-0.4.3-M5-sources.jar",
729-
)
730-
val sourceManagedPath = os.Path((Compile / sourceManaged).value / "downloaded")
731-
os.remove.all(sourceManagedPath)
732-
os.makeDir.all(sourceManagedPath)
733-
for(download <- downloads) {
734-
os.unzip.stream(requests.get.stream(download), dest = sourceManagedPath)
735-
}
736-
for {
737-
file <- os.walk(sourceManagedPath)
738-
if file.ext == "scala"
739-
if file.last != "CollectionName.scala"
740-
} yield {
741-
val text = os.read(file)
742-
os.write.over(
743-
file,
744-
"package dotty.shaded\n" +
745-
text
746-
.replace("import scala", "import _root_.scala")
747-
.replace(" scala.collection.", " _root_.scala.collection.")
748-
.replace("_root_.pprint", "_root_.dotty.shaded.pprint")
749-
.replace("_root_.fansi", "_root_.dotty.shaded.fansi")
750-
.replace("def apply(c: Char): Trie[T]", "def apply(c: Char): Trie[T] | Null")
751-
.replace("var head: Iterator[T] = null", "var head: Iterator[T] | Null = null")
752-
.replace("if (head != null && head.hasNext) true", "if (head != null && head.nn.hasNext) true")
753-
.replace("head.next()", "head.nn.next()")
754-
.replace(
755-
"_root_.scala.collection.internal.pprint.CollectionName.get(i)",
756-
"import scala.reflect.Selectable.reflectiveSelectable\n" +
757-
" i.asInstanceOf[{def collectionClassName: String}].collectionClassName"
758-
)
759-
.replace("abstract class Walker", "@scala.annotation.nowarn abstract class Walker")
760-
.replace("object TPrintLowPri", "@scala.annotation.nowarn object TPrintLowPri")
761-
// .replace("_root_.scala.collection.internal.pprint.CollectionName.get(i)", "head.nn.next()")
762-
// .replace("_root_.scala.collection.internal.pprint.CollectionName.get(i)", "head.nn.next()")
763-
)
764-
file.toIO
765-
}
766-
}.taskValue,
767+
shadedSourceGenerator,
767768

768769
// For convenience, change the baseDirectory when running the compiler
769770
Compile / forkOptions := (Compile / forkOptions).value.withWorkingDirectory((ThisBuild / baseDirectory).value),
@@ -2185,6 +2186,7 @@ object Build {
21852186

21862187
Seq(file)
21872188
}.taskValue,
2189+
shadedSourceGenerator,
21882190
// sbt adds all the projects to scala-tool config which breaks building the scalaInstance
21892191
// as a workaround, I build it manually by only adding the compiler
21902192
scalaInstance := {

0 commit comments

Comments
 (0)