summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/ant/Scalac.scala
diff options
context:
space:
mode:
authordcaoyuan <dcaoyuan@epfl.ch>2009-11-18 04:35:07 +0000
committerdcaoyuan <dcaoyuan@epfl.ch>2009-11-18 04:35:07 +0000
commit08cba2fd9fad8456b85330bc2185d509357e1044 (patch)
treeba69cfbd1eab8a4511a54583d22e1c7105121de0 /src/compiler/scala/tools/ant/Scalac.scala
parent2edbf55c114c0eed66b8bbb05e56ef6b262aa62b (diff)
downloadscala-08cba2fd9fad8456b85330bc2185d509357e1044.tar.gz
scala-08cba2fd9fad8456b85330bc2185d509357e1044.tar.bz2
scala-08cba2fd9fad8456b85330bc2185d509357e1044.zip
Fixed #2631
Diffstat (limited to 'src/compiler/scala/tools/ant/Scalac.scala')
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala70
1 files changed, 63 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index aaa50cdd08..7b28ee9103 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -10,7 +10,7 @@
package scala.tools.ant
-import java.io.{File,PrintWriter,BufferedWriter,FileWriter}
+import java.io.{File,PrintWriter,BufferedWriter,FileWriter, IOException}
import org.apache.tools.ant.{ BuildException, Project, AntClassLoader }
import org.apache.tools.ant.taskdefs.{MatchingTask,Java}
@@ -18,7 +18,7 @@ import org.apache.tools.ant.types.{Path, Reference, FileSet}
import org.apache.tools.ant.util.{FileUtils, GlobPatternMapper,
SourceFileScanner}
-import scala.tools.nsc.{Global, Settings}
+import scala.tools.nsc.{Global, Settings, Properties}
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
/** <p>
@@ -105,10 +105,10 @@ class Scalac extends MatchingTask {
/** Defines valid values for the <code>deprecation</code> and
* <code>unchecked</code> properties. */
object Flag extends PermissibleValue {
- val values = List("yes", "no", "on", "off")
+ val values = List("yes", "no", "on", "off", "true", "false")
def toBoolean(flag: String) =
- if (flag == "yes" || flag == "on") Some(true)
- else if (flag == "no" || flag == "off") Some(false)
+ if (flag == "yes" || flag == "on" || flag == "true") Some(true)
+ else if (flag == "no" || flag == "off" || flag == "false") Some(false)
else None
}
@@ -477,6 +477,9 @@ class Scalac extends MatchingTask {
/** Initializes settings and source files */
protected def initialize: (Settings, List[File], Boolean) = {
+ if (scalacDebugging)
+ log("Base directory is `%s`".format(scala.tools.nsc.io.Path("").normalize))
+
// Tests if all mandatory attributes are set and valid.
if (origin.isEmpty) error("Attribute 'srcdir' is not set.")
if (!destination.isEmpty && !destination.get.isDirectory())
@@ -558,11 +561,64 @@ class Scalac extends MatchingTask {
if (!assemrefs.isEmpty) settings.assemrefs.value = assemrefs.get
log("Scalac params = '" + addParams + "'", Project.MSG_DEBUG)
- settings.parseParams(addParams)
+ // todo, process fs from addParams?
+ val fs = processArguments(settings, addParams.trim.split("""\s+""").toList)
+
+ // resolve dependenciesFile path from project's basedir, so <ant antfile ...> call from other project works.
+ // the dependenciesFile may be relative path to basedir or absolute path, in either case, the following code
+ // will return correct answer.
+ settings.dependenciesFile.value match {
+ case "none" =>
+ case x =>
+ val depFilePath = scala.tools.nsc.io.Path(x)
+ settings.dependenciesFile.value = scala.tools.nsc.io.Path(getProject.getBaseDir).normalize resolve depFilePath path
+ }
(settings, sourceFiles, javaOnly)
}
+ /** Process the arguments and update the settings accordingly.
+ * This method is called only once, during initialization.
+ * @return Accumulated files to compile
+ */
+ protected def processArguments(settings: Settings, arguments: List[String]): List[String] = {
+ /** file extensions of files that the compiler can process */
+ lazy val fileEndings = Properties.fileEndings
+
+ // initialization
+ var ok = true
+ var fs: List[String] = Nil
+ var args = arguments
+ def errorAndNotOk(msg: String) = { error(msg) ; ok = false }
+
+ // given a @ argument expands it out
+ def doExpand(x: String) =
+ try { args = scala.tools.nsc.util.ArgumentsExpander.expandArg(x) ::: args.tail }
+ catch { case ex: IOException => errorAndNotOk(ex.getMessage) }
+
+ // true if it's a legit looking source file
+ def isSourceFile(x: String) =
+ (settings.script.value != "") ||
+ (fileEndings exists (x endsWith _))
+
+ // given an option for scalac finds out what it is
+ def doOption(x: String): Unit = {
+ val argsLeft = settings.parseParams(args)
+ if (args != argsLeft) args = argsLeft
+ else errorAndNotOk("bad option: '" + x + "'")
+ }
+
+ // cycle through args until empty or error
+ while (!args.isEmpty && ok) args.head match {
+ case x if x startsWith "@" => doExpand(x)
+ case x if x startsWith "-" => doOption(x)
+ case x if isSourceFile(x) => fs = x :: fs ; args = args.tail
+ case "" => args = args.tail // quick fix [martin: for what?]
+ case x => errorAndNotOk("don't know what to do with " + x)
+ }
+
+ fs
+ }
override def execute() {
val (settings, sourceFiles, javaOnly) = initialize
@@ -586,7 +642,7 @@ class Scalac extends MatchingTask {
if (compilerPath.isDefined) path add compilerPath.get
else getClass.getClassLoader match {
case cl: AntClassLoader => path add new Path(getProject, cl.getClasspath)
- case _ => error("Cannot determine default classpath for sclac, please specify one!")
+ case _ => error("Cannot determine default classpath for scalac, please specify one!")
}
path
}