Skip to content

Commit fa7c102

Browse files
committed
Repackage the Scala 2.13 stdlib with .tasty files
1 parent 275eab4 commit fa7c102

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134

135135
- name: Cmd Tests
136136
run: |
137-
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-2_13-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
137+
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-2_13-bootstrapped/test:run ;stdlib-2_13-tasty-bundle/packageBin ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
138138
./project/scripts/cmdTests
139139
./project/scripts/bootstrappedOnlyCmdTests
140140
@@ -488,7 +488,7 @@ jobs:
488488

489489
- name: Test
490490
run: |
491-
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-2_13-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test"
491+
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-2_13-bootstrapped/test:run ;stdlib-2_13-tasty-bundle/packageBin ;stdlib-bootstrapped-tasty-tests/test"
492492
./project/scripts/cmdTests
493493
./project/scripts/bootstrappedOnlyCmdTests
494494

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
1616
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1717
val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped`
1818
val `stdlib-2_13-bootstrapped` = Build.`stdlib-2_13-bootstrapped`
19+
val `stdlib-2_13-tasty-bundle` = Build.`stdlib-2_13-tasty-bundle`
1920
val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests`
2021
val `tasty-core` = Build.`tasty-core`
2122
val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped`

project/Build.scala

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,66 @@ object Build {
10441044
},
10451045
)
10461046

1047+
/** Creates a copy of the Scala 2.13 library JAR with TASTy from `stdlib-2_13-bootstrapped` */
1048+
lazy val `stdlib-2_13-tasty-bundle` = project.in(file("stdlib-2_13-tasty-bundle")).
1049+
withCommonSettings(Bootstrapped).
1050+
dependsOn(`stdlib-2_13-bootstrapped`).
1051+
settings(commonBootstrappedSettings).
1052+
settings(
1053+
moduleName := "scala-library",
1054+
exportJars := true,
1055+
Compile / compile := {
1056+
val classDir = (Compile / classDirectory).value
1057+
1058+
// Copy contents of Scala 2.13 JAR into classDir
1059+
val s = streams.value
1060+
val report = updateClassifiers.value
1061+
val scalaLibraryJar =
1062+
// FIXME could not find it with report.select. Other options?
1063+
report.select(
1064+
configuration = configurationFilter("compile"),
1065+
module = (_: ModuleID).name == "scala-library",
1066+
artifact = artifactFilter(`type` = "src"))
1067+
.headOption.getOrElse {
1068+
sys.error(s"Could not fetch scala-library sources")
1069+
}.getParentFile / s"scala-library-${stdlibVersion(Bootstrapped)}.jar"
1070+
val cacheDir = s.cacheDirectory
1071+
FileFunction.cached(cacheDir / "fetchScalaLibraryBin",
1072+
FilesInfo.lastModified, FilesInfo.exists) { dependencies =>
1073+
s.log.info(s"Unpacking scala-library classfiles to $classDir")
1074+
if (classDir.exists)
1075+
IO.delete(classDir)
1076+
IO.createDirectory(classDir)
1077+
IO.unzip(scalaLibraryJar, classDir)
1078+
(classDir ** "*").get.toSet
1079+
} (Set(scalaLibraryJar)).toSeq
1080+
IO.delete(classDir / "META-INF")
1081+
// TODO What to do with library.properties, LICENSE, NOTICE, rootdoc.txt? Keep? Modify?
1082+
1083+
// Copy .tasty files from stdlib-2_13-bootstrapped into classDir
1084+
val tastySrcDir = (`stdlib-2_13-bootstrapped` / Compile / classDirectory).value
1085+
s.log.info(s"Copying .tasty files from $tastySrcDir to $classDir")
1086+
for (tastyFile <- tastySrcDir.allPaths.get()) {
1087+
if (tastyFile.getName.endsWith(".tasty")) {
1088+
val tastyFileDest = tastyFile.relativeTo(tastySrcDir).get
1089+
val destFile = classDir / tastyFileDest.toString()
1090+
IO.copyFile(tastyFile, destFile)
1091+
}
1092+
}
1093+
1094+
(Compile / compile).value
1095+
},
1096+
Compile / packageBin / artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
1097+
artifact.name + "-" + stdlibVersion(Bootstrapped) + "-" + module.revision + "." + artifact.extension
1098+
},
1099+
Compile / packageBin := {
1100+
val version = stdlibVersion(Bootstrapped)
1101+
val path = (Compile / packageBin / artifactPath).value
1102+
streams.value.log.info(s"Repackaging Scala $version library with .tasty files into $path")
1103+
(Compile / packageBin).value
1104+
}
1105+
)
1106+
10471107
/** Test the tasty generated by `stdlib-bootstrapped`
10481108
*
10491109
* The tests are run with the bootstrapped compiler and the tasty inpector on the classpath.

stdlib-2_13-tasty-bundle/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Creates a copy of the Scala 2.13 library JAR with TASTy from `stdlib-2_13-bootstrapped`.
2+
3+
```
4+
sbt> stdlib-2_13-tasty-bundle/packageBin
5+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package hello
2+
3+
enum Color:
4+
case Red, Green, Blue
5+
6+
object HelloWorld:
7+
def main(args: Array[String]): Unit = {
8+
println("hello 2.13 library bootstrapped")
9+
println(Color.Red)
10+
println(Color.Green)
11+
println(Color.Blue)
12+
}

0 commit comments

Comments
 (0)