diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-18 21:54:37 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-18 21:54:37 -0700 |
commit | 738104aafa8ac0f0dd09e9ef015d909b3f016158 (patch) | |
tree | 63fcba527489f1ee69913745dd69336c1c58ad0d /src/main/scala/hbt/Target.scala | |
parent | 538b5ac28b80285953dbea08651cf5c5afa7c0f9 (diff) | |
download | mill-738104aafa8ac0f0dd09e9ef015d909b3f016158.tar.gz mill-738104aafa8ac0f0dd09e9ef015d909b3f016158.tar.bz2 mill-738104aafa8ac0f0dd09e9ef015d909b3f016158.zip |
- Add a configurable workspace to `evaluateTargetGraph`
- Break up `Hbt.scala` into `Args.scala` `Target.scala` and `Evaluator.scala`
Diffstat (limited to 'src/main/scala/hbt/Target.scala')
-rw-r--r-- | src/main/scala/hbt/Target.scala | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/scala/hbt/Target.scala b/src/main/scala/hbt/Target.scala new file mode 100644 index 00000000..99f6e27d --- /dev/null +++ b/src/main/scala/hbt/Target.scala @@ -0,0 +1,61 @@ +package hbt + +import java.nio.{file => jnio} + +import sourcecode.Enclosing + +trait Target[T]{ + val label: String + val inputs: Seq[Target[_]] + def evaluate(args: Args): T + + def map[V](f: T => V)(implicit path: Enclosing) = { + Target.Mapped(this, f, path.value) + } + def zip[V](other: Target[V])(implicit path: Enclosing) = { + Target.Zipped(this, other, path.value) + } + def ~[V, R](other: Target[V]) + (implicit s: Implicits.Sequencer[T, V, R]): Target[R] = { + this.zip(other).map(s.apply _ tupled) + } + +} + +object Target{ + def traverse[T](source: Seq[Target[T]])(implicit path: Enclosing) = { + Traverse[T](source, path.value) + } + case class Traverse[T](inputs: Seq[Target[T]], label: String) extends Target[Seq[T]]{ + def evaluate(args: Args) = { + for (i <- 0 until args.length) + yield args(i).asInstanceOf[T] + } + + } + case class Mapped[T, V](source: Target[T], f: T => V, + label: String) extends Target[V]{ + def evaluate(args: Args) = f(args(0)) + val inputs = List(source) + } + case class Zipped[T, V](source1: Target[T], + source2: Target[V], + label: String) extends Target[(T, V)]{ + def evaluate(args: Args) = (args(0), args(0)) + val inputs = List(source1, source1) + } + + def path(path: jnio.Path)(implicit label: Enclosing) = Path(path, label.value) + case class Path(path: jnio.Path, label: String) extends Target[jnio.Path]{ + def evaluate(args: Args) = path + val inputs = Nil + } +// case class Command(inputs: Seq[Target[jnio.Path]], +// output: Seq[Target[jnio.Path]], +// label: String) extends Target[Command.Result] +// object Command{ +// case class Result(stdout: String, +// stderr: String, +// writtenFiles: Seq[jnio.Path]) +// } +} |