aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--circle.yml2
-rw-r--r--examples/dotty-example/README.md3
-rw-r--r--examples/dotty-example/build/build.scala2
-rw-r--r--examples/dotty-example/src/Main.scala7
-rw-r--r--stage2/plugins/Dotty.scala107
-rw-r--r--test/test.scala2
6 files changed, 122 insertions, 1 deletions
diff --git a/circle.yml b/circle.yml
index 1615ad5..9de5b42 100644
--- a/circle.yml
+++ b/circle.yml
@@ -1,6 +1,6 @@
machine:
java:
- version: oraclejdk7
+ version: oraclejdk8
dependencies:
cache_directories:
diff --git a/examples/dotty-example/README.md b/examples/dotty-example/README.md
new file mode 100644
index 0000000..bc0f6b0
--- /dev/null
+++ b/examples/dotty-example/README.md
@@ -0,0 +1,3 @@
+Dotty example project compiling hello world with the next version of Scala.
+
+All you need to do to enable Dotty is `extends Dotty` in your build.scala .
diff --git a/examples/dotty-example/build/build.scala b/examples/dotty-example/build/build.scala
new file mode 100644
index 0000000..eb67d93
--- /dev/null
+++ b/examples/dotty-example/build/build.scala
@@ -0,0 +1,2 @@
+import cbt._
+class Build(val context: Context) extends Dotty
diff --git a/examples/dotty-example/src/Main.scala b/examples/dotty-example/src/Main.scala
new file mode 100644
index 0000000..411527a
--- /dev/null
+++ b/examples/dotty-example/src/Main.scala
@@ -0,0 +1,7 @@
+object Main extends Foo("Hello Dotty - trait parameters, yay"){
+ def main(args: Array[String]) = {
+ println(hello)
+ }
+}
+
+trait Foo(val hello: String)
diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala
new file mode 100644
index 0000000..1e5addb
--- /dev/null
+++ b/stage2/plugins/Dotty.scala
@@ -0,0 +1,107 @@
+package cbt
+import java.io.File
+import java.net.URL
+import java.nio.file.Files
+import java.nio.file.attribute.FileTime
+
+trait Dotty extends BaseBuild{
+ override def scalacOptions: Seq[String] = Seq()
+
+ private object compileCache extends Cache[Option[File]]
+ override def compile: Option[File] = compileCache{
+ new DottyLib(logger).compile(
+ context.cbtHasChanged,
+ needsUpdate || context.parentBuild.map(_.needsUpdate).getOrElse(false),
+ sourceFiles, compileTarget, compileStatusFile, dependencyClasspath ++ compileClasspath,
+ context.paths.mavenCache, scalacOptions, context.classLoaderCache
+ )
+ }
+}
+
+class DottyLib(logger: Logger){
+ val lib = new Lib(logger)
+ import lib._
+
+ def compile(
+ cbtHasChanged: Boolean,
+ needsRecompile: Boolean,
+ files: Seq[File],
+ compileTarget: File,
+ statusFile: File,
+ classpath: ClassPath,
+ mavenCache: File,
+ scalacOptions: Seq[String] = Seq(),
+ classLoaderCache: ClassLoaderCache
+ ): Option[File] = {
+
+ if(classpath.files.isEmpty)
+ throw new Exception("Trying to compile with empty classpath. Source files: " ++ files.toString)
+
+ if( files.isEmpty ){
+ None
+ }else{
+ if( needsRecompile ){
+ def Resolver(urls: URL*) = MavenResolver(cbtHasChanged, mavenCache, urls: _*)
+ val dotty = Resolver(mavenCentral).bindOne(
+ MavenDependency("ch.epfl.lamp","dotty_2.11","0.1-20160925-b2b475d-NIGHTLY")
+ )
+
+ val cp = classpath ++ dotty.classpath
+
+ val start = System.currentTimeMillis
+
+ val _class = "dotty.tools.dotc.Main"
+ val dualArgs =
+ Seq(
+ "-d", compileTarget.toString
+ )
+ val singleArgs = scalacOptions.map( "-S" ++ _ )
+
+ val code =
+ try{
+ System.err.println("Compiling with Dotty to " ++ compileTarget.toString)
+ compileTarget.mkdirs
+ redirectOutToErr{
+ lib.runMain(
+ _class,
+ dualArgs ++ singleArgs ++ Seq(
+ "-classpath", cp.string // let's put cp last. It so long
+ ) ++ files.map(_.toString),
+ dotty.classLoader(classLoaderCache)
+ )
+ }
+ } catch {
+ case e: Exception =>
+ System.err.println(red("Dotty crashed. Try running it by hand:"))
+ System.out.println(s"""
+java -cp \\
+${dotty.classpath.strings.mkString(":\\\n")} \\
+\\
+${_class} \\
+\\
+${dualArgs.grouped(2).map(_.mkString(" ")).mkString(" \\\n")} \\
+\\
+${singleArgs.mkString(" \\\n")} \\
+\\
+-classpath \\
+${cp.strings.mkString(":\\\n")} \\
+\\
+${files.sorted.mkString(" \\\n")}
+"""
+ )
+ ExitCode.Failure
+ }
+
+ if(code == ExitCode.Success){
+ // write version and when last compilation started so we can trigger
+ // recompile if cbt version changed or newer source files are seen
+ write(statusFile, "")//cbtVersion.getBytes)
+ Files.setLastModifiedTime(statusFile.toPath, FileTime.fromMillis(start) )
+ } else {
+ System.exit(code.integer) // FIXME: let's find a better solution for error handling. Maybe a monad after all.
+ }
+ }
+ Some( compileTarget )
+ }
+ }
+}
diff --git a/test/test.scala b/test/test.scala
index 4f0afcd..f8ba351 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -193,6 +193,8 @@ object Main{
compile("../examples/scalajs-react-example/js")
compile("../examples/scalajs-react-example/jvm")
compile("../examples/multi-project-example")
+ compile("../examples/dotty-example")
+ task("run","../examples/dotty-example")
task("fastOptJS","../examples/scalajs-react-example/js")
task("fullOptJS","../examples/scalajs-react-example/js")
compile("../examples/uber-jar-example")