Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Baccata committed Apr 10, 2018
1 parent d0fa222 commit b4f041d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
3 changes: 3 additions & 0 deletions core/src/mill/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion main/src/mill/main/MainRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
15 changes: 15 additions & 0 deletions main/test/resources/examples/external/outer/build.sc
Original file line number Diff line number Diff line change
@@ -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 }
}
35 changes: 35 additions & 0 deletions main/test/resources/examples/external/project/build.sc
Original file line number Diff line number Diff line change
@@ -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 }

}

19 changes: 19 additions & 0 deletions main/test/src/mill/main/OuterBuildTest.scala
Original file line number Diff line number Diff line change
@@ -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"))
}
}
}
11 changes: 6 additions & 5 deletions main/test/src/mill/util/ScriptTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@ 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}
}
}
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")
}


Expand Down

0 comments on commit b4f041d

Please sign in to comment.