attempt to fix reopened SI-5196
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@26073 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
b11147e5d9
commit
4f3d4f91c4
|
|
@ -8,10 +8,14 @@
|
|||
|
||||
package scala.tools.ant
|
||||
|
||||
import org.apache.tools.ant.Project
|
||||
import org.apache.tools.ant.{AntClassLoader, Project}
|
||||
import org.apache.tools.ant.taskdefs.Java
|
||||
import org.apache.tools.ant.types.Path
|
||||
|
||||
import scala.tools.nsc.Settings
|
||||
import scala.tools.nsc.io.File
|
||||
import scala.tools.nsc.settings.FscSettings
|
||||
import scala.tools.nsc.util.ScalaClassLoader
|
||||
|
||||
/** An Ant task to compile with the fast Scala compiler (`fsc`).
|
||||
*
|
||||
|
|
@ -92,12 +96,6 @@ class FastScalac extends Scalac {
|
|||
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*/
|
||||
|
|
@ -111,9 +109,9 @@ class FastScalac extends Scalac {
|
|||
List(
|
||||
/*scalac*/
|
||||
s.debuginfo, s.target
|
||||
) map (x => "%s:%s".format(x.name, x.value))
|
||||
) filter (x => x.value != x.default) map (x => "%s:%s".format(x.name, x.value))
|
||||
|
||||
val booleanSettings =
|
||||
val booleanSettings =
|
||||
List(
|
||||
/*scalac*/
|
||||
s.debug, s.deprecation, s.explaintypes, s.nospecialization, s.nowarn,
|
||||
|
|
@ -134,20 +132,61 @@ class FastScalac extends Scalac {
|
|||
else List("%s:%s".format(s.name, s.value.mkString(",")))
|
||||
}
|
||||
|
||||
val cmdOptions =
|
||||
prefixSettings ::: stringSettings ::: choiceSettings ::: booleanSettings ::: intSettings ::: phaseSetting
|
||||
val fscOptions =
|
||||
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.")
|
||||
val java = new Java(this)
|
||||
java setFork true
|
||||
// use same default memory options as in fsc script
|
||||
java.createJvmarg() setValue "-Xmx256M"
|
||||
java.createJvmarg() setValue "-Xms32M"
|
||||
val scalacPath: Path = {
|
||||
val path = new Path(getProject)
|
||||
if (compilerPath.isDefined) path add compilerPath.get
|
||||
else getClass.getClassLoader match {
|
||||
case cl: AntClassLoader =>
|
||||
path add new Path(getProject, cl.getClasspath)
|
||||
case _ =>
|
||||
buildError("Compilation failed because of an internal compiler error;"+
|
||||
" see the error output for details.")
|
||||
}
|
||||
path
|
||||
}
|
||||
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.")
|
||||
java.createJvmarg() setValue ("-Xbootclasspath/a:"+scalacPath)
|
||||
s.jvmargs.value foreach (java.createJvmarg() setValue _)
|
||||
|
||||
val scalaHome: String = try {
|
||||
val url = ScalaClassLoader.originOfClass(classOf[FastScalac]).get
|
||||
File(url.getFile).jfile.getParentFile.getParentFile getAbsolutePath
|
||||
} catch {
|
||||
case _ =>
|
||||
buildError("Compilation failed because of an internal compiler error;"+
|
||||
" couldn't determine value for -Dscala.home=<value>")
|
||||
}
|
||||
java.createJvmarg() setValue "-Dscala.usejavacp=true"
|
||||
java.createJvmarg() setValue ("-Dscala.home="+scalaHome)
|
||||
s.defines.value foreach (java.createJvmarg() setValue _)
|
||||
|
||||
java setClassname "scala.tools.nsc.MainGenericRunner"
|
||||
java.createArg() setValue "scala.tools.nsc.CompileClient"
|
||||
|
||||
// Encode scalac/javac args for use in a file to be read back via "@file.txt"
|
||||
def encodeScalacArgsFile(t: Traversable[String]) = t map { s =>
|
||||
if(s.find(c => c <= ' ' || "\"'\\".contains(c)).isDefined)
|
||||
"\"" + s.flatMap(c => (if(c == '"' || c == '\\') "\\" else "") + c ) + "\""
|
||||
else s
|
||||
} mkString "\n"
|
||||
|
||||
// dump the arguments to a file and do "java @file"
|
||||
val tempArgFile = File.makeTemp("fastscalac")
|
||||
val tokens = fscOptions ++ (sourceFiles map (_.getPath))
|
||||
tempArgFile writeAll encodeScalacArgsFile(tokens)
|
||||
|
||||
val paths = List(Some(tempArgFile.toAbsolute.path), argfile).flatten map (_.toString)
|
||||
val res = execWithArgFiles(java, paths)
|
||||
|
||||
if (failonerror && res != 0)
|
||||
buildError("Compilation failed because of an internal compiler error;"+
|
||||
" see the error output for details.")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
|
|||
* - `bootclasspathref`,
|
||||
* - `extdirs`,
|
||||
* - `extdirsref`,
|
||||
* - `argfile`,
|
||||
* - `dependencyfile`,
|
||||
* - `encoding`,
|
||||
* - `target`,
|
||||
|
|
@ -126,8 +127,9 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
|
|||
/** The external extensions path to use for this compilation. */
|
||||
protected var extdirs: Option[Path] = None
|
||||
|
||||
protected var argfile: Option[File] = None
|
||||
/** The dependency tracking file. */
|
||||
protected var dependencyfile: Option[String] = None
|
||||
protected var dependencyfile: Option[File] = None
|
||||
/** The character encoding of the files to compile. */
|
||||
protected var encoding: Option[String] = None
|
||||
|
||||
|
|
@ -229,7 +231,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
|
|||
}
|
||||
/** Sets the `compilerPath` attribute. Used by [[http://ant.apache.org Ant]].
|
||||
* @param input The value of `compilerPath`. */
|
||||
def setCompilerPath(input : Path) {
|
||||
def setCompilerPath(input: Path) {
|
||||
compilerPath = setOrAppend(compilerPath, input)
|
||||
}
|
||||
|
||||
|
|
@ -299,9 +301,15 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
|
|||
def setExtdirsref(input: Reference) =
|
||||
createExtdirs().setRefid(input)
|
||||
|
||||
/** Sets the `argfile` attribute. Used by [[http://ant.apache.org Ant]].
|
||||
* @param input The value of `argfile`. */
|
||||
def setArgfile(input: File) {
|
||||
argfile = Some(input)
|
||||
}
|
||||
|
||||
/** Sets the `dependencyfile` attribute. Used by [[http://ant.apache.org Ant]].
|
||||
* @param input The value of `dependencyfile`. */
|
||||
def setDependencyfile(input: String) {
|
||||
def setDependencyfile(input: File) {
|
||||
dependencyfile = Some(input)
|
||||
}
|
||||
|
||||
|
|
@ -584,7 +592,8 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
|
|||
if (!bootclasspath.isEmpty)
|
||||
settings.bootclasspath.value = asString(getBootclasspath)
|
||||
if (!extdirs.isEmpty) settings.extdirs.value = asString(getExtdirs)
|
||||
if (!dependencyfile.isEmpty) settings.dependencyfile.value = dependencyfile.get
|
||||
if (!dependencyfile.isEmpty)
|
||||
settings.dependencyfile.value = asString(dependencyfile.get)
|
||||
if (!encoding.isEmpty) settings.encoding.value = encoding.get
|
||||
if (!backend.isEmpty) settings.target.value = backend.get
|
||||
if (!logging.isEmpty && logging.get == "verbose")
|
||||
|
|
|
|||
Loading…
Reference in New Issue