forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scala#5809: Run the community-build on every PR
This commit is meant to replace the infrastructure previously setup in https://github.com/lampepfl/dotty-community-build. A new sbt project, community-build, is added to dotty's Build.scala and contains all the integration tests for the community build. In case of failure the tests will output instructions on how to reproduce the error without JUnit. Hopefully these instructions are sufficient to have everyone fix regressions as they are introduced, or as a very last resort, update the code for the community build. This should be the main improvement over the previous approach, where the community build maintenance was centralized (Allan did all the work) and asynchronous (it's now broken for more than a month...). Another improvement is that a published local version of the sbt plugin is used when running the integration test, so breakage to sbt-dotty should be caught earlier than before.
- Loading branch information
1 parent
5bec023
commit 5967bff
Showing
10 changed files
with
247 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.2.7 |
149 changes: 149 additions & 0 deletions
149
community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package dotty.communitybuild | ||
|
||
import java.nio.file._ | ||
import java.io.{PrintWriter, File} | ||
import java.nio.charset.StandardCharsets.UTF_8 | ||
import org.junit.{Ignore, Test} | ||
import org.junit.Assert.{assertEquals, fail} | ||
|
||
class CommunityBuildTest { | ||
lazy val communitybuildDir: Path = Paths.get(sys.props("user.dir") + "/community-build/") | ||
|
||
lazy val compilerVersion: String = { | ||
val file = communitybuildDir.resolve("dotty-bootstrapped.version") | ||
new String(Files.readAllBytes(file), UTF_8) | ||
} | ||
|
||
/** Build the given project with the published local compiler and sbt plugin. | ||
* | ||
* This test reads the compiler version from community-build/dotty-bootstrapped.version | ||
* and expects community-build/sbt-dotty.sbt to set the compiler plugin. | ||
* | ||
* @param project The project name, should be a git submodule in community-build/ | ||
* @param command The sbt command used to build the project | ||
*/ | ||
def test(project: String, command: String): Unit = { | ||
def log(msg: String) = println(Console.GREEN + msg + Console.RESET) | ||
|
||
log(s"Building $project with dotty-bootstrapped $compilerVersion...") | ||
|
||
val projectDir = communitybuildDir.resolve("community-projects").resolve(project) | ||
|
||
if (!Files.exists(projectDir.resolve(".git"))) { | ||
fail(s""" | ||
| | ||
|Missing $project submodule. You can initialize this module using | ||
| | ||
| git submodule update --init community-build/community-projects/$project | ||
| | ||
|""".stripMargin) | ||
} | ||
|
||
/** Executes shell command, returns false in case of error. */ | ||
def exec(binary: String, arguments: String*): Int = { | ||
val command = binary +: arguments | ||
log(command.mkString(" ")) | ||
val builder = new ProcessBuilder(command: _*).directory(projectDir.toFile).inheritIO() | ||
val process = builder.start() | ||
val exitCode = process.waitFor() | ||
exitCode | ||
} | ||
|
||
// Workaround for https://github.com/sbt/sbt/issues/4395 | ||
new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs() | ||
val pluginFilePath = communitybuildDir.resolve("sbt-dotty.sbt").toAbsolutePath().toString() | ||
|
||
// Run the sbt command with the compiler version and sbt plugin set in the build | ||
val arguments = Seq( | ||
"-sbt-version", "1.2.7", | ||
s"--addPluginSbtFile=$pluginFilePath", | ||
s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $command" | ||
) | ||
|
||
val exitCode = exec("sbt", arguments: _*) | ||
|
||
if (exitCode != 0) { | ||
fail(s""" | ||
| | ||
|sbt exited with an error code. To reproduce without JUnit, use: | ||
| | ||
| sbt community-build/prepareCommunityBuild | ||
| cd community-build/community-projects/$project | ||
| sbt ${arguments.init.mkString(" ")} "${arguments.last}" | ||
| | ||
|For a faster feedback loop, one can try to extract a direct call to dotc from | ||
|usign the sbt export command. For instance, for scalacheck, use | ||
| sbt export jvm/test:compileIncremental | ||
| | ||
|""".stripMargin) | ||
} | ||
} | ||
|
||
@Test def algebra = test( | ||
project = "algebra", | ||
command = "coreJVM/compile" | ||
) | ||
|
||
@Test def scalacheck = test( | ||
project = "scalacheck", | ||
command = "jvm/test:compile" | ||
) | ||
|
||
@Test def scalatest = test( | ||
project = "scalatest", | ||
command = "scalatest/compile" | ||
) | ||
|
||
@Test def scopt = test( | ||
project = "scopt", | ||
command = "scoptJVM/compile" | ||
) | ||
|
||
@Test def scalap = test( | ||
project = "scalap", | ||
command = "scalap/compile" | ||
) | ||
|
||
@Test def squants = test( | ||
project = "squants", | ||
command = "squantsJVM/compile" | ||
) | ||
|
||
@Test def betterfiles = test( | ||
project = "betterfiles", | ||
command = "dottyCompile" | ||
) | ||
|
||
@Test def ScalaPB = test( | ||
project = "ScalaPB", | ||
command = "dottyCompile" | ||
) | ||
|
||
@Test def minitest = test( | ||
project = "minitest", | ||
command = "dottyCompile" | ||
) | ||
|
||
@Test def fastparse = test( | ||
project = "fastparse", | ||
command = "fastparseJVM/compile" | ||
) | ||
|
||
// TODO: revert to sourcecodeJVM/test | ||
@Test def sourcecode = test( | ||
project = "sourcecode", | ||
command = "sourcecodeJVM/compile" | ||
) | ||
|
||
// TODO @smarter? | ||
// @Test def stdLib213 = test( | ||
// project = "stdLib213", | ||
// command = "library/compile" | ||
// ) | ||
|
||
// TODO @oderky? It got broken by #5458 | ||
// @Test def pdbp = test( | ||
// project = "pdbp", | ||
// command = "compile" | ||
// ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Dotty Community Build | ||
|
||
This project contains tests to build and test a corpus of open sources Scala projects against the latest version of Dotty. | ||
|
||
To run the community build on a local machine, first fetch all the git submodules with `git submodule update --init` and run `sbt community-build/test` from the root of the dotty repo. | ||
|
||
## Adding your project | ||
|
||
To add your project to the community build you can follow these steps: | ||
|
||
1. Get your project to compile with Dotty. Instructions can be found on the [dotty-example-project](https://github.com/lampepfl/dotty-example-project). | ||
See the submodules in [community-projects](https://github.com/lampepfl/dotty/tree/master/community-build/community-projects/) for examples of projects that compile with Dotty. | ||
|
||
2. Open a PR against this repo that: | ||
- Adds your project as a new git submodule | ||
- Adds a test in [CommunityBuildTest.scala](https://github.com/lampepfl/dotty/blob/master/src/test/scala/dotty/community-build/src/test/scala/dotty/communitybuild/CommunityBuildTest.scala) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters