summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/ant/FastScalac.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2011-11-16 20:35:21 +0000
committermichelou <michelou@epfl.ch>2011-11-16 20:35:21 +0000
commit44741eee5336b6d8f195d01cf993debf537124c7 (patch)
tree3044bf16965cbb16837c69a025758cfa93ed2be6 /src/compiler/scala/tools/ant/FastScalac.scala
parent3b0fd925a85f2d5cdab7c1467fb60fce287114f3 (diff)
downloadscala-44741eee5336b6d8f195d01cf993debf537124c7.tar.gz
scala-44741eee5336b6d8f195d01cf993debf537124c7.tar.bz2
scala-44741eee5336b6d8f195d01cf993debf537124c7.zip
Updated/fixed the following two Scala Ant tasks:
scalac (ant.Scalac) - added attributes `dependencyfile`, `explaintypes`, `nobootcp`, `nowarn` and `usejavacp` - added support for nested element `compilerarg` (see Ant manual) in order to pass prefix settings (eg. -J-Xbootclasspath, -Ddebug=true) to nsc.CompileClient - updated list of permissible values for compiler phases fsc (ant.FastScalac) - added attributes `ip4` and `maxIdle` in addition to `reset`, `server` and `shutdown` (and forwards them to nsc.CompileClient) - also forwards prefix settings `jvmargs` and `defines`, and boolean settings `explaintypes`, `nospecialization`, `nowarn`, `optimise`, `unchecked` and `usejavacp` to nsc.CompileClient - fixed CompileClient.process if-test Nota Bene I added the following element to partest.PartestTask (commit is pending) in order to automatically test the Scala Ant tasks: <anttests dir="${partest.dir}/${partest.srcdir}/ant" includes="*build.xml"/> Here is the output: [user@localhost scala]$ ant test.ant Buildfile: /home/user/workspace/scala/build.xml [echo] Forking with JVM opts: -Xms1536M [...] init: [echo] Build number is '2.10.0.r26022-b20111116212958' [echo] Built 16 November 2011, 21:29:58 [...] [...] test.ant: [partest] Running ant task tests [partest] testing: [...]/files/ant/fsc-build.xml [ OK ] [partest] testing: [...]/files/ant/scaladoc-build.xml [ OK ] [partest] testing: [...]/files/ant/scalac-build.xml [ OK ] [partest] Test suite finished with no failures. BUILD SUCCESSFUL Total time: 12 seconds
Diffstat (limited to 'src/compiler/scala/tools/ant/FastScalac.scala')
-rw-r--r--src/compiler/scala/tools/ant/FastScalac.scala146
1 files changed, 94 insertions, 52 deletions
diff --git a/src/compiler/scala/tools/ant/FastScalac.scala b/src/compiler/scala/tools/ant/FastScalac.scala
index ca60a55f02..96d242ae07 100644
--- a/src/compiler/scala/tools/ant/FastScalac.scala
+++ b/src/compiler/scala/tools/ant/FastScalac.scala
@@ -8,6 +8,11 @@
package scala.tools.ant
+import org.apache.tools.ant.Project
+
+import scala.tools.nsc.Settings
+import scala.tools.nsc.settings.FscSettings
+
/** An Ant task to compile with the fast Scala compiler (`fsc`).
*
* In addition to the attributes shared with the `Scalac` task, this task
@@ -15,6 +20,8 @@ package scala.tools.ant
* - `reset`
* - `server`
* - `shutdown`
+ * - `ipv4`
+ * - `maxIdle`
*
* @author Stephane Micheloud
*/
@@ -26,6 +33,10 @@ class FastScalac extends Scalac {
private var shutdownServer: Boolean = false
+ private var useIPv4: Boolean = false
+
+ private var idleMinutes: Option[Int] = None
+
/*============================================================================*\
** Properties setters **
\*============================================================================*/
@@ -48,64 +59,95 @@ class FastScalac extends Scalac {
*/
def setShutdown(input: Boolean) { shutdownServer = input }
+ /** Sets the `ipv4` attribute. Used by [[http://ant.apache.org Ant]].
+ *
+ * @param input The value for `ipv4`.
+ */
+ def setIPv4(input: Boolean) { useIPv4 = input }
+
+ /** Sets the `maxIdle` attribute. Used by [[http://ant.apache.org Ant]].
+ *
+ * @param input The value for `maxIdle`.
+ */
+ def setMaxIdle(input: Int) { if (0 <= input) idleMinutes = Some(input) }
+
/*============================================================================*\
** The execute method **
\*============================================================================*/
+ override protected def newSettings(error: String=>Unit): Settings =
+ new FscSettings(error)
+
/** Performs the compilation. */
- override def execute() = {
+ override def execute() {
val (settings, sourceFiles, javaOnly) = initialize
- val s = settings
-
- if (!sourceFiles.isEmpty && !javaOnly) {
- def trim(xs: List[String]) = xs filter (x => x.length > 0)
- val reset = settings.BooleanSetting("-reset", "Reset compile server caches")
- val shutdown = settings.BooleanSetting("-shutdown", "Shutdown compile server")
-
- reset.value = resetCaches
- shutdown.value = shutdownServer
-
- /** XXX Since fsc is largely unmaintained, the set of options being
- * individually assessed here is likely to bear little relationship to
- * the current set of options. Most likely this manifests in confusing
- * and very difficult to debug behavior in fsc. We should warn or fix.
- */
- val stringSettings =
- List(s.outdir, s.classpath, s.bootclasspath, s.extdirs, s.encoding) flatMap (x => List(x.name, x.value))
-
- val serverOption =
- serverAddr.toList flatMap (x => List("-server", x)) // '-server' option
-
- val choiceSettings =
- List(s.debuginfo, s.target) map (x => "%s:%s".format(x.name, x.value))
-
- val booleanSettings =
- List(s.debug, s.deprecation, s.verbose, reset, shutdown) map (x => if (x.value) List(x.name) else Nil) flatten
-
- val phaseSetting = {
- val s = settings.log
- if (s.value.isEmpty) Nil
- else List("%s:%s".format(s.name, s.value.mkString(",")))
- }
-
- val cmdOptions =
- stringSettings ::: serverOption ::: choiceSettings ::: booleanSettings ::: phaseSetting
-
- val args = (cmdOptions ::: (sourceFiles map (_.toString))).toArray
- try {
- if (scala.tools.nsc.CompileClient.process(args) && failonerror)
- buildError("Compile failed; see the compiler error output for details.")
- }
- catch {
- case exception: Throwable if exception.getMessage ne null =>
- exception.printStackTrace()
- buildError("Compile failed because of an internal compiler error (" +
- exception.getMessage + "); see the error output for details.")
- case exception =>
- exception.printStackTrace()
- buildError("Compile failed because of an internal compiler error " +
- "(no error message provided); see the error output for details.")
- }
+ if (sourceFiles.isEmpty || javaOnly)
+ return
+
+ // initialize fsc specific settings
+ val s = settings.asInstanceOf[FscSettings] // safe (newSettings)
+ s.reset.value = resetCaches
+ if (!serverAddr.isEmpty) s.server.value = serverAddr.get
+ s.shutdown.value = shutdownServer
+ s.preferIPv4.value = useIPv4
+ if (!idleMinutes.isEmpty) s.idleMins.value = idleMinutes.get
+
+ val prefixSettings =
+ List(
+ /*scalac*/
+ s.jvmargs, s.defines
+ ) flatMap (_.value)
+
+ val stringSettings =
+ List(
+ /*scalac*/
+ s.bootclasspath, s.classpath, s.extdirs, s.dependencyfile, s.encoding,
+ s.outdir, s.sourcepath,
+ /*fsc*/
+ s.server
+ ) filter (_.value != "") flatMap (x => List(x.name, x.value))
+
+ val choiceSettings =
+ List(
+ /*scalac*/
+ s.debuginfo, s.target
+ ) map (x => "%s:%s".format(x.name, x.value))
+
+ val booleanSettings =
+ List(
+ /*scalac*/
+ s.debug, s.deprecation, s.explaintypes, s.nospecialization, s.nowarn,
+ s.optimise, s.unchecked, s.usejavacp, s.verbose,
+ /*fsc*/
+ s.preferIPv4, s.reset, s.shutdown
+ ) filter (_.value) map (_.name)
+
+ val intSettings =
+ List(
+ /*fsc*/
+ s.idleMins
+ ) filter (x => x.value != x.default) flatMap (x => List(x.name, x.value.toString))
+
+ val phaseSetting = {
+ val s = settings.log
+ if (s.value.isEmpty) Nil
+ else List("%s:%s".format(s.name, s.value.mkString(",")))
+ }
+
+ val cmdOptions =
+ prefixSettings ::: stringSettings ::: choiceSettings ::: booleanSettings ::: intSettings ::: phaseSetting
+
+ val args = (cmdOptions ::: (sourceFiles map (_.toString))).toArray
+ log("FastScalac args="+args.mkString(" "), Project.MSG_DEBUG)
+ try {
+ if (!scala.tools.nsc.CompileClient.process(args) && failonerror)
+ buildError("Compile failed; see the compiler error output for details.")
+ }
+ catch {
+ case ex: Throwable =>
+ ex.printStackTrace()
+ val msg = if (ex.getMessage == null) "no error message provided" else ex.getMessage
+ buildError("Compile failed because of an internal compiler error (" + msg + "); see the error output for details.")
}
}
}