From 6b7889b84db9425330ead582efe257a9b51952a7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 6 Jun 2023 15:49:08 +0200 Subject: [PATCH] Test compiling with TASTy of stdlib-bootstrapped --- .github/workflows/ci.yaml | 4 +- build.sbt | 1 + project/Build.scala | 38 ++++++++++++++++--- .../src}/Main.scala | 0 4 files changed, 35 insertions(+), 8 deletions(-) rename {stdlib-bootstrapped/test => stdlib-bootstrapped-tasty-tests/src}/Main.scala (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 456aa70f2a17..727e62f62afa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -134,7 +134,7 @@ jobs: - name: Cmd Tests run: | - ./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test" + ./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped-tasty-tests/run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test" ./project/scripts/cmdTests ./project/scripts/bootstrappedOnlyCmdTests @@ -488,7 +488,7 @@ jobs: - name: Test run: | - ./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test" + ./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;stdlib-bootstrapped-tasty-tests/run ;stdlib-bootstrapped-tasty-tests/test" ./project/scripts/cmdTests ./project/scripts/bootstrappedOnlyCmdTests diff --git a/build.sbt b/build.sbt index 80a36739d5e8..6f2d3e423f16 100644 --- a/build.sbt +++ b/build.sbt @@ -15,6 +15,7 @@ val `scala3-bench` = Build.`scala3-bench` val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped` val `scala3-bench-micro` = Build.`scala3-bench-micro` val `stdlib-bootstrapped` = Build.`stdlib-bootstrapped` +val `stdlib-bootstrapped-tasty` = Build.`stdlib-bootstrapped-tasty` val `stdlib-bootstrapped-tasty-tests` = Build.`stdlib-bootstrapped-tasty-tests` val `tasty-core` = Build.`tasty-core` val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped` diff --git a/project/Build.scala b/project/Build.scala index e493785c0af4..79d31a7a512c 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -936,7 +936,7 @@ object Build { dependsOn(dottyCompiler(Bootstrapped) % "provided; compile->runtime; test->test"). settings(commonBootstrappedSettings). settings( - moduleName := "scala-library", + moduleName := "scala2-library", javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, Compile / scalacOptions ++= { Seq("-sourcepath", ((Compile/sourceManaged).value / "scala-library-src").toString) @@ -1025,10 +1025,10 @@ object Build { |""".stripMargin) }).value, - // TODO package only TASTy files. - // We first need to check that a project can depend on a JAR that only contains TASTy files. - // Compile / exportJars := true, - // Compile / packageBin / mappings ~= { _.filter(_._2.endsWith(".tasty")) }, + Compile / exportJars := true, + artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) => + "scala2-library-" + dottyVersion + "." + artifact.extension + }, run := { val log = streams.value.log val args: Seq[String] = spaceDelimited("").parsed @@ -1077,7 +1077,21 @@ object Build { } ) + /** Packages the TASTy files of `stdlib-bootstrapped` in a jar */ + lazy val `stdlib-bootstrapped-tasty` = project.in(file("stdlib-bootstrapped-tasty")). + withCommonSettings(Bootstrapped). + settings( + exportJars := true, + Compile / packageBin / mappings := { + (`stdlib-bootstrapped` / Compile / packageBin / mappings).value + .filter(_._2.endsWith(".tasty")) + }, + ) + /** Test the tasty generated by `stdlib-bootstrapped` + * + * The sources in src are compiled using TASTy from stdlib-bootstrapped-tasty but then run + * with the scala-library compiled be Scala 2. * * The tests are run with the bootstrapped compiler and the tasty inpector on the classpath. * The classpath has the default `scala-library` and not `stdlib-bootstrapped`. @@ -1088,11 +1102,23 @@ object Build { */ lazy val `stdlib-bootstrapped-tasty-tests` = project.in(file("stdlib-bootstrapped-tasty-tests")). withCommonSettings(Bootstrapped). + dependsOn(dottyCompiler(Bootstrapped) % "compile->compile"). dependsOn(`scala3-tasty-inspector` % "test->test"). + dependsOn(`stdlib-bootstrapped-tasty`). settings(commonBootstrappedSettings). settings( javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value, - javaOptions += "-Ddotty.scala.library=" + (`stdlib-bootstrapped` / Compile / packageBin).value.getAbsolutePath + Test / javaOptions += "-Ddotty.scala.library=" + (`stdlib-bootstrapped` / Compile / packageBin).value.getAbsolutePath, + Compile / compile / fullClasspath ~= { + _.filterNot(file => file.data.getName == s"scala-library-${stdlibVersion(Bootstrapped)}.jar") + }, + Compile / compile / dependencyClasspath := { + // make sure that the scala2-library (tasty of `stdlib-bootstrapped-tasty`) is listed before the scala-library (classfiles) + val (bootstrappedLib, otherLibs) = + (Compile / compile / dependencyClasspath).value + .partition(_.data.getName == s"scala2-library-${dottyVersion}.jar") + bootstrappedLib ++ otherLibs + }, ) lazy val `scala3-sbt-bridge` = project.in(file("sbt-bridge/src")). diff --git a/stdlib-bootstrapped/test/Main.scala b/stdlib-bootstrapped-tasty-tests/src/Main.scala similarity index 100% rename from stdlib-bootstrapped/test/Main.scala rename to stdlib-bootstrapped-tasty-tests/src/Main.scala