diff options
Diffstat (limited to 'scalaplugin')
6 files changed, 33 insertions, 38 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala b/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala index cb59bdba..f720123d 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala @@ -9,31 +9,27 @@ import mill.util.{OSet, PrintLogger} object GenIdea { - def apply[T: Discovered](obj: T): Unit = { + def apply[T](mapping: Discovered.Mapping[T]): Unit = { val pp = new scala.xml.PrettyPrinter(999, 4) rm! pwd/".idea" rm! pwd/".idea_modules" - val discovered = implicitly[Discovered[T]] - val mapping = Discovered.mapping(obj)(discovered) val workspacePath = pwd / 'out - val evaluator = new Evaluator(workspacePath, mapping, new PrintLogger(true)) + val evaluator = new Evaluator(workspacePath, mapping.value, new PrintLogger(true)) - for((relPath, xml) <- xmlFileLayout(obj, evaluator, mapping)){ + for((relPath, xml) <- xmlFileLayout(mapping, evaluator)){ write.over(pwd/relPath, pp.format(xml)) } } - def xmlFileLayout[T: Discovered](obj: T, - evaluator: Evaluator, - mapping: Map[Target[_], LabelledTarget[_]]): Seq[(RelPath, scala.xml.Node)] = { + def xmlFileLayout[T](mapping: Discovered.Mapping[T], + evaluator: Evaluator): Seq[(RelPath, scala.xml.Node)] = { - val discovered = implicitly[Discovered[T]] val modules = Mirror - .traverse(obj, discovered.mirror){ (h, p) => - h.node(obj, p.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList) match { + .traverse(mapping.base, mapping.mirror){ (h, p) => + h.node(mapping.base, p.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList) match { case m: ScalaModule => Seq(p -> m) case _ => Nil } @@ -82,7 +78,7 @@ object GenIdea { val Seq(sourcePath: PathRef) = evaluator.evaluate(OSet(mod.sources)).values - val (destPath, jsonPath) = evaluator.resolveDestPaths(mapping(mod.compile)) + val (destPath, jsonPath) = evaluator.resolveDestPaths(mapping.value(mod.compile)) val elem = moduleXmlTemplate( sourcePath.path, diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala index 185cffc8..deaa766e 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala @@ -37,7 +37,7 @@ object AcyclicTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(AcyclicBuild) - def eval[T](t: Task[T]) = TestEvaluator.eval(mapping, workspacePath)(t) + def eval[T](t: Task[T]) = TestEvaluator.eval(mapping.value, workspacePath)(t) val packageScala = workspacePath/'src/'main/'scala/'acyclic/"package.scala" diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala index f4247094..c9c8618c 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala @@ -97,7 +97,7 @@ object BetterFilesTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(BetterFilesBuild) - def eval[T](t: Task[T]) = TestEvaluator.eval(mapping, workspacePath)(t) + def eval[T](t: Task[T]) = TestEvaluator.eval(mapping.value, workspacePath)(t) 'test - { diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala index 239f6871..a5e52330 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala @@ -47,7 +47,7 @@ object HelloWorldTests extends TestSuite { 'scalaVersion - { 'fromBuild - { val Right((result, evalCount)) = - eval(HelloWorld.scalaVersion, helloWorldMapping) + eval(HelloWorld.scalaVersion, helloWorldMapping.value) assert( result == "2.12.4", @@ -61,7 +61,7 @@ object HelloWorldTests extends TestSuite { val Right((result, evalCount)) = eval(HelloWorldScalaOverride.scalaVersion, - Discovered.mapping(HelloWorldScalaOverride)) + Discovered.mapping(HelloWorldScalaOverride).value) assert( result == "2.11.11", @@ -72,7 +72,7 @@ object HelloWorldTests extends TestSuite { 'scalacOptions - { 'emptyByDefault - { val Right((result, evalCount)) = - eval(HelloWorld.scalacOptions, helloWorldMapping) + eval(HelloWorld.scalacOptions, helloWorldMapping.value) assert( result.isEmpty, @@ -82,7 +82,7 @@ object HelloWorldTests extends TestSuite { 'override - { val Right((result, evalCount)) = eval(HelloWorldFatalWarnings.scalacOptions, - Discovered.mapping(HelloWorldFatalWarnings)) + Discovered.mapping(HelloWorldFatalWarnings).value) assert( result == Seq("-Ywarn-unused", "-Xfatal-warnings"), @@ -93,7 +93,7 @@ object HelloWorldTests extends TestSuite { 'compile - { 'fromScratch - { val Right((result, evalCount)) = - eval(HelloWorld.compile, helloWorldMapping) + eval(HelloWorld.compile, helloWorldMapping.value) val outPath = result.classes.path val analysisFile = result.analysisFile @@ -109,31 +109,31 @@ object HelloWorldTests extends TestSuite { // don't recompile if nothing changed val Right((_, unchangedEvalCount)) = - eval(HelloWorld.compile, helloWorldMapping) + eval(HelloWorld.compile, helloWorldMapping.value) assert(unchangedEvalCount == 0) } 'recompileOnChange - { val Right((_, freshCount)) = - eval(HelloWorld.compile, helloWorldMapping) + eval(HelloWorld.compile, helloWorldMapping.value) assert(freshCount > 0) write.append(mainObject, "\n") val Right((_, incCompileCount)) = - eval(HelloWorld.compile, helloWorldMapping) + eval(HelloWorld.compile, helloWorldMapping.value) assert(incCompileCount > 0, incCompileCount < freshCount) } 'failOnError - { write.append(mainObject, "val x: ") val Left(Result.Exception(err)) = - eval(HelloWorld.compile, helloWorldMapping) + eval(HelloWorld.compile, helloWorldMapping.value) assert(err.isInstanceOf[CompileFailed]) val (compilePath, compileMetadataPath) = TestEvaluator.resolveDestPaths(outputPath)( - helloWorldMapping(HelloWorld.compile)) + helloWorldMapping.value(HelloWorld.compile)) assert( ls.rec(compilePath / 'classes).isEmpty, @@ -144,7 +144,7 @@ object HelloWorldTests extends TestSuite { // compilation fails because of "-Xfatal-warnings" flag val Left(Result.Exception(err)) = eval(HelloWorldFatalWarnings.compile, - Discovered.mapping(HelloWorldFatalWarnings)) + Discovered.mapping(HelloWorldFatalWarnings).value) assert(err.isInstanceOf[CompileFailed]) } @@ -152,7 +152,7 @@ object HelloWorldTests extends TestSuite { 'runMain - { 'runMainObject - { val Right((_, evalCount)) = - eval(HelloWorld.runMain("Main"), helloWorldMapping) + eval(HelloWorld.runMain("Main"), helloWorldMapping.value) assert(evalCount > 0) @@ -164,7 +164,7 @@ object HelloWorldTests extends TestSuite { } 'notRunInvalidMainObject - { val Left(Result.Exception(err)) = - eval(HelloWorld.runMain("Invalid"), helloWorldMapping) + eval(HelloWorld.runMain("Invalid"), helloWorldMapping.value) assert( err.isInstanceOf[InteractiveShelloutException] @@ -174,7 +174,7 @@ object HelloWorldTests extends TestSuite { write.append(mainObject, "val x: ") val Left(Result.Exception(err)) = - eval(HelloWorld.runMain("Main"), helloWorldMapping) + eval(HelloWorld.runMain("Main"), helloWorldMapping.value) assert( err.isInstanceOf[CompileFailed] @@ -184,7 +184,7 @@ object HelloWorldTests extends TestSuite { 'run - { 'runIfMainClassProvided - { val Right((_, evalCount)) = - eval(HelloWorldWithMain.run(), helloWorldWithMainMapping) + eval(HelloWorldWithMain.run(), helloWorldWithMainMapping.value) assert(evalCount > 0) @@ -196,7 +196,7 @@ object HelloWorldTests extends TestSuite { } 'notRunWithoutMainClass - { val Left(Result.Exception(err)) = - eval(HelloWorld.run(), helloWorldMapping) + eval(HelloWorld.run(), helloWorldMapping.value) assert( err.isInstanceOf[RuntimeException] @@ -206,7 +206,7 @@ object HelloWorldTests extends TestSuite { 'jar - { 'nonEmpty - { val Right((result, evalCount)) = - eval(HelloWorld.jar, helloWorldMapping) + eval(HelloWorld.jar, helloWorldMapping.value) assert( exists(result.path), @@ -219,7 +219,7 @@ object HelloWorldTests extends TestSuite { val manifestFiles = Seq( unJarPath / "META-INF", - unJarPath / "META-INF" / "MANIFEST.MF", + unJarPath / "META-INF" / "MANIFEST.MF" ) val expectedFiles = compileClassfiles(unJarPath) ++ manifestFiles @@ -231,7 +231,7 @@ object HelloWorldTests extends TestSuite { } 'runJar - { val Right((result, evalCount)) = - eval(HelloWorldWithMain.jar, helloWorldWithMainMapping) + eval(HelloWorldWithMain.jar, helloWorldWithMainMapping.value) assert( exists(result.path), @@ -247,7 +247,7 @@ object HelloWorldTests extends TestSuite { ) } 'logOutputToFile { - eval(HelloWorld.compile, helloWorldMapping) + eval(HelloWorld.compile, helloWorldMapping.value) val logFile = outputPath / "compile.log" assert(exists(logFile)) diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala index 0d876660..892857c9 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala @@ -74,7 +74,7 @@ object JawnTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(JawnBuild) - def eval[T](t: Task[T]) = TestEvaluator.eval(mapping, workspacePath)(t) + def eval[T](t: Task[T]) = TestEvaluator.eval(mapping.value, workspacePath)(t) 'test - { def compileOutput = workspacePath / 'jawn / "2.12.3" / 'Parser / 'compile diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala b/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala index f0593e2a..58e4f5f3 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala @@ -13,9 +13,8 @@ object TestEvaluator { new Evaluator(workspacePath, Map.empty, DummyLogger).resolveDestPaths(t) } - def eval[T]( - mapping: Map[Target[_], Mirror.LabelledTarget[_]], - workspacePath: Path)(t: Task[T]): Either[Result.Failing, (T, Int)] = { + def eval[T](mapping: Map[Target[_], Mirror.LabelledTarget[_]], + workspacePath: Path)(t: Task[T]): Either[Result.Failing, (T, Int)] = { val evaluator = new Evaluator(workspacePath, mapping, DummyLogger) val evaluated = evaluator.evaluate(OSet(t)) |