diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-29 21:22:03 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-29 21:22:03 -0700 |
commit | 405fa45fb0f2fe2a5d7d8f0f7ebd8f112fc7cd70 (patch) | |
tree | 2ff021ac69d86c7819378ba2510ab7ed2b9b063a /src | |
parent | f32fca9c5858c487a83bf461d5b2ecc772025a4a (diff) | |
download | mill-405fa45fb0f2fe2a5d7d8f0f7ebd8f112fc7cd70.tar.gz mill-405fa45fb0f2fe2a5d7d8f0f7ebd8f112fc7cd70.tar.bz2 mill-405fa45fb0f2fe2a5d7d8f0f7ebd8f112fc7cd70.zip |
Got Zinc working on the test bench, compiling forge's own project
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/forge/Implicits.scala | 71 | ||||
-rw-r--r-- | src/main/scala/forge/Target.scala | 4 | ||||
-rw-r--r-- | src/test/scala/forge/Main.scala | 16 | ||||
-rw-r--r-- | src/test/scala/forge/TestMain.scala | 100 |
4 files changed, 100 insertions, 91 deletions
diff --git a/src/main/scala/forge/Implicits.scala b/src/main/scala/forge/Implicits.scala deleted file mode 100644 index 3295ce38..00000000 --- a/src/main/scala/forge/Implicits.scala +++ /dev/null @@ -1,71 +0,0 @@ -package forge - - -import scala.collection.mutable - -/** - * Container for all the type-level logic around appending things - * to tuples or flattening `Seq[Unit]`s into `Unit`s. - * - * Some of these implicits make liberal use of mutable state, so as - * to minimize allocations while parsing. - */ -object Implicits { - trait Sequencer[-T, V, R]{ - def apply(t: T, v: V): R - } - object Sequencer extends LowPriSequencer{ - def apply[T, V, R](f: (T, V) => R) = new Sequencer[T, V, R]{ - def apply(t: T, v: V): R = f(t, v) - } - implicit def SingleSequencer[T]: Sequencer[Unit, T, T] = Sequencer( (_, t) => t ) - } - trait LowPriSequencer extends LowerPriSequencer{ - implicit def UnitSequencer[T]: Sequencer[T, Unit, T] = Sequencer( (t, _) => t ) - } - trait LowerPriSequencer extends SequencerGen[Sequencer]{ - protected[this] def Sequencer0[A, B, C](f: (A, B) => C) = Sequencer(f) - } - trait Repeater[-T, R]{ - type Acc - def initial: Acc - def accumulate(t: T, acc: Acc): Unit - def result(acc: Acc): R - } - object Repeater extends LowPriRepeater{ - implicit object UnitRepeater extends Repeater[Unit, Unit]{ - type Acc = Unit - def initial = () - def accumulate(t: Unit, acc: Unit) = acc - def result(acc: Unit) = () - } - } - trait LowPriRepeater{ - implicit def GenericRepeaterImplicit[T] = GenericRepeater[T]() - case class GenericRepeater[T]() extends Repeater[T, Seq[T]]{ - type Acc = mutable.Buffer[T] - def initial = mutable.Buffer.empty[T] - def accumulate(t: T, acc: mutable.Buffer[T]) = acc += t - def result(acc: mutable.Buffer[T]) = acc - } - } - - trait Optioner[-T, R]{ - def none: R - def some(value: T): R - } - - object Optioner extends LowPriOptioner{ - implicit object UnitOptioner extends Optioner[Unit, Unit]{ - def none = () - def some(value: Unit) = () - } - } - trait LowPriOptioner{ - implicit def GenericOptionerImplicit[T] = GenericOptioner[T]() - case class GenericOptioner[T]() extends Optioner[T, Option[T]]{ - def none = None - def some(value: T) = Some(value) - } - } -}
\ No newline at end of file diff --git a/src/main/scala/forge/Target.scala b/src/main/scala/forge/Target.scala index 9dd3f8ab..c6908d1d 100644 --- a/src/main/scala/forge/Target.scala +++ b/src/main/scala/forge/Target.scala @@ -36,10 +36,6 @@ object Target{ def zip[V: Format](other: Target[V]) = { new Target.Zipped(this, other) } - def ~[V: Format, R: Format](other: Target[V]) - (implicit s: Implicits.Sequencer[T, V, R]): Target[R] = { - this.zip(other).map(s.apply _ tupled) - } } def test(inputs: Target[Int]*) = { new Test(inputs, pure = inputs.nonEmpty) diff --git a/src/test/scala/forge/Main.scala b/src/test/scala/forge/Main.scala deleted file mode 100644 index 51aaa3bd..00000000 --- a/src/test/scala/forge/Main.scala +++ /dev/null @@ -1,16 +0,0 @@ -package forge -import java.io.FileOutputStream -import java.util.jar.JarEntry - -import collection.JavaConverters._ -import ammonite.ops._ -import forge.util.{Args, OSet, PathRef} -object Main{ - - - def main(args: Array[String]): Unit = { - - } - - -} diff --git a/src/test/scala/forge/TestMain.scala b/src/test/scala/forge/TestMain.scala new file mode 100644 index 00000000..c94e13f0 --- /dev/null +++ b/src/test/scala/forge/TestMain.scala @@ -0,0 +1,100 @@ +package forge +import ammonite.ops._ +import java.io.File + +import coursier._ +import sbt.internal.inc.{FreshCompilerCache, ScalaInstance, ZincUtil} +import sbt.internal.util.{ConsoleOut, MainAppender} +import sbt.util.LogExchange +import xsbti.api.{ClassLike, DependencyContext} +import xsbti.compile._ + +import scalaz.concurrent.Task + +object TestMain { + def main(args: Array[String]): Unit = { + val scalaVersion = "2.12.4" + val start = Resolution( + Set( + Dependency(Module("org.scala-lang", "scala-reflect"), scalaVersion), + Dependency(Module("org.scala-lang", "scala-compiler"), scalaVersion), + Dependency(Module("org.scala-lang", "scala-reflect"), scalaVersion), + Dependency(Module("org.scala-sbt", "compiler-bridge_2.12"), "1.0.3"), + Dependency(Module("com.lihaoyi", "sourcecode_2.12"), "0.1.4"), + Dependency(Module("com.lihaoyi", "pprint_2.12"), "0.5.3"), + Dependency(Module("com.lihaoyi", "ammonite_2.12.4"), "1.0.3"), + Dependency(Module("com.typesafe.play", "play-json_2.12"), "2.6.6"), + Dependency(Module("org.scala-sbt", "zinc_2.12"), "1.0.3") + ) + ) + val repositories = Seq( + Cache.ivy2Local, + MavenRepository("https://repo1.maven.org/maven2") + ) + + val fetch = Fetch.from(repositories, Cache.fetch()) + val resolution = start.process.run(fetch).unsafePerformSync + + + val localArtifacts: Seq[File] = Task.gatherUnordered( + resolution.artifacts.map(Cache.file(_).run) + ).unsafePerformSync.flatMap(_.toOption) + + pprint.log(localArtifacts) + def grepJar(s: String) = localArtifacts.find(_.toString.endsWith(s)).get + + val scalac = ZincUtil.scalaCompiler( + new ScalaInstance( + version = scalaVersion, + loader = getClass.getClassLoader, + libraryJar = grepJar(s"scala-library-$scalaVersion.jar"), + compilerJar = grepJar(s"scala-compiler-$scalaVersion.jar"), + allJars = localArtifacts.toArray, + explicitActual = None + ), + grepJar("compiler-bridge_2.12-1.0.3.jar") + ) + + val outputDir = pwd/'target/'zinc + mkdir(outputDir) + val scalaFiles = ls.rec(pwd/'src/'main/'scala/'forge).filter(_.ext == "scala").map(_.toIO).toArray + + pprint.log(scalaFiles) + scalac.apply( + sources = scalaFiles, + changes = new DependencyChanges { + def isEmpty = true + def modifiedBinaries() = Array[File]() + def modifiedClasses() = Array[String]() + }, + classpath = localArtifacts.toArray, + singleOutput = outputDir.toIO, + options = Array(), + callback = new xsbti.AnalysisCallback { + def startSource(source: File) = () + def apiPhaseCompleted() = () + def enabled() = true + def binaryDependency(onBinaryEntry: File, onBinaryClassName: String, fromClassName: String, fromSourceFile: File, context: DependencyContext) = () + def generatedNonLocalClass(source: File, classFile: File, binaryClassName: String, srcClassName: String) = () + def problem(what: String, pos: xsbti.Position, msg: String, severity: xsbti.Severity, reported: Boolean) = () + def dependencyPhaseCompleted() = () + def classDependency(onClassName: String, sourceClassName: String, context: DependencyContext) = () + def generatedLocalClass(source: File, classFile: File) = () + def api(sourceFile: File, classApi: ClassLike) = () + + def mainClass(sourceFile: File, className: String) = () + def usedName(className: String, name: String, useScopes: java.util.EnumSet[xsbti.UseScope]) = () + }, + maximumErrors = 10, + cache = new FreshCompilerCache(), + log = { + val console = ConsoleOut.systemOut + val consoleAppender = MainAppender.defaultScreen(console) + val l = LogExchange.logger("Hello") + LogExchange.unbindLoggerAppenders("Hello") + LogExchange.bindLoggerAppenders("Hello", (consoleAppender -> sbt.util.Level.Warn) :: Nil) + l + } + ) + } +} |