summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-20 05:38:34 +0000
committerPaul Phillips <paulp@improving.org>2010-02-20 05:38:34 +0000
commitff32248e9a8dd8dd6ea55e502c15e2e8626148e0 (patch)
tree69fcbd6be353afe4ee112e1e3ef95c9347977a5f /src
parentd6fb9d7809ea0c8cd9b8e3b0f46c78cfb96ad890 (diff)
downloadscala-ff32248e9a8dd8dd6ea55e502c15e2e8626148e0.tar.gz
scala-ff32248e9a8dd8dd6ea55e502c15e2e8626148e0.tar.bz2
scala-ff32248e9a8dd8dd6ea55e502c15e2e8626148e0.zip
Some cleanups on the scalacfork ant task since ...
Some cleanups on the scalacfork ant task since I'm clearly going to have to go through everything which touches classpaths in any way shape or form. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/ant/sabbus/ScalacFork.scala122
-rw-r--r--src/compiler/scala/tools/ant/sabbus/TaskArgs.scala2
2 files changed, 69 insertions, 55 deletions
diff --git a/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala b/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala
index 77cc11fe6b..20e410543e 100644
--- a/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala
+++ b/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala
@@ -8,15 +8,19 @@
// $Id$
-package scala.tools.ant.sabbus
+package scala.tools.ant
+package sabbus
import java.io.File
import java.io.FileWriter
import org.apache.tools.ant.Project
import org.apache.tools.ant.taskdefs.{MatchingTask, Java}
import org.apache.tools.ant.util.{GlobPatternMapper, SourceFileScanner}
+import scala.tools.nsc.io
class ScalacFork extends MatchingTask with TaskArgs {
+ val MainClass = "scala.tools.nsc.Main"
+
def setSrcdir(input: File) {
sourceDir = Some(input)
}
@@ -43,67 +47,75 @@ class ScalacFork extends MatchingTask with TaskArgs {
private var jvmArgs: Option[String] = None
private var argfile: Option[File] = None
+ private def createMapper() = {
+ val mapper = new GlobPatternMapper()
+ val extension = if (isMSIL) "*.msil" else "*.class"
+ mapper setTo extension
+ mapper setFrom "*.scala"
+
+ mapper
+ }
+
override def execute() {
- if (compilerPath.isEmpty) error("Mandatory attribute 'compilerpath' is not set.")
- if (sourceDir.isEmpty) error("Mandatory attribute 'srcdir' is not set.")
- if (destinationDir.isEmpty) error("Mandatory attribute 'destdir' is not set.")
+ def plural(x: Int) = if (x > 1) "s" else ""
+
+ val compilerPath = this.compilerPath getOrElse error("Mandatory attribute 'compilerpath' is not set.")
+ val sourceDir = this.sourceDir getOrElse error("Mandatory attribute 'srcdir' is not set.")
+ val destinationDir = this.destinationDir getOrElse error("Mandatory attribute 'destdir' is not set.")
val settings = new Settings
- settings.d = destinationDir.get
- if (!compTarget.isEmpty) settings.target = compTarget.get
- if (!compilationPath.isEmpty) settings.classpath = compilationPath.get
- if (!sourcePath.isEmpty) settings.sourcepath = sourcePath.get
- if (compTarget.isDefined && compTarget.get == "msil") settings.sourcedir = sourceDir.get
- if (!params.isEmpty) settings.more = params.get
+ settings.d = destinationDir
- // not yet used: compilerPath, sourcedir (used in mapper), failonerror, timeout
+ compTarget foreach (settings.target = _)
+ compilationPath foreach (settings.classpath = _)
+ sourcePath foreach (settings.sourcepath = _)
+ params foreach (settings.more = _)
+
+ if (isMSIL)
+ settings.sourcedir = sourceDir
+
+ val mapper = createMapper()
- val mapper = new GlobPatternMapper()
- if (compTarget.isDefined && compTarget.get == "msil")
- mapper.setTo("*.msil")
- else
- mapper.setTo("*.class")
- mapper.setFrom("*.scala")
val includedFiles: Array[File] =
new SourceFileScanner(this).restrict(
- getDirectoryScanner(sourceDir.get).getIncludedFiles,
- sourceDir.get,
- destinationDir.get,
+ getDirectoryScanner(sourceDir).getIncludedFiles,
+ sourceDir,
+ destinationDir,
mapper
- ) map (new File(sourceDir.get, _))
- if (includedFiles.size > 0 || argfile.isDefined) {
- if (includedFiles.size > 0)
- log("Compiling "+ includedFiles.size +" file"+
- (if (includedFiles.size > 1) "s" else "") +" to "+ destinationDir.get)
- if (argfile.isDefined)
- log("Using argument file: @"+ argfile.get)
-
- val java = new Java(this) // set this as owner
- java.setFork(true)
- // using 'setLine' creates multiple arguments out of a space-separated string
- if (!jvmArgs.isEmpty) java.createJvmarg().setLine(jvmArgs.get)
- java.setClasspath(compilerPath.get)
- java.setClassname("scala.tools.nsc.Main")
- if (!timeout.isEmpty) java.setTimeout(timeout.get)
-
- //dump the arguments to a file and do "java @file"
- val tempArgFile = File.createTempFile("scalacfork","")
- val outf = new FileWriter(tempArgFile)
- for (arg <- settings.toArgs)
- { outf.write(arg) ; outf.write(" ") }
- for (file <- includedFiles)
- { outf.write(file.getPath) ; outf.write(" ") }
- outf.close
-
- java.createArg().setValue("@"+ tempArgFile.getAbsolutePath)
- if (argfile.isDefined)
- java.createArg().setValue("@"+ argfile.get)
-
- log(java.getCommandLine.getCommandline.mkString("", " ", ""), Project.MSG_VERBOSE)
- val res = java.executeJava()
- if (failOnError && res != 0)
- error("Compilation failed because of an internal compiler error;"+
- " see the error output for details.")
- }
+ ) map (x => new File(sourceDir, x))
+
+ /** Nothing to do. */
+ if (includedFiles.isEmpty && argfile.isEmpty)
+ return
+
+ if (includedFiles.nonEmpty)
+ log("Compiling %d file%s to %s".format(includedFiles.size, plural(includedFiles.size), destinationDir))
+
+ argfile foreach (x => log("Using argfile file: @" + x))
+
+ val java = new Java(this) // set this as owner
+ java setFork true
+ // using 'setLine' creates multiple arguments out of a space-separated string
+ jvmArgs foreach (java.createJvmarg() setLine _)
+ timeout foreach (java setTimeout _)
+
+ java setClasspath compilerPath
+ java setClassname MainClass
+
+ // dump the arguments to a file and do "java @file"
+ val tempArgFile = io.File.makeTemp("scalacfork")
+ val tokens = settings.toArgs ++ (includedFiles map (_.getPath))
+ tempArgFile writeAll List(tokens mkString " ")
+
+ val paths = List(Some(tempArgFile.toAbsolute.path), argfile).flatten map (_.toString)
+ paths foreach (p => java.createArg() setValue ("@"+ p))
+
+ val debugString = paths map (x => " (@ = '%s')".format(io.File(x).slurp())) mkString ""
+ log(java.getCommandLine.getCommandline.mkString("", " ", debugString), Project.MSG_VERBOSE)
+
+ val res = java.executeJava()
+ if (failOnError && res != 0)
+ error("Compilation failed because of an internal compiler error;"+
+ " see the error output for details.")
}
}
diff --git a/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala b/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala
index 72f091cecc..6526f67254 100644
--- a/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala
+++ b/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala
@@ -84,4 +84,6 @@ trait TaskArgs { this: Task =>
protected var sourcePath: Option[Path] = None
protected var compilerPath: Option[Path] = None
protected var destinationDir: Option[File] = None
+
+ def isMSIL = compTarget exists (_ == "msil")
}