diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-31 20:54:00 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-31 20:54:00 -0700 |
commit | f63535b955941e1a9a0f84abeaf53bb2f2cc2fc4 (patch) | |
tree | c9ed2e76692df275a7456b4bd7230a6132ae366a /src/main | |
parent | c8fa7e83c1934e30e178cb727d98dcf367a13d93 (diff) | |
download | mill-f63535b955941e1a9a0f84abeaf53bb2f2cc2fc4.tar.gz mill-f63535b955941e1a9a0f84abeaf53bb2f2cc2fc4.tar.bz2 mill-f63535b955941e1a9a0f84abeaf53bb2f2cc2fc4.zip |
Sketched out `MetacircularTests` using `scalaplugin.Subproject`; still doesn't compile
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/scala/forge/Target.scala | 16 | ||||
-rw-r--r-- | src/main/scala/forge/package.scala | 7 | ||||
-rw-r--r-- | src/main/scala/forge/scalaplugin/Subproject.scala | 56 |
3 files changed, 49 insertions, 30 deletions
diff --git a/src/main/scala/forge/Target.scala b/src/main/scala/forge/Target.scala index f8205bed..01b76d47 100644 --- a/src/main/scala/forge/Target.scala +++ b/src/main/scala/forge/Target.scala @@ -4,6 +4,8 @@ package forge import ammonite.ops.{ls, mkdir} import forge.util.{Args, PathRef} import play.api.libs.json.{Format, JsValue, Json} + +import scala.annotation.compileTimeOnly abstract class Target[T] extends Target.Ops[T]{ /** * What other Targets does this Target depend on? @@ -21,14 +23,23 @@ abstract class Target[T] extends Target.Ops[T]{ */ def sideHash: Int = 0 + @compileTimeOnly("Target#apply() can only be used with a T{...} block") + def apply(): T = ??? } object Target{ class Target0[T](t: T) extends Target[T]{ + lazy val t0 = t val inputs = Nil - def evaluate(args: Args) = t + def evaluate(args: Args) = t0 + } + class Target1[T](t: => Target[T]) extends Target[T]{ + lazy val t0 = t + val inputs = t0.inputs + def evaluate(args: Args) = t0.evaluate(args) } - implicit def apply[T](t: T): Target[T] = new Target0(t) + implicit def toTarget[T](t: T): Target[T] = new Target0(t) + implicit def apply[T](t: => Target[T]): Target[T] = new Target1(t) abstract class Ops[T]{ this: Target[T] => def map[V](f: T => V) = new Target.Mapped(this, f) @@ -73,6 +84,7 @@ object Target{ mkdir(args.dest) import ammonite.ops._ implicit val path = ammonite.ops.Path(args.dest, pwd) + val toTarget = () // Shadow the implicit conversion :/ val output = %%(command(args)) assert(output.exitCode == 0) Subprocess.Result(output, PathRef(args.dest)) diff --git a/src/main/scala/forge/package.scala b/src/main/scala/forge/package.scala index f7d1c78b..1a07c846 100644 --- a/src/main/scala/forge/package.scala +++ b/src/main/scala/forge/package.scala @@ -1,9 +1,10 @@ import play.api.libs.json._ import ammonite.ops.{Bytes, Path} import forge.util.Args -import forge.{Target => T} package object forge { + val T = Target + type T[T] = Target[T] def zip[A, B](a: T[A], b: T[B]) = a.zip(b) def zip[A, B, C](a: T[A], b: T[B], c: T[C]) = new Target[(A, B, C)]{ val inputs = Seq(a, b, c) @@ -54,5 +55,7 @@ package object forge { } implicit val crFormat: Format[ammonite.ops.CommandResult] = Json.format - + implicit val depFormat: Format[coursier.Dependency] = Json.format + implicit val modFormat: Format[coursier.Module] = Json.format + implicit val attrFormat: Format[coursier.Attributes] = Json.format } diff --git a/src/main/scala/forge/scalaplugin/Subproject.scala b/src/main/scala/forge/scalaplugin/Subproject.scala index c4c9c562..b548c559 100644 --- a/src/main/scala/forge/scalaplugin/Subproject.scala +++ b/src/main/scala/forge/scalaplugin/Subproject.scala @@ -5,7 +5,6 @@ import java.io.File import ammonite.ops.{Path, ls, mkdir, pwd} import coursier.{Cache, Dependency, Fetch, MavenRepository, Module, Repository, Resolution} -import forge.scalaplugin.Compile.getClass import forge.{Target => T} import forge.util.PathRef import sbt.internal.inc.{FreshCompilerCache, ScalaInstance, ZincUtil} @@ -98,37 +97,42 @@ import Subproject._ abstract class Subproject { val scalaVersion: T[String] - val compileDeps: T[Seq[coursier.Dependency]] - val runDeps: T[Seq[coursier.Dependency]] + val scalaBinaryVersion = T{ scalaVersion.map(_.split('.').dropRight(1).mkString(".")) } + val deps = T{ Seq[coursier.Dependency]() } + val compileDeps = T{ Seq[coursier.Dependency]() } + val runDeps = T{ Seq[coursier.Dependency]() } val basePath: T[Path] - val repositories: T[Seq[Repository]] = T( - Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")) + val repositories: Seq[Repository] = Seq( + Cache.ivy2Local, + MavenRepository("https://repo1.maven.org/maven2") ) - val compileDepClasspath: T[Seq[PathRef]] = resolveDependencies( - repositories, - for((scalaVersion, compileDeps) <- zip(scalaVersion, compileDeps)) - yield compileDeps :+ Dependency(Module("org.scala-lang", "scala-compiler"), scalaVersion) + val compileDepClasspath: T[Seq[PathRef]] = T( + resolveDependencies( + repositories, + for((scalaVersion, compileDeps) <- zip(scalaVersion, compileDeps)) + yield compileDeps :+ Dependency(Module("org.scala-lang", "scala-compiler"), scalaVersion) + ) ) - val runDepClasspath: T[Seq[PathRef]] = resolveDependencies( - repositories, - for((scalaVersion, runDeps) <- zip(scalaVersion, runDeps)) - yield runDeps ++ Seq( - Dependency(Module("org.scala-lang", "scala-library"), scalaVersion) + val runDepClasspath: T[Seq[PathRef]] = T( + resolveDependencies( + repositories, + for((scalaVersion, runDeps) <- zip(scalaVersion, runDeps)) + yield runDeps ++ Seq( + Dependency(Module("org.scala-lang", "scala-library"), scalaVersion) + ) ) ) - val sources: T[PathRef] = basePath.map(p => PathRef(p / 'src)) - val outputPath: T[Path] = basePath.map(p => p / 'out) - val resources: T[PathRef] = basePath.map(p => PathRef(p / 'resources)) - val compiledPath: T[Path] = outputPath.map(p => p / 'classpath) - val compiled: T[PathRef] = compileScala( - scalaVersion, - sources, - compileDepClasspath, - outputPath - ) - val classpath: T[Seq[PathRef]] = for((r, c) <- resources.zip(compiled)) yield Seq(r, c) - val jar: T[PathRef] = createJar(classpath) + val sources = T{ basePath.map(p => PathRef(p / 'src)) } + val outputPath = T{ basePath.map(p => p / 'out) } + val resources = T{ basePath.map(p => PathRef(p / 'resources)) } + val compiledPath = T{ outputPath.map(p => p / 'classpath) } + val compiled = T{ + compileScala(scalaVersion, sources, compileDepClasspath, outputPath) + } + + val classpath = T{ for((r, c) <- resources.zip(compiled)) yield Seq(r, c) } + val jar = T{ createJar(classpath) } } |