From b4f041de52289d6b72124d038ba86983d43e79f6 Mon Sep 17 00:00:00 2001 From: Olivier Melois Date: Tue, 10 Apr 2018 18:30:04 +0200 Subject: [PATCH] WIP --- core/src/mill/eval/Evaluator.scala | 3 ++ main/src/mill/main/MainRunner.scala | 3 +- .../examples/external/outer/build.sc | 15 ++++++++ .../examples/external/project/build.sc | 35 +++++++++++++++++++ main/test/src/mill/main/OuterBuildTest.scala | 19 ++++++++++ main/test/src/mill/util/ScriptTestSuite.scala | 11 +++--- 6 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 main/test/resources/examples/external/outer/build.sc create mode 100644 main/test/resources/examples/external/project/build.sc create mode 100644 main/test/src/mill/main/OuterBuildTest.scala diff --git a/core/src/mill/eval/Evaluator.scala b/core/src/mill/eval/Evaluator.scala index a728ec9784a..e6f9ee5ebea 100644 --- a/core/src/mill/eval/Evaluator.scala +++ b/core/src/mill/eval/Evaluator.scala @@ -124,6 +124,9 @@ case class Evaluator[T](home: Path, (newResults, newEvaluated, false) case Right(labelledNamedTask) => + println("OUT PATH " + outPath) + println("EXT PATH " + externalOutPath) + val paths = Evaluator.resolveDestPaths( if (!labelledNamedTask.task.ctx.external) outPath else externalOutPath, labelledNamedTask.segments diff --git a/main/src/mill/main/MainRunner.scala b/main/src/mill/main/MainRunner.scala index a0a6dfe62b3..f28a9b89331 100644 --- a/main/src/mill/main/MainRunner.scala +++ b/main/src/mill/main/MainRunner.scala @@ -133,13 +133,14 @@ class MainRunner(val config: ammonite.main.Cli.Config, .map(path => path.toNIO.getParent) .getOrElse(config.wd.toNIO) val literalPath = pprint.Util.literalize(path.toString) + val external = !(path.compareTo(config.wd.toNIO) == 0) val top = s""" |package ${pkgName.head.encoded} |package ${Util.encodeScalaSourcePath(pkgName.tail)} |$imports |import mill._ |object $wrapName - |extends mill.define.BaseModule(ammonite.ops.Path($literalPath)) + |extends mill.define.BaseModule(ammonite.ops.Path($literalPath), $external) |with $wrapName{ | // Stub to make sure Ammonite has something to call after it evaluates a script, | // even if it does nothing... diff --git a/main/test/resources/examples/external/outer/build.sc b/main/test/resources/examples/external/outer/build.sc new file mode 100644 index 00000000000..7cd8d08c767 --- /dev/null +++ b/main/test/resources/examples/external/outer/build.sc @@ -0,0 +1,15 @@ +import mill._ + +object sub extends PathAware { + object sub extends PathAware { + + def dest = T { + T.ctx().dest + } + + } +} + +trait PathAware extends mill.Module { + def selfPath = T { millSourcePath } +} diff --git a/main/test/resources/examples/external/project/build.sc b/main/test/resources/examples/external/project/build.sc new file mode 100644 index 00000000000..cb838fbc808 --- /dev/null +++ b/main/test/resources/examples/external/project/build.sc @@ -0,0 +1,35 @@ +import $file.^.outer.build +import ammonite.ops._ +import mill._ + +def assertPaths(p1 : Path, p2 : Path) : Unit = if (p1 != p2) throw new Exception( + s"Paths were not equal : \n- $p1 \n- $p2" +) + +def check = T { + val thisPath : Path = millSourcePath + assert(thisPath.last == "project") + assertPaths(^.outer.build.millSourcePath, thisPath / up / 'outer ) + assertPaths(^.outer.build.sub.selfPath(), thisPath / up / 'outer / 'sub) + assertPaths(^.outer.build.sub.sub.selfPath(), thisPath / up / 'outer / 'sub / 'sub) + assertPaths(inner.selfPath(), thisPath / 'inner) + assertPaths(inner.sub.selfPath(), thisPath / 'inner / 'sub) + assertPaths(inner.sub2.selfPath(), thisPath / 'inner / 'sub2) + throw new Exception("WORK IN PROGESS") +} + + +object inner extends PathAware { + + object sub extends PathAware + + object sub2 extends ^.outer.build.PathAware + +} + +trait PathAware extends mill.Module { + + def selfPath = T { millSourcePath } + +} + diff --git a/main/test/src/mill/main/OuterBuildTest.scala b/main/test/src/mill/main/OuterBuildTest.scala new file mode 100644 index 00000000000..67bc9f0f61a --- /dev/null +++ b/main/test/src/mill/main/OuterBuildTest.scala @@ -0,0 +1,19 @@ +package mill.main + +import ammonite.ops._ +import mill.util.ScriptTestSuite +import utest._ + +object OuterBuildTest extends ScriptTestSuite(fork = false) { + def workspaceSlug = "compile-outer-deps" + def scriptSourcePath = + pwd / 'main / 'test / 'resources / 'examples / 'external + override def buildPath = 'project / "build.sc" + + val tests = Tests { + initWorkspace() + 'test - { + assert(eval("check")) + } + } +} diff --git a/main/test/src/mill/util/ScriptTestSuite.scala b/main/test/src/mill/util/ScriptTestSuite.scala index 53356930df0..e9f31ce309c 100644 --- a/main/test/src/mill/util/ScriptTestSuite.scala +++ b/main/test/src/mill/util/ScriptTestSuite.scala @@ -8,20 +8,21 @@ import utest._ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ def workspaceSlug: String def scriptSourcePath: Path + def buildPath: RelPath = "build.sc" val workspacePath = pwd / 'target / 'workspace / workspaceSlug + val wd = workspacePath / buildPath / up val stdOutErr = new PrintStream(new ByteArrayOutputStream()) -// val stdOutErr = new PrintStream(System.out) val stdIn = new ByteArrayInputStream(Array()) lazy val runner = new mill.main.MainRunner( - ammonite.main.Cli.Config(wd = workspacePath), + ammonite.main.Cli.Config(wd = wd), stdOutErr, stdOutErr, stdIn, None, Map.empty ) def eval(s: String*) = { - if (!fork) runner.runScript(workspacePath / "build.sc", s.toList) + if (!fork) runner.runScript(workspacePath / buildPath , s.toList) else{ try { - %(home / "mill-release", "-i", s)(workspacePath) + %(home / "mill-release", "-i", s)(wd) true }catch{case e: Throwable => false} } @@ -29,7 +30,7 @@ abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ def meta(s: String) = { val (List(selector), args) = ParseArgs.apply(Seq(s), multiSelect = false).right.get - read(workspacePath / "out" / selector._2.value.flatMap(_.pathSegments) / "meta.json") + read(wd / "out" / selector._2.value.flatMap(_.pathSegments) / "meta.json") }