|
| 1 | +package dotty.communitybuild |
| 2 | + |
| 3 | +import java.nio.file._ |
| 4 | +import java.io.{PrintWriter, File} |
| 5 | +import java.nio.charset.StandardCharsets.UTF_8 |
| 6 | +import org.junit.{Ignore, Test} |
| 7 | +import org.junit.Assert.{assertEquals, fail} |
| 8 | + |
| 9 | +class CommunityBuildTest { |
| 10 | + lazy val communitybuildDir: Path = Paths.get(sys.props("user.dir") + "/community-build/") |
| 11 | + |
| 12 | + lazy val compilerVersion: String = { |
| 13 | + val file = communitybuildDir.resolve("dotty-bootstrapped.version") |
| 14 | + new String(Files.readAllBytes(file), UTF_8) |
| 15 | + } |
| 16 | + |
| 17 | + /** Build the given project with the published local compiler and sbt plugin. |
| 18 | + * |
| 19 | + * This test reads the compiler version from community-build/dotty-bootstrapped.version |
| 20 | + * and expects community-build/sbt-dotty.sbt to set the compiler plugin. |
| 21 | + * |
| 22 | + * @param project The project name, should be a git submodule in community-build/ |
| 23 | + * @param command The sbt command used to build the project |
| 24 | + */ |
| 25 | + def test(project: String, command: String): Unit = { |
| 26 | + def log(msg: String) = println(Console.GREEN + msg + Console.RESET) |
| 27 | + |
| 28 | + log(s"Building $project with dotty-bootstrapped $compilerVersion...") |
| 29 | + |
| 30 | + val projectDir = communitybuildDir.resolve("community-projects").resolve(project) |
| 31 | + |
| 32 | + if (!Files.exists(projectDir.resolve(".git"))) { |
| 33 | + fail(s""" |
| 34 | + | |
| 35 | + |Missing $project submodule. You can initialize this module using |
| 36 | + | |
| 37 | + | git submodule update --init community-build/community-projects/$project |
| 38 | + | |
| 39 | + |""".stripMargin) |
| 40 | + } |
| 41 | + |
| 42 | + /** Executes shell command, returns false in case of error. */ |
| 43 | + def exec(binary: String, arguments: String*): Int = { |
| 44 | + val command = binary +: arguments |
| 45 | + log(command.mkString(" ")) |
| 46 | + val builder = new ProcessBuilder(command: _*).directory(projectDir.toFile).inheritIO() |
| 47 | + val process = builder.start() |
| 48 | + val exitCode = process.waitFor() |
| 49 | + exitCode |
| 50 | + } |
| 51 | + |
| 52 | + // Workaround for https://github.com/sbt/sbt/issues/4395 |
| 53 | + new File(sys.props("user.home") + "/.sbt/1.0/plugins").mkdirs() |
| 54 | + val pluginFilePath = communitybuildDir.resolve("sbt-dotty.sbt").toAbsolutePath().toString() |
| 55 | + |
| 56 | + // Run the sbt command with the compiler version and sbt plugin set in the build |
| 57 | + val arguments = Seq( |
| 58 | + "-sbt-version", "1.2.7", |
| 59 | + s"--addPluginSbtFile=$pluginFilePath", |
| 60 | + s";clean ;set updateOptions in Global ~= (_.withLatestSnapshots(false)) ;++$compilerVersion! $command" |
| 61 | + ) |
| 62 | + |
| 63 | + val exitCode = exec("sbt", arguments: _*) |
| 64 | + |
| 65 | + if (exitCode != 0) { |
| 66 | + fail(s""" |
| 67 | + | |
| 68 | + |sbt exited with an error code. To reproduce without JUnit, use: |
| 69 | + | |
| 70 | + | sbt community-build/prepareCommunityBuild |
| 71 | + | cd community-build/community-projects/$project |
| 72 | + | sbt ${arguments.init.mkString(" ")} "${arguments.last}" |
| 73 | + | |
| 74 | + |For a faster feedback loop, one can try to extract a direct call to dotc from |
| 75 | + |usign the sbt export command. For instance, for scalacheck, use |
| 76 | + | sbt export jvm/test:compileIncremental |
| 77 | + | |
| 78 | + |""".stripMargin) |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + @Test def algebra = test( |
| 83 | + project = "algebra", |
| 84 | + command = "coreJVM/compile" |
| 85 | + ) |
| 86 | + |
| 87 | + @Test def scalacheck = test( |
| 88 | + project = "scalacheck", |
| 89 | + command = "jvm/test:compile" |
| 90 | + ) |
| 91 | + |
| 92 | + @Test def scalatest = test( |
| 93 | + project = "scalatest", |
| 94 | + command = "scalatest/compile" |
| 95 | + ) |
| 96 | + |
| 97 | + @Test def scopt = test( |
| 98 | + project = "scopt", |
| 99 | + command = "scoptJVM/compile" |
| 100 | + ) |
| 101 | + |
| 102 | + @Test def scalap = test( |
| 103 | + project = "scalap", |
| 104 | + command = "scalap/compile" |
| 105 | + ) |
| 106 | + |
| 107 | + @Test def squants = test( |
| 108 | + project = "squants", |
| 109 | + command = "squantsJVM/compile" |
| 110 | + ) |
| 111 | + |
| 112 | + @Test def betterfiles = test( |
| 113 | + project = "betterfiles", |
| 114 | + command = "dottyCompile" |
| 115 | + ) |
| 116 | + |
| 117 | + @Test def ScalaPB = test( |
| 118 | + project = "ScalaPB", |
| 119 | + command = "dottyCompile" |
| 120 | + ) |
| 121 | + |
| 122 | + @Test def minitest = test( |
| 123 | + project = "minitest", |
| 124 | + command = "dottyCompile" |
| 125 | + ) |
| 126 | + |
| 127 | + @Test def fastparse = test( |
| 128 | + project = "fastparse", |
| 129 | + command = "fastparseJVM/compile" |
| 130 | + ) |
| 131 | + |
| 132 | + // TODO: revert to sourcecodeJVM/test |
| 133 | + @Test def sourcecode = test( |
| 134 | + project = "sourcecode", |
| 135 | + command = "sourcecodeJVM/compile" |
| 136 | + ) |
| 137 | + |
| 138 | + // TODO @smarter? |
| 139 | + // @Test def stdLib213 = test( |
| 140 | + // project = "stdLib213", |
| 141 | + // command = "library/compile" |
| 142 | + // ) |
| 143 | + |
| 144 | + // TODO @oderky? It got broken by #5458 |
| 145 | + // @Test def pdbp = test( |
| 146 | + // project = "pdbp", |
| 147 | + // command = "compile" |
| 148 | + // ) |
| 149 | +} |
0 commit comments