diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-26 10:26:25 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-26 10:26:25 -0800 |
commit | 0384674fa4fd1bda50cc484a70904c7e76eadca8 (patch) | |
tree | f9a12a374d904b5bca620a648cf19e412b9547cf /scalaplugin/src | |
parent | 39f38d4fd354ec70d4dcaf52a8804c8143b1c3f0 (diff) | |
download | mill-0384674fa4fd1bda50cc484a70904c7e76eadca8.tar.gz mill-0384674fa4fd1bda50cc484a70904c7e76eadca8.tar.bz2 mill-0384674fa4fd1bda50cc484a70904c7e76eadca8.zip |
WIP getting Acyclic build working in Mill. Test suite doesn't work, neither does non-2.12 versions of Scala, but compiling the main code on 2.12 works
Diffstat (limited to 'scalaplugin/src')
-rw-r--r-- | scalaplugin/src/test/resource/acyclic/build.sc | 119 | ||||
-rw-r--r-- | scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala | 98 |
2 files changed, 98 insertions, 119 deletions
diff --git a/scalaplugin/src/test/resource/acyclic/build.sc b/scalaplugin/src/test/resource/acyclic/build.sc deleted file mode 100644 index c52193b4..00000000 --- a/scalaplugin/src/test/resource/acyclic/build.sc +++ /dev/null @@ -1,119 +0,0 @@ - -val crossVersions = Cross("2.10.6", "2.11.8", "2.12.0") - -val acyclic = - for(crossVersion <- crossVersions) - yield new ScalaModule{ - def organization = "com.lihaoyi" - def name = "acyclic" - def scalaVersion = crossVersion - def version = "0.1.7" - - override def compileIvyDeps = Seq( - Dep.Java("org.scala-lang", "scala-compiler", scalaVersion()) - ) - } - -val tests = - for(crossVersion <- crossVersions) - yield new ScalaModule{ - override def projectDeps = Seq(acyclic(crossVersion)) - - override def ivyDeps = Seq( - Dep("com.lihaoyi", "utest", "0.6.0") - ) - def test() = T.command{ - TestRunner.apply( - "mill.UTestFramework", - runDepClasspath().map(_.path) :+ compile().path, - Seq(compile().path) - ) - } - } -// mill run acyclic(2.10.6) - - -// -//object acyclic extends crossModule(Seq("2.10.6", "2.11.8", "2.12.0"))(crossVersion => -// new ScalaModule{ -// def organization = "com.lihaoyi" -// def name = "acyclic" -// def scalaVersion = crossVersion -// def version = "0.1.7" -// -// override def compileIvyDeps = Seq( -// Dep.Java("org.scala-lang", "scala-compiler", scalaVersion()) -// ) -// -// object Tests extends Module{ -// override def projectDeps = Seq(Acyclic(scalaVersion)) -// -// override def ivyDeps = Seq( -// Dep("com.lihaoyi", "utest", "0.6.0") -// ) -// def test() = T.command{ -// TestRunner.apply( -// "mill.UTestFramework", -// runDepClasspath().map(_.path) :+ compile().path, -// Seq(compile().path) -// ) -// } -// } -// } -// -//) -// - -// Seq("2.10.6", "2.11.8", "2.12.0") -//case class Acyclic(scalaVersion: String = "2.11.8") extends CrossModule{ -// def organization = "com.lihaoyi" -// def name = "acyclic" -// def version = "0.1.7" -// -// override def compileIvyDeps = Seq( -// Dep.Java("org.scala-lang", "scala-compiler", scalaVersion()) -// ) -//} -// -//case class AcyclicTests(scalaVersion: String = "2.11.8") extends CrossModule{ -// override def projectDeps = Seq(Acyclic(scalaVersion)) -// -// override def ivyDeps = Seq( -// Dep("com.lihaoyi", "utest", "0.6.0") -// ) -// def test() = T.command{ -// TestRunner.apply( -// "mill.UTestFramework", -// runDepClasspath().map(_.path) :+ compile().path, -// Seq(compile().path) -// ) -// } -//} - -//unmanagedSourceDirectories in Test <+= baseDirectory(_ / "src" / "test" / "resources") -// -//// Sonatype -//publishTo <<= version { (v: String) => -// Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") -//} -// -//pomExtra := ( -// <url>https://github.com/lihaoyi/acyclic</url> -// <licenses> -// <license> -// <name>MIT license</name> -// <url>http://www.opensource.org/licenses/mit-license.php</url> -// </license> -// </licenses> -// <scm> -// <url>git://github.com/lihaoyi/utest.git</url> -// <connection>scm:git://github.com/lihaoyi/acyclic.git</connection> -// </scm> -// <developers> -// <developer> -// <id>lihaoyi</id> -// <name>Li Haoyi</name> -// <url>https://github.com/lihaoyi</url> -// </developer> -// </developers> -// ) diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala new file mode 100644 index 00000000..97ca4d0b --- /dev/null +++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala @@ -0,0 +1,98 @@ +package mill.scalaplugin + +import ammonite.ops.ImplicitWd._ +import ammonite.ops._ +import mill.define.{Cross, Target, Task} +import mill.discover.Discovered +import mill.eval.{Evaluator, PathRef, Result} +import mill.modules.Jvm.jarUp +import mill.{Module, T} +import mill.util.OSet +import utest._ +import mill.util.JsonFormatters._ +object AcyclicBuild{ + val acyclic = + for(crossVersion <- Cross("2.10.6", "2.11.8", "2.12.4")) + yield new ScalaModule{outer => + def basePath = AcyclicTests.workspacePath + def organization = "com.lihaoyi" + def name = "acyclic" + + def version = "0.1.7" + override def sources = basePath/'src/'main/'scala + def scalaVersion = crossVersion + override def compileIvyDeps = Seq( + Dep.Java("org.scala-lang", "scala-compiler", scalaVersion()) + ) + object test extends this.Tests{ + def basePath = AcyclicTests.workspacePath + override def ivyDeps = Seq( + Dep("com.lihaoyi", "utest", "0.6.0") + ) + override def sources = basePath/'src/'test/'scala + def testFramework = "utest.runner.Framework" + } + } +} +object AcyclicTests extends TestSuite{ + val workspacePath = pwd / 'target / 'workspace / 'acyclic + val srcPath = pwd / 'scalaplugin / 'src / 'test / 'resource / 'acyclic + val tests = Tests{ + 'acyclic - { + rm(workspacePath) + mkdir(workspacePath/up) + cp(srcPath, workspacePath) + val mapping = Discovered.mapping(AcyclicBuild) + def eval[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { + val evaluator = new Evaluator(workspacePath, mapping, _ => ()) + val evaluated = evaluator.evaluate(OSet(t)) + + if (evaluated.failing.keyCount == 0){ + Right(Tuple2( + evaluated.rawValues(0).asInstanceOf[Result.Success[T]].value, + evaluated.evaluated.collect{ + case t: Target[_] if mapping.contains(t) => t + case t: mill.define.Command[_] => t + }.size + )) + }else{ + Left(evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next()) + } + } + + // We can compile + val Right((pathRef, evalCount)) = eval(AcyclicBuild.acyclic("2.12.4").compile) + val outputPath = pathRef.path + val outputFiles = ls.rec(outputPath) + assert( + evalCount > 0, + outputFiles.contains(outputPath/'acyclic/'plugin/"GraphAnalysis.class"), + outputFiles.contains(outputPath/'acyclic/'plugin/"PluginPhase.class") + ) + + // Compilation is cached + val Right((_, evalCount2)) = eval(AcyclicBuild.acyclic("2.12.4").compile) + assert(evalCount2 == 0) + + val packageScala = workspacePath/'src/'main/'scala/'acyclic/"package.scala" + write.append(packageScala, "\n") + + // Caches are invalidated if code is changed + val Right((_, evalCount3)) = eval(AcyclicBuild.acyclic("2.12.4").compile) + assert(evalCount3 > 0) + + // Compilation can fail on broken code, and work when fixed + write.append(packageScala, "\n}}") + val Left(Result.Exception(ex)) = eval(AcyclicBuild.acyclic("2.12.4").compile) + + assert(ex.isInstanceOf[sbt.internal.inc.CompileFailed]) + + write.write(packageScala, read(packageScala).dropRight(3)) + + val Right((_, _)) = eval(AcyclicBuild.acyclic("2.12.4").compile) + + // Tests can run +// val Right((_, _)) = eval(AcyclicBuild.acyclic("2.12.4").test.test()) + } + } +} |