Skip to content

Commit

Permalink
Fix scala#5809: Run the community-build on every PR
Browse files Browse the repository at this point in the history
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
OlivierBlanvillain committed Feb 7, 2019
1 parent 5bec023 commit 5967bff
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 8 deletions.
22 changes: 15 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,31 @@ pipeline:
# We run tests in parallel. Tests run in a copy of the working directory to avoid conflict
test:
group: test
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
commands:
- cp -R . /tmp/1/ && cd /tmp/1/
- ./project/scripts/sbt ";compile ;test"
- ./project/scripts/cmdTests

test_bootstrapped:
group: test
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
commands:
- cp -R . /tmp/2/ && cd /tmp/2/
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test ;sjsSandbox/run"
- ./project/scripts/bootstrapCmdTests

community_build:
group: test
image: lampepfl/dotty:2019-02-06
commands:
- cp -R . /tmp/3/ && cd /tmp/3/
- export PATH=/tmp/4/project/scripts:$PATH
- sbt community-build/test

test_sbt:
group: test
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
commands:
- cp -R . /tmp/4/ && cd /tmp/4/
- ./project/scripts/sbt sbt-dotty/scripted
Expand All @@ -49,7 +57,7 @@ pipeline:

# DOCUMENTATION:
documentation:
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
commands:
- ./project/scripts/genDocs
secrets: [ bot_token ]
Expand All @@ -61,7 +69,7 @@ pipeline:
# PUBLISHING:
# Publishing expect NIGHTLYBUILD or RELEASEBUILD to be set. See dottyVersion in Build.scala
publish_nightly:
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
environment:
- NIGHTLYBUILD=yes
commands:
Expand All @@ -72,7 +80,7 @@ pipeline:
environment: nightly

publish_release:
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
environment:
- RELEASEBUILD=yes
commands:
Expand All @@ -96,7 +104,7 @@ pipeline:
event: tag

publish_sbt_release:
image: lampepfl/dotty:2018-12-12
image: lampepfl/dotty:2019-02-06
environment:
- RELEASEBUILD=yes
commands:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ bench/compile.txt

# The vscode app for testing
vscode-dotty/.vscode-test
dotty-bootstrapped.version
sbt-dotty.sbt
39 changes: 39 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,42 @@
path = scala2-library
url = https://github.com/lampepfl/scala.git
branch = dotty-library2.12
[submodule "community-build/community-projects/algebra"]
path = community-build/community-projects/algebra
url = https://github.com/dotty-staging/algebra
[submodule "community-build/community-projects/betterfiles"]
path = community-build/community-projects/betterfiles
url = https://github.com/dotty-staging/better-files
[submodule "community-build/community-projects/scalacheck"]
path = community-build/community-projects/scalacheck
url = https://github.com/dotty-staging/scalacheck
[submodule "community-build/community-projects/ScalaPB"]
path = community-build/community-projects/ScalaPB
url = https://github.com/dotty-staging/ScalaPB
[submodule "community-build/community-projects/scalatest"]
path = community-build/community-projects/scalatest
url = https://github.com/dotty-staging/scalatest
[submodule "community-build/community-projects/scopt"]
path = community-build/community-projects/scopt
url = https://github.com/dotty-staging/scopt
[submodule "community-build/community-projects/squants"]
path = community-build/community-projects/squants
url = https://github.com/dotty-staging/squants
[submodule "community-build/community-projects/scalap"]
path = community-build/community-projects/scalap
url = https://github.com/dotty-staging/scala
[submodule "community-build/community-projects/minitest"]
path = community-build/community-projects/minitest
url = https://github.com/dotty-staging/minitest
[submodule "community-build/community-projects/fastparse"]
path = community-build/community-projects/fastparse
url = https://github.com/dotty-staging/fastparse
[submodule "community-build/community-projects/stdLib213"]
path = community-build/community-projects/stdLib213
url = https://github.com/dotty-staging/scala
[submodule "community-build/community-projects/pdbp"]
path = community-build/community-projects/pdbp
url = https://github.com/dotty-staging/pdbp
[submodule "community-build/community-projects/sourcecode"]
path = community-build/community-projects/sourcecode
url = https://github.com/dotty-staging/sourcecode
1 change: 1 addition & 0 deletions .vscode-template/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"**/*.class": true,
"**/*.hasTasty": true,
"**/target/": true,
"community-build/community-projects": true,
"scala2-library/{doc,docs,lib,META-INF,scripts,spec,test,tools}/": true, // only allow scala-backend/src
"scala2-library/src/[abcefimprs]*": true, // only allow scala-backend/src/library
"scala-backend/{doc,docs,lib,META-INF,scripts,spec,test,tools}/": true, // only allow scala-backend/src
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ val `scala-reflect` = Build.`scala-reflect`
val scalap = Build.scalap
val dist = Build.dist
val `dist-bootstrapped` = Build.`dist-bootstrapped`
val `community-build` = Build.`community-build`

val sjsSandbox = Build.sjsSandbox

Expand Down
2 changes: 1 addition & 1 deletion community-build/community-projects/squants
Submodule squants updated 1 files
+2 −7 project/plugins.sbt
1 change: 1 addition & 0 deletions community-build/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.2.7
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"
// )
}
16 changes: 16 additions & 0 deletions community-build/test/scala/dotty/communitybuild/readme.md
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)
22 changes: 22 additions & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,28 @@ object Build {
}.dependsOn(compile in Compile).evaluated
)

val prepareCommunityBuild = taskKey[Unit]("Publish local the compiler and the sbt plugin. Also store the versions of the published local artefacts in two files, community-build/{dotty-bootstrapped.version,sbt-dotty.sbt}.")

lazy val `community-build` = project.in(file("community-build")).
settings(commonNonBootstrappedSettings).
settings(
prepareCommunityBuild := {
(publishLocal in `dotty-sbt-bridge`).value
(publishLocal in `dotty-interfaces`).value
(publishLocal in `scala-library`).value
(publishLocal in `scala-reflect`).value
(publishLocal in `dotty-library-bootstrapped`).value
(publishLocal in `dotty-doc-bootstrapped`).value
(publishLocal in `dotty-compiler-bootstrapped`).value
(publishLocal in `sbt-dotty`).value
(publishLocal in `dotty-bootstrapped`).value
val pluginText = s"""addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "$sbtDottyVersion")"""
IO.write(baseDirectory.value / "sbt-dotty.sbt", pluginText)
IO.write(baseDirectory.value / "dotty-bootstrapped.version", dottyVersion)
},
(Test / testOnly) := ((Test / testOnly) dependsOn prepareCommunityBuild).evaluated,
(Test / test ) := ((Test / test ) dependsOn prepareCommunityBuild).value
)

lazy val publishSettings = Seq(
publishMavenStyle := true,
Expand Down

0 comments on commit 5967bff

Please sign in to comment.