summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-11-08 10:34:03 +0000
committermichelou <michelou@epfl.ch>2006-11-08 10:34:03 +0000
commit4fb358b4ae286de7dd30fd3143aeabc689636876 (patch)
tree60db62d7b16c7e17100076566bd4e6c8fef74a63
parent1e1a2160bcd84fcfe58132a4da1e1f9d16fa939f (diff)
downloadscala-4fb358b4ae286de7dd30fd3143aeabc689636876.tar.gz
scala-4fb358b4ae286de7dd30fd3143aeabc689636876.tar.bz2
scala-4fb358b4ae286de7dd30fd3143aeabc689636876.zip
added ant task "FastScalac" and updated test su...
added ant task "FastScalac" and updated test suite accordingly
-rw-r--r--src/compiler/scala/tools/ant/FastScalac.scala118
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala13
-rw-r--r--src/compiler/scala/tools/ant/antlib.xml2
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala29
-rw-r--r--test/files/ant/fsc-build.xml31
-rw-r--r--test/files/ant/fsc.check13
-rw-r--r--test/files/ant/fsc.scala (renamed from test/files/ant/test.scala)0
-rw-r--r--test/files/ant/imported.xml (renamed from test/files/ant/test-build.xml)23
-rw-r--r--test/files/ant/scalac-build.xml31
-rw-r--r--test/files/ant/scalac.check13
-rw-r--r--test/files/ant/scalac.scala6
-rw-r--r--test/files/ant/test.check13
12 files changed, 244 insertions, 48 deletions
diff --git a/src/compiler/scala/tools/ant/FastScalac.scala b/src/compiler/scala/tools/ant/FastScalac.scala
new file mode 100644
index 0000000000..47dc7b1fee
--- /dev/null
+++ b/src/compiler/scala/tools/ant/FastScalac.scala
@@ -0,0 +1,118 @@
+/* __ ______________ *\
+** / |/ / ____/ ____/ **
+** / | | /___ / /___ **
+** /_/|__/_____/_____/ Copyright 2005-2006 LAMP/EPFL **
+** **
+\* */
+
+// $Id: $
+
+package scala.tools.ant {
+
+ /** <p>
+ * An Ant task to compile with the fast Scala compiler (<code>fsc</code>).
+ * </p>
+ * <p>
+ * In addition to the attributes shared with the <code>Scalac</code>
+ * task, this task also accepts the following attributes:
+ * </p>
+ * <ul style="font-family:Courier;">
+ * <li>reset</li>
+ * <li>server</li>
+ * <li>shutdown</li>
+ * </ul>
+ *
+ * @author Stephane Micheloud
+ */
+ class FastScalac extends Scalac {
+
+ private var resetCaches: Boolean = false
+
+ private var serverAddr: Option[String] = None
+
+ private var shutdownServer: Boolean = false
+
+/*============================================================================*\
+** Properties setters **
+\*============================================================================*/
+
+ /** Sets the <code>reset</code> attribute. Used by Ant.
+ *
+ * @param input The value for <code>reset</code>.
+ */
+ def setReset(input: Boolean): Unit =
+ resetCaches = input
+
+ /** Sets the <code>server</code> attribute. Used by Ant.
+ *
+ * @param input The value for <code>server</code>.
+ */
+ def setServer(input: String): Unit = {
+ def isHostNameValid(host: String): Boolean =
+ try { val _ = java.net.InetAddress.getByName(host); true }
+ catch { case _ => false }
+ if (isHostNameValid(input)) serverAddr = Some(input)
+ else error("Unknown server '" + input + "'")
+ }
+
+ /** Sets the <code>shutdown</code> attribute. Used by Ant.
+ *
+ * @param input The value for <code>shutdown</code>.
+ */
+ def setShutdown(input: Boolean): Unit =
+ shutdownServer = input
+
+/*============================================================================*\
+** The execute method **
+\*============================================================================*/
+
+ private def trim(xs: List[String]) = xs filter (x => x.length > 0)
+
+ /** Performs the compilation. */
+ override def execute() = {
+ val Pair(settings, sourceFiles) = initialize
+
+ val reset = settings.BooleanSetting("-reset", "Reset compile server caches")
+ //val server = settings.StringSetting("-server", "serverAddr", "Specify compile server socket", "")
+ val shutdown = settings.BooleanSetting("-shutdown", "Shutdown compile server")
+
+ reset.value = resetCaches
+ shutdown.value = shutdownServer
+ val cmdOptions =
+ // StringSetting
+ List.flatten(
+ List(settings.outdir, settings.classpath, settings.bootclasspath,
+ settings.extdirs, settings.encoding) map (s => List(s.nme, s.value))) :::
+ // '-server' option
+ (if (serverAddr.isEmpty) Nil else List("-server", serverAddr.get)) :::
+ // ChoiceSetting
+ (List(settings.debuginfo, settings.target) map (s => s.nme + ":" + s.value)) :::
+ // BooleanSetting
+ trim(
+ List(settings.debug, settings.deprecation, settings.nopredefs,
+ settings.verbose, reset, shutdown) map (s => if (s.value) s.nme else "")) :::
+ // PhaseSetting
+ trim(
+ List(settings.log) map (s => if (s.value.isEmpty) "" else s.nme + ":" + s.value))
+ //Console.println("options="+cmdOptions)//debug
+ //Console.println("files="+sourceFiles)//debug
+
+ if (!sourceFiles.isEmpty) {
+ val args = (cmdOptions ::: (sourceFiles map (.toString()))).toArray
+ try {
+ nsc.CompileClient.main0(args)
+ } catch {
+ case exception: Throwable if (exception.getMessage != null) =>
+ exception.printStackTrace()
+ error("Compile failed because of an internal compiler error (" +
+ exception.getMessage + "); see the error output for details.")
+ case exception =>
+ exception.printStackTrace()
+ error("Compile failed because of an internal compiler error " +
+ "(no error message provided); see the error output for details.")
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index c373e68f6a..6ef3fa50f5 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -486,9 +486,8 @@ package scala.tools.ant {
** The big execute method **
\*============================================================================*/
- /** Performs the compilation. */
- override def execute() = {
-
+ /** Initializes settings and source files */
+ protected def initialize: Pair[Settings, List[File]] = {
// Tests if all mandatory attributes are set and valid.
if (origin.isEmpty) error("Attribute 'srcdir' is not set.")
if (getOrigin.isEmpty) error("Attribute 'srcdir' is not set.")
@@ -541,7 +540,6 @@ package scala.tools.ant {
// Builds-up the compilation settings for Scalac with the existing Ant
// parameters.
- val reporter = new ConsoleReporter()
val settings = new Settings(error)
settings.outdir.value = asString(destination.get)
if (!classpath.isEmpty)
@@ -579,6 +577,13 @@ package scala.tools.ant {
if (argsBuf eq args)
error("Parameter '" + args.head + "' is not recognised by Scalac.")
}
+ Pair(settings, sourceFiles)
+ }
+
+ /** Performs the compilation. */
+ override def execute() = {
+ val reporter = new ConsoleReporter()
+ val Pair(settings, sourceFiles) = initialize
// Compiles the actual code
val compiler = new Global(settings, reporter)
diff --git a/src/compiler/scala/tools/ant/antlib.xml b/src/compiler/scala/tools/ant/antlib.xml
index b6f00d0a40..2f8565e896 100644
--- a/src/compiler/scala/tools/ant/antlib.xml
+++ b/src/compiler/scala/tools/ant/antlib.xml
@@ -1,6 +1,8 @@
<antlib>
<!--<taskdef name="scala"
classname="scala.tools.ant.Scala"/>-->
+ <taskdef name="fsc"
+ classname="scala.tools.ant.FastScalac"/>
<taskdef name="scalac"
classname="scala.tools.ant.Scalac"/>
<taskdef name="scalascript"
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala
index ada6f83ea4..facfca7768 100644
--- a/src/compiler/scala/tools/nsc/CompileClient.scala
+++ b/src/compiler/scala/tools/nsc/CompileClient.scala
@@ -7,11 +7,10 @@
package scala.tools.nsc
import java.lang.System.getProperty
-import java.io.File
-import java.io.PrintWriter
-import java.io.{BufferedReader, InputStreamReader}
+import java.io.{BufferedReader, File, InputStreamReader, PrintWriter}
+
+import scala.compat.StringBuilder
import scala.tools.util.StringOps
-import compat.StringBuilder
/** The main class for NSC, a compiler for the programming
* language Scala.
@@ -29,7 +28,7 @@ object CompileClient {
/** Convert a filename to an absolute path */
def absFileName(path: String) = new File(path).getAbsolutePath()
- /** Convert a sequence of filenames, separated by File.pathSeparator,
+ /** Convert a sequence of filenames, separated by <code>File.pathSeparator</code>,
* into absolute filenames.
*/
def absFileNames(paths: String) = {
@@ -38,7 +37,7 @@ object CompileClient {
pathsList.map(absFileName).mkString("", sep, "")
}
- def normalize(args: Array[String]): Pair[String, String] = {
+ private def normalize(args: Array[String]): Pair[String, String] = {
var i = 0
val vmArgs = new StringBuilder
var serverAdr = ""
@@ -74,17 +73,18 @@ object CompileClient {
Pair(vmArgs.toString, serverAdr)
}
- def main(args0: Array[String]): unit = {
+ // used by class ant.FastScalac to skip exit statement in Ant.
+ def main0(args0: Array[String]): Int = {
val args =
- if(args0.exists(arg => arg=="-d"))
+ if (args0.exists(arg => arg == "-d"))
args0
else
("-d" :: "." :: args0.toList).toArray
val Pair(vmArgs, serverAdr) = normalize(args)
- if(version) {
+ if (version) {
Console.println(versionMsg)
- return
+ return 0
}
if (verbose) {
Console.println("[Server arguments: " + args.mkString("", " ", "]"))
@@ -99,7 +99,7 @@ object CompileClient {
var sawerror = false
var fromServer = in.readLine()
while (fromServer != null) {
- if(CompileSocket.errorPattern.matcher(fromServer).matches)
+ if (CompileSocket.errorPattern.matcher(fromServer).matches)
sawerror = true
Console.println(fromServer)
fromServer = in.readLine()
@@ -108,6 +108,11 @@ object CompileClient {
out.close()
socket.close()
- exit(if (sawerror) 1 else 0)
+ if (sawerror) 1 else 0
+ }
+
+ def main(args: Array[String]) {
+ val status = main0(args)
+ exit(status)
}
}
diff --git a/test/files/ant/fsc-build.xml b/test/files/ant/fsc-build.xml
new file mode 100644
index 0000000000..5941ae8568
--- /dev/null
+++ b/test/files/ant/fsc-build.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id: $ -->
+
+<project name="fsc" default="run" basedir=".">
+
+ <import file="${basedir}/imported.xml"/>
+
+<!-- ===========================================================================
+BUILD
+============================================================================ -->
+
+ <target name="build" depends="init">
+ <echo level="verbose" message="build.dir=${build.dir}"/>
+ <mkdir dir="${build.dir}"/>
+ <fsc
+ srcdir="${source.dir}"
+ includes="**/${ant.project.name}*.scala"
+ destdir="${build.dir}"
+ classpathref="build.classpath"
+ />
+ <dirname property="log.dir" file="${build.dir}"/>
+ <echo level="verbose" message="log.dir=${log.dir}"/>
+ <replace
+ file="${log.dir}/${ant.project.name}-ant.log"
+ token="${log.dir}"
+ value="[...]/files/ant"
+ />
+ </target>
+
+</project>
+
diff --git a/test/files/ant/fsc.check b/test/files/ant/fsc.check
new file mode 100644
index 0000000000..d6c4f9078f
--- /dev/null
+++ b/test/files/ant/fsc.check
@@ -0,0 +1,13 @@
+Buildfile: [...]/files/ant/fsc-build.xml
+
+quick.init:
+
+latest.init:
+
+installed.init:
+
+init:
+
+build:
+ [mkdir] Created dir: [...]/files/ant/fsc-ant.obj
+ [fsc] Compiling 1 source file to [...]/files/ant/fsc-ant.obj
diff --git a/test/files/ant/test.scala b/test/files/ant/fsc.scala
index 47131daac6..47131daac6 100644
--- a/test/files/ant/test.scala
+++ b/test/files/ant/fsc.scala
diff --git a/test/files/ant/test-build.xml b/test/files/ant/imported.xml
index 7d28eccb47..1bb2318a8f 100644
--- a/test/files/ant/test-build.xml
+++ b/test/files/ant/imported.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- $Id$ -->
+<!-- $Id: $ -->
-<project name="test" default="build" basedir=".">
+<project name="imported" default="run" basedir=".">
<!-- Prevents system classpath from being used -->
<property name="build.sysclasspath" value="ignore"/>
@@ -119,25 +119,10 @@ INITIALISATION
</target>
<!-- ===========================================================================
-BUILD
+RUN
============================================================================ -->
- <target name="build" depends="init">
- <echo level="verbose" message="build.dir=${build.dir}"/>
- <mkdir dir="${build.dir}"/>
- <scalac
- srcdir="${source.dir}"
- includes="**/*.scala"
- destdir="${build.dir}"
- classpathref="build.classpath"
- />
- <dirname property="log.dir" file="${build.dir}"/>
- <replace
- file="${log.dir}/${ant.project.name}-ant.log"
- token="${log.dir}"
- value="[...]/files/ant"
- />
- </target>
+ <target name="run" depends="build, clean"/>
<!-- ===========================================================================
CLEAN
diff --git a/test/files/ant/scalac-build.xml b/test/files/ant/scalac-build.xml
new file mode 100644
index 0000000000..dcbc420800
--- /dev/null
+++ b/test/files/ant/scalac-build.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id: $ -->
+
+<project name="scalac" default="run" basedir=".">
+
+ <import file="${basedir}/imported.xml"/>
+
+<!-- ===========================================================================
+BUILD
+============================================================================ -->
+
+ <target name="build" depends="init">
+ <echo level="verbose" message="build.dir=${build.dir}"/>
+ <mkdir dir="${build.dir}"/>
+ <scalac
+ srcdir="${source.dir}"
+ includes="**/${ant.project.name}*.scala"
+ destdir="${build.dir}"
+ classpathref="build.classpath"
+ />
+ <dirname property="log.dir" file="${build.dir}"/>
+ <echo level="verbose" message="log.dir=${log.dir}"/>
+ <replace
+ file="${log.dir}/${ant.project.name}-ant.log"
+ token="${log.dir}"
+ value="[...]/files/ant"
+ />
+ </target>
+
+</project>
+
diff --git a/test/files/ant/scalac.check b/test/files/ant/scalac.check
new file mode 100644
index 0000000000..c7bd156484
--- /dev/null
+++ b/test/files/ant/scalac.check
@@ -0,0 +1,13 @@
+Buildfile: [...]/files/ant/scalac-build.xml
+
+quick.init:
+
+latest.init:
+
+installed.init:
+
+init:
+
+build:
+ [mkdir] Created dir: [...]/files/ant/scalac-ant.obj
+ [scalac] Compiling 1 source file to [...]/files/ant/scalac-ant.obj
diff --git a/test/files/ant/scalac.scala b/test/files/ant/scalac.scala
new file mode 100644
index 0000000000..47131daac6
--- /dev/null
+++ b/test/files/ant/scalac.scala
@@ -0,0 +1,6 @@
+package test
+
+object Main {
+ def main(args: Array[String]): Unit =
+ Console.println(args.toList)
+}
diff --git a/test/files/ant/test.check b/test/files/ant/test.check
deleted file mode 100644
index 6675558506..0000000000
--- a/test/files/ant/test.check
+++ /dev/null
@@ -1,13 +0,0 @@
-Buildfile: [...]/files/ant/test-build.xml
-
-quick.init:
-
-latest.init:
-
-installed.init:
-
-init:
-
-build:
- [mkdir] Created dir: [...]/files/ant/test-ant.obj
- [scalac] Compiling 1 source file to [...]/files/ant/test-ant.obj