From 59666ddfdca48ae79ef38bcf42427954c6fea17d Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Fri, 10 Feb 2017 17:18:34 -0500 Subject: upgrade dotty and detach logic from inheritance --- stage2/plugins/Dotty.scala | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala index d20f3ea..4934568 100644 --- a/stage2/plugins/Dotty.scala +++ b/stage2/plugins/Dotty.scala @@ -5,13 +5,15 @@ import java.nio.file.Files import java.nio.file.attribute.FileTime trait Dotty extends BaseBuild{ - def dottyVersion: String = "0.1-20160926-ec28ea1-NIGHTLY" + def dottyVersion: String = Dotty.version def dottyOptions: Seq[String] = Seq() override def scalaTarget: File = target ++ s"/dotty-$dottyVersion" - def dottyDependency: DependencyImplementation = Resolver(mavenCentral).bindOne( - MavenDependency("ch.epfl.lamp","dotty_2.11",dottyVersion) - ) + def dottyDependency: DependencyImplementation = + Resolver(mavenCentral).bindOne( + MavenDependency(Dotty.groupId,Dotty.artifactId,Dotty.version) + ) + private lazy val dottyLib = new DottyLib( logger, context.cbtLastModified, context.paths.mavenCache, @@ -31,9 +33,14 @@ trait Dotty extends BaseBuild{ override def repl = dottyLib.repl(context.args, classpath) - override def dependencies: Seq[Dependency] = Resolver(mavenCentral).bind( - ScalaDependency( "org.scala-lang.modules", "scala-java8-compat", "0.8.0-RC7" ) - ) + // this seems needed for cbt run of dotty produced artifacts + override def dependencies: Seq[Dependency] = Seq( dottyDependency ) +} + +object Dotty{ + val version: String = "0.1.1-20170203-da7d723-NIGHTLY" + val groupId = "ch.epfl.lamp" + val artifactId = "dotty_2.11" } class DottyLib( @@ -41,24 +48,22 @@ class DottyLib( cbtLastModified: Long, mavenCache: File, classLoaderCache: ClassLoaderCache, - dottyDependency: DependencyImplementation + dependency: DependencyImplementation )(implicit transientCache: java.util.Map[AnyRef,AnyRef]){ val lib = new Lib(logger) import lib._ - private def Resolver(urls: URL*) = MavenResolver(cbtLastModified, mavenCache, urls: _*) - def repl(args: Seq[String], classpath: ClassPath) = { consoleOrFail("Use `cbt direct repl` instead") lib.runMain( "dotty.tools.dotc.repl.Main", Seq( "-bootclasspath", - dottyDependency.classpath.string, + dependency.classpath.string, "-classpath", classpath.string ) ++ args, - dottyDependency.classLoader(classLoaderCache) + dependency.classLoader(classLoaderCache) ) } @@ -74,16 +79,16 @@ class DottyLib( docTarget.mkdirs val args = Seq( // FIXME: can we use compiler dependency here? - "-bootclasspath", dottyDependency.classpath.string, // FIXME: does this break for builds that don't have scalac dependencies? + "-bootclasspath", dependency.classpath.string, // FIXME: does this break for builds that don't have scalac dependencies? "-classpath", dependencyClasspath.string, // FIXME: does this break for builds that don't have scalac dependencies? "-d", docTarget.toString ) ++ compileArgs ++ sourceFiles.map(_.toString) logger.lib("creating docs for source files "+args.mkString(", ")) val exitCode = redirectOutToErr{ runMain( - "dotty.tools.dottydoc.api.java.Dottydoc", + "dotty.tools.dottydoc.DocDriver", args, - dottyDependency.classLoader(classLoaderCache), + dependency.classLoader(classLoaderCache), fakeInstance = true // this is a hack as Dottydoc's main method is not static ) } @@ -127,10 +132,10 @@ class DottyLib( lib.runMain( _class, dualArgs ++ singleArgs ++ Seq( - "-bootclasspath", dottyDependency.classpath.string, // let's put cp last. It so long + "-bootclasspath", dependency.classpath.string, // let's put cp last. It so long "-classpath", classpath.string // let's put cp last. It so long ) ++ sourceFiles.map(_.toString), - dottyDependency.classLoader(classLoaderCache) + dependency.classLoader(classLoaderCache) ) } } catch { @@ -138,7 +143,7 @@ class DottyLib( System.err.println(red("Dotty crashed. See https://github.com/lampepfl/dotty/issues. To reproduce run:")) System.out.println(s""" java -cp \\ -${dottyDependency.classpath.strings.mkString(":\\\n")} \\ +${dependency.classpath.strings.mkString(":\\\n")} \\ \\ ${_class} \\ \\ @@ -147,7 +152,7 @@ ${dualArgs.grouped(2).map(_.mkString(" ")).mkString(" \\\n")} \\ ${singleArgs.mkString(" \\\n")} \\ \\ -bootclasspath \\ -${dottyDependency.classpath.strings.mkString(":\\\n")} \\ +${dependency.classpath.strings.mkString(":\\\n")} \\ -classpath \\ ${classpath.strings.mkString(":\\\n")} \\ \\ -- cgit v1.2.3 From aca3c4dab2528b30ffad73b67ef95e41ab485304 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Sat, 11 Feb 2017 17:05:56 -0500 Subject: omit classpath when classpath is empty (= no dependencies, only jdk) --- stage1/Stage1Lib.scala | 35 ++++++++++++++++------------------- stage2/plugins/Dotty.scala | 18 +++++++++--------- stage2/plugins/Frege.scala | 11 +++++------ 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala index f73995e..4f3f592 100644 --- a/stage1/Stage1Lib.scala +++ b/stage1/Stage1Lib.scala @@ -201,8 +201,6 @@ class Stage1Lib( logger: Logger ) extends BaseLib{ val d = Dependencies(dependencies) val classpath = d.classpath val cp = classpath.string - if(classpath.files.isEmpty) - throw new Exception("Trying to compile with empty classpath. Source files: " ++ sourceFiles.toString) if( sourceFiles.isEmpty ){ None @@ -258,29 +256,28 @@ class Stage1Lib( logger: Logger ) extends BaseLib{ try{ lib.runMain( _class, - dualArgs ++ singleArgs ++ Seq( - "-cp", cp // let's put cp last. It so long + dualArgs ++ singleArgs ++ ( + if(cp.isEmpty) Nil else Seq("-cp", cp) ) ++ sourceFiles.map(_.toString), zinc.classLoader(classLoaderCache) ) } catch { - case e: Exception => + case scala.util.control.NonFatal(e) => System.err.println(red("The Scala compiler crashed. Try running it by hand:")) System.out.println(s""" - java -cp \\ - ${zinc.classpath.strings.mkString(":\\\n")} \\ - \\ - ${_class} \\ - \\ - ${dualArgs.grouped(2).map(_.mkString(" ")).mkString(" \\\n")} \\ - \\ - ${singleArgs.mkString(" \\\n")} \\ - \\ - -cp \\ - ${classpath.strings.mkString(":\\\n")} \\ - \\ - ${sourceFiles.sorted.mkString(" \\\n")} - """ +java -cp \\ +${zinc.classpath.strings.mkString(":\\\n")} \\ +\\ +${_class} \\ +\\ +${dualArgs.grouped(2).map(_.mkString(" ")).mkString(" \\\n")} \\ +\\ +${singleArgs.mkString(" \\\n")} \\ +\\ +${if(cp.isEmpty) "" else (" -classpath \\\n" ++ classpath.strings.mkString(":\\\n"))} \\ +\\ +${sourceFiles.sorted.mkString(" \\\n")} +""" ) redirectOutToErr( e.printStackTrace ) diff --git a/stage2/plugins/Dotty.scala b/stage2/plugins/Dotty.scala index 4934568..8a49257 100644 --- a/stage2/plugins/Dotty.scala +++ b/stage2/plugins/Dotty.scala @@ -107,8 +107,6 @@ class DottyLib( val d = Dependencies(dependencies) val classpath = d.classpath val cp = classpath.string - if(classpath.files.isEmpty) - throw new Exception("Trying to compile with empty classpath. Source files: " ++ sourceFiles.toString) if( sourceFiles.isEmpty ){ None @@ -123,7 +121,7 @@ class DottyLib( "-d", compileTarget.toString ) val singleArgs = dottyOptions.map( "-S" ++ _ ) - + val cl = dependency.classLoader(classLoaderCache) val code = try{ System.err.println("Compiling with Dotty to " ++ compileTarget.toString) @@ -132,15 +130,17 @@ class DottyLib( lib.runMain( _class, dualArgs ++ singleArgs ++ Seq( - "-bootclasspath", dependency.classpath.string, // let's put cp last. It so long - "-classpath", classpath.string // let's put cp last. It so long + "-bootclasspath", dependency.classpath.string + ) ++ ( + if(cp.isEmpty) Nil else Seq("-classpath", cp) // let's put cp last. It so long ) ++ sourceFiles.map(_.toString), - dependency.classLoader(classLoaderCache) + cl ) } } catch { case e: Exception => System.err.println(red("Dotty crashed. See https://github.com/lampepfl/dotty/issues. To reproduce run:")) + System.err.println(cl) System.out.println(s""" java -cp \\ ${dependency.classpath.strings.mkString(":\\\n")} \\ @@ -153,13 +153,13 @@ ${singleArgs.mkString(" \\\n")} \\ \\ -bootclasspath \\ ${dependency.classpath.strings.mkString(":\\\n")} \\ --classpath \\ -${classpath.strings.mkString(":\\\n")} \\ +${if(cp.isEmpty) "" else (" -classpath \\\n" ++ classpath.strings.mkString(":\\\n"))} \\ \\ ${sourceFiles.sorted.mkString(" \\\n")} + """ ) - ExitCode.Failure + throw e } if(code == ExitCode.Success){ diff --git a/stage2/plugins/Frege.scala b/stage2/plugins/Frege.scala index c0868af..b5a4dd0 100644 --- a/stage2/plugins/Frege.scala +++ b/stage2/plugins/Frege.scala @@ -67,8 +67,6 @@ class FregeLib( val d = Dependencies(dependencies) val classpath = d.classpath val cp = classpath.string - if(classpath.files.isEmpty) - throw new Exception("Trying to compile with empty classpath. Source files: " ++ sourceFiles.toString) if( sourceFiles.isEmpty ){ None @@ -78,11 +76,13 @@ class FregeLib( if( d.lastModified > lastCompiled || sourceFiles.exists(_.lastModified > lastCompiled) ){ val _class = "frege.compiler.Main" + val fp = (fregeDependency.classpath.strings ++ fregeDependencies.map(_.classpath.string)) val dualArgs = Seq( "-target", fregeTarget, - "-d", compileTarget.toString, - "-fp", (fregeDependency.classpath.strings ++ fregeDependencies.map(_.classpath.string)).mkString(":") + "-d", compileTarget.toString + ) ++ ( + if(fp.isEmpty) Nil else Seq("-fp", fp.mkString(":")) ) val singleArgs = fregeOptions val code = @@ -111,8 +111,7 @@ ${singleArgs.mkString(" \\\n")} \\ \\ -bootclasspath \\ ${fregeDependency.classpath.strings.mkString(":\\\n")} \\ --classpath \\ -${classpath.strings.mkString(":\\\n")} \\ +${if(classpath.strings.isEmpty) "" else (" -fp \\\n" ++ classpath.strings.mkString(":\\\n"))} \\ \\ ${sourceFiles.sorted.mkString(" \\\n")} """ -- cgit v1.2.3