Skip to content

Commit 768c301

Browse files
committed
Allow overwrite of sources in stdlib-bootstrapped
1 parent cba5c9a commit 768c301

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

project/Build.scala

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,11 @@ object Build {
931931
settings(
932932
moduleName := "scala-library",
933933
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
934-
Compile/scalacOptions += "-Yerased-terms",
935934
Compile/scalacOptions ++= {
936935
Seq(
937936
"-sourcepath",
938937
Seq(
938+
baseDirectory.value / "stdlib-bootstrapped" / "src",
939939
(Compile/sourceManaged).value / "scala-library-src",
940940
(Compile/sourceManaged).value / "dotty-library-src",
941941
).mkString(File.pathSeparator),
@@ -1009,9 +1009,59 @@ object Build {
10091009
file.getPath.endsWith("scala-library-src/scala/Nothing.scala") ||
10101010
file.getPath.endsWith("scala-library-src/scala/Null.scala") ||
10111011
file.getPath.endsWith("scala-library-src/scala/Singleton.scala"))),
1012+
(Compile / sources) ~= (files =>
1013+
{
1014+
val overwritenSources = files.collect {
1015+
case file if file.getPath.contains("stdlib-bootstrapped/src") => file.getPath.split("stdlib-bootstrapped/src/")(1)
1016+
}.toSet
1017+
files.filterNot(file =>
1018+
file.getPath.contains("scala-library-src/") && overwritenSources(file.getPath.split("scala-library-src/")(1)))
1019+
}
1020+
),
10121021
(Test / managedClasspath) ~= {
10131022
_.filterNot(file => file.data.getName == s"scala-library-${stdlibVersion(Bootstrapped)}.jar")
10141023
},
1024+
run := {
1025+
val args: Seq[String] = spaceDelimited("<arg>").parsed
1026+
val reference = (Compile/sourceManaged).value / "scala-library-src"
1027+
args match {
1028+
case Seq("list") =>
1029+
println(s"List of non-overriden files in $reference")
1030+
reference.allPaths.get()
1031+
.flatMap(_.relativeTo(reference))
1032+
.filter(_.ext == "scala")
1033+
.sorted
1034+
.foreach(println)
1035+
case Seq(cmd @ ("clone" | "overwrite"), files*) =>
1036+
println("Cloning scala-library sources: " + files.mkString(", "))
1037+
for (file <- files) {
1038+
val referenceStdlibPaths = reference / file
1039+
val destination = baseDirectory.value / "src" / file
1040+
if (!referenceStdlibPaths.exists) {
1041+
println("Not found " + referenceStdlibPaths)
1042+
} else if (destination.exists && cmd == "clone") {
1043+
println(s"Already exists $file. (use `overwrite` command to overwrite)")
1044+
} else {
1045+
val action = if (cmd == "clone") "Cloning" else "Overwriting"
1046+
println(s"$action $file")
1047+
IO.copyFile(referenceStdlibPaths, destination)
1048+
}
1049+
}
1050+
case _ =>
1051+
println(
1052+
"""Usage:
1053+
|> stdlib-bootstrapped/run list
1054+
| -- lists all files that are not overriden in stdlib-bootstrapped/src
1055+
|
1056+
|> stdlib-bootstrapped/run clone <sources>*
1057+
| -- clones the specified sources from the stdlib-bootstrapped/src
1058+
| -- example: stdlib-bootstrapped/run clone scala/Option.scala
1059+
|
1060+
|> stdlib-bootstrapped/run overwrite <sources>*
1061+
| -- (danger) overwrites the specified sources from the stdlib-bootstrapped/src
1062+
|""".stripMargin)
1063+
}
1064+
}
10151065
)
10161066

10171067
/** Test the tasty generated by `stdlib-bootstrapped`

stdlib-bootstrapped/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## stdlib-bootstrapped
2+
3+
This project compiles the Scala standard library using the Scala 3 compiler.
4+
It uses the sources Scala (2/3) standard library sources from `stdlib-bootstrapped/src`
5+
and the Scala 3 library form `library/src`. It fetches any missing Scala (2/3) sources
6+
from `org.scala-lang" % "scala-library" % stdlibVersion(Bootstrapped) % "sourcedeps`.
7+
This implies that files in `stdlib-bootstrapped/src` override files override the Scala (2/3)
8+
sources. Currently we can not override files from `library/src`.
9+
10+
To clone or list non-overridden sources execute `stdlib-bootstrapped/run`.
11+
12+
This project generates a version of the Scala 3 library that contains the full library with
13+
TASTy files. The compiled library is located in `out/bootstrap/stdlib-bootstrapped/`.

0 commit comments

Comments
 (0)