From fb248a8ec1bb829d706ad08ac73550513f867b68 Mon Sep 17 00:00:00 2001 From: Gilles Dubochet Date: Thu, 10 May 2007 13:38:25 +0000 Subject: [#1095] Changed Scalac Ant task to use default ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#1095] Changed Scalac Ant task to use default settings from “nsc.Settings” instead of its own. This means that Scala will now be built with “vars” debug symbols. --- src/compiler/scala/tools/ant/Scalac.scala | 217 ++++++++++-------------------- 1 file changed, 69 insertions(+), 148 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala index 069e274239..64d7280455 100644 --- a/src/compiler/scala/tools/ant/Scalac.scala +++ b/src/compiler/scala/tools/ant/Scalac.scala @@ -61,9 +61,7 @@ import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} *
  • bootclasspath,
  • *
  • extdirs.
  • * - * - * @author Gilles Dubochet, Stephane Micheloud - */ + * @author Gilles Dubochet, Stephane Micheloud */ class Scalac extends MatchingTask { /** The unique Ant file utilities instance to use in this task. */ @@ -98,8 +96,7 @@ class Scalac extends MatchingTask { } /** Defines valid values for the deprecation and - * unchecked properties. - */ + * unchecked properties. */ object Flag extends PermissibleValue { val values = List("yes", "no", "on", "off") } @@ -133,24 +130,23 @@ class Scalac extends MatchingTask { private var logPhase: List[String] = Nil /** Whether to use implicit predefined values or not. */ - private var usepredefs: Boolean = true + private var usepredefs: Option[Boolean] = None /** Instruct the compiler to generate debugging information */ - private var debugInfo: String = "line" + private var debugInfo: Option[String] = None /** Instruct the compiler to use additional parameters */ private var addParams: String = "" /** Instruct the compiler to generate deprecation information. */ - private var deprecation: Boolean = false + private var deprecation: Option[Boolean] = None /** Instruct the compiler to generate unchecked information. */ - private var unchecked: Boolean = false + private var unchecked: Option[Boolean] = None // Name of the output assembly (only relevant with -target:msil) - private var assemname: String = "" + private var assemname: Option[String] = None // List of assemblies referenced by the program (only relevant with -target:msil) - private var assemrefs: String = "." + private var assemrefs: Option[String] = None /** Whether the compiler is being debuged. Prints more information in case - * in case of failure. - */ + * in case of failure. */ private var scalacDebugging: Boolean = false /*============================================================================*\ @@ -158,97 +154,74 @@ class Scalac extends MatchingTask { \*============================================================================*/ /** Sets the srcdir attribute. Used by Ant. - * - * @param input The value of origin. - */ + * @param input The value of origin. */ def setSrcdir(input: Path) = if (origin.isEmpty) origin = Some(input) else origin.get.append(input) /** Sets the origin as a nested src Ant parameter. - * - * @return An origin path to be configured. - */ + * @return An origin path to be configured. */ def createSrc(): Path = { if (origin.isEmpty) origin = Some(new Path(getProject())) origin.get.createPath() } /** Sets the origin as an external reference Ant parameter. - * - * @param input A reference to an origin path. - */ + * @param input A reference to an origin path. */ def setSrcref(input: Reference) = createSrc().setRefid(input) /** Sets the destdir attribute. Used by Ant. - * - * @param input The value of destination. - */ + * @param input The value of destination. */ def setDestdir(input: File) = destination = Some(input) /** Sets the classpath attribute. Used by Ant. - * - * @param input The value of classpath. - */ + * @param input The value of classpath. */ def setClasspath(input: Path) = if (classpath.isEmpty) classpath = Some(input) else classpath.get.append(input) /** Sets the classpath as a nested classpath Ant parameter. - * - * @return A class path to be configured. - */ + * @return A class path to be configured. */ def createClasspath(): Path = { if (classpath.isEmpty) classpath = Some(new Path(getProject())) classpath.get.createPath() } /** Sets the classpath as an external reference Ant parameter. - * - * @param input A reference to a class path. - */ + * @param input A reference to a class path. */ def setClasspathref(input: Reference) = createClasspath().setRefid(input) /** Sets the sourcepath attribute. Used by Ant. - * - * @param input The value of sourcepath. - */ + * @param input The value of sourcepath. */ def setSourcepath(input: Path) = if (sourcepath.isEmpty) sourcepath = Some(input) else sourcepath.get.append(input) /** Sets the sourcepath as a nested sourcepath Ant parameter. - * - * @return A source path to be configured. - */ + * @return A source path to be configured. */ def createSourcepath(): Path = { if (sourcepath.isEmpty) sourcepath = Some(new Path(getProject())) sourcepath.get.createPath() } /** Sets the sourcepath as an external reference Ant parameter. - * - * @param input A reference to a source path. - */ + * @param input A reference to a source path. */ def setSourcepathref(input: Reference) = createSourcepath().setRefid(input) /** Sets the boot classpath attribute. Used by Ant. * - * @param input The value of bootclasspath. - */ + * @param input The value of bootclasspath. */ def setBootclasspath(input: Path) = if (bootclasspath.isEmpty) bootclasspath = Some(input) else bootclasspath.get.append(input) /** Sets the bootclasspath as a nested sourcepath Ant * parameter. - * - * @return A source path to be configured. - */ + * @return A source path to be configured. */ def createBootclasspath(): Path = { if (bootclasspath.isEmpty) bootclasspath = Some(new Path(getProject())) bootclasspath.get.createPath() @@ -256,70 +229,52 @@ class Scalac extends MatchingTask { /** Sets the bootclasspath as an external reference Ant * parameter. - * - * @param input A reference to a source path. - */ + * @param input A reference to a source path. */ def setBootclasspathref(input: Reference) = createBootclasspath().setRefid(input) /** Sets the external extensions path attribute. Used by Ant. - * - * @param input The value of extdirs. - */ + * @param input The value of extdirs. */ def setExtdirs(input: Path) = if (extdirs.isEmpty) extdirs = Some(input) else extdirs.get.append(input) /** Sets the extdirs as a nested sourcepath Ant parameter. - * - * @return An extensions path to be configured. - */ + * @return An extensions path to be configured. */ def createExtdirs(): Path = { if (extdirs.isEmpty) extdirs = Some(new Path(getProject())) extdirs.get.createPath() } /** Sets the extdirs as an external reference Ant parameter. - * - * @param input A reference to an extensions path. - */ + * @param input A reference to an extensions path. */ def setExtdirsref(input: Reference) = createExtdirs().setRefid(input) /** Sets the encoding attribute. Used by Ant. - * - * @param input The value of encoding. - */ + * @param input The value of encoding. */ def setEncoding(input: String): Unit = encoding = Some(input) /** Sets the target attribute. Used by Ant. - * - * @param input The value for target. - */ + * @param input The value for target. */ def setTarget(input: String): Unit = if (Target.isPermissible(input)) backend = Some(input) else error("Unknown target '" + input + "'") /** Sets the force attribute. Used by Ant. - * - * @param input The value for force. - */ + * @param input The value for force. */ def setForce(input: Boolean): Unit = force = input /** Sets the logging level attribute. Used by Ant. - * - * @param input The value for logging. - */ + * @param input The value for logging. */ def setLogging(input: String) = if (LoggingLevel.isPermissible(input)) logging = Some(input) else error("Logging level '" + input + "' does not exist.") /** Sets the logphase attribute. Used by Ant. - * - * @param input The value for logPhase. - */ + * @param input The value for logPhase. */ def setLogPhase(input: String) = { logPhase = List.fromArray(input.split(",")).flatMap { s: String => val st = s.trim() @@ -333,58 +288,46 @@ class Scalac extends MatchingTask { } /** Sets the usepredefs attribute. Used by Ant. - * - * @param input The value for usepredefs. - */ + * @param input The value for usepredefs. */ def setUsepredefs(input: Boolean): Unit = - usepredefs = input + usepredefs = Some(input) /** Set the debug info attribute. - * - * @param input The value for debug. - */ + * @param input The value for debug. */ def setDebuginfo(input: String): Unit = - debugInfo = input + debugInfo = Some(input) /** Set the addparams info attribute. - * - * @param input The value for addparams. - */ + * @param input The value for addparams. */ def setAddparams(input: String): Unit = addParams = input /** Set the deprecation info attribute. - * - * @param input One of the flags yes/no or on/off. - */ + * @param input One of the flags yes/no or on/off. */ def setDeprecation(input: String): Unit = if (Flag.isPermissible(input)) - deprecation = "yes".equals(input) || "on".equals(input) + deprecation = Some("yes" == input || "on" == input) else error("Unknown deprecation flag '" + input + "'") /** Set the unchecked info attribute. - * - * @param input One of the flags yes/no or on/off. - */ + * @param input One of the flags yes/no or on/off. */ def setUnchecked(input: String): Unit = if (Flag.isPermissible(input)) - unchecked = "yes".equals(input) || "on".equals(input) + unchecked = Some("yes" == input || "on" == input) else error("Unknown unchecked flag '" + input + "'") /** Set the scalacdebugging info attribute. - * - * @param input The specified flag - */ + * @param input The specified flag */ def setScalacdebugging(input: Boolean): Unit = scalacDebugging = input def setAssemname(input: String): Unit = - assemname = input + assemname = Some(input) def setAssemrefs(input: String): Unit = - assemrefs = input + assemrefs = Some(input) /*============================================================================*\ ** Properties getters ** @@ -392,54 +335,42 @@ class Scalac extends MatchingTask { /** Gets the value of the classpath attribute in a * Scala-friendly form. - * - * @return The class path as a list of files. - */ + * @return The class path as a list of files. */ private def getClasspath: List[File] = if (classpath.isEmpty) error("Member 'classpath' is empty.") else List.fromArray(classpath.get.list()).map(nameToFile) /** Gets the value of the origin attribute in a - * Scala-friendly form. - * - * @return The origin path as a list of files. - */ + * Scala-friendly form. + * @return The origin path as a list of files. */ private def getOrigin: List[File] = if (origin.isEmpty) error("Member 'origin' is empty.") else List.fromArray(origin.get.list()).map(nameToFile) /** Gets the value of the destination attribute in a * Scala-friendly form. - * - * @return The destination as a file. - */ + * @return The destination as a file. */ private def getDestination: File = if (destination.isEmpty) error("Member 'destination' is empty.") else existing(getProject().resolveFile(destination.get.toString())) /** Gets the value of the sourcepath attribute in a * Scala-friendly form. - * - * @return The source path as a list of files. - */ + * @return The source path as a list of files. */ private def getSourcepath: List[File] = if (sourcepath.isEmpty) error("Member 'sourcepath' is empty.") else List.fromArray(sourcepath.get.list()).map(nameToFile) /** Gets the value of the bootclasspath attribute in a * Scala-friendly form. - * - * @return The boot class path as a list of files. - */ + * @return The boot class path as a list of files. */ private def getBootclasspath: List[File] = if (bootclasspath.isEmpty) error("Member 'bootclasspath' is empty.") else List.fromArray(bootclasspath.get.list()).map(nameToFile) /** Gets the value of the extdirs attribute in a * Scala-friendly form. - * - * @return The extensions path as a list of files. - */ + * @return The extensions path as a list of files. */ private def getExtdirs: List[File] = if (extdirs.isEmpty) error("Member 'extdirs' is empty.") else List.fromArray(extdirs.get.list()).map(nameToFile) @@ -449,37 +380,30 @@ class Scalac extends MatchingTask { \*============================================================================*/ /** This is forwarding method to circumvent bug #281 in Scala 2. Remove when - * bug has been corrected. - */ + * bug has been corrected. */ override protected def getDirectoryScanner(baseDir: File) = super.getDirectoryScanner(baseDir) /** Transforms a string name into a file relative to the provided base * directory. - * * @param base A file pointing to the location relative to which the name * will be resolved. * @param name A relative or absolute path to the file as a string. - * @return A file created from the name and the base file. - */ + * @return A file created from the name and the base file. */ private def nameToFile(base: File)(name: String): File = existing(fileUtils.resolveFile(base, name)) /** Transforms a string name into a file relative to the build root * directory. - * * @param name A relative or absolute path to the file as a string. - * @return A file created from the name. - */ + * @return A file created from the name. */ private def nameToFile(name: String): File = existing(getProject().resolveFile(name)) /** Tests if a file exists and prints a warning in case it doesn't. Always * returns the file, even if it doesn't exist. - * * @param file A file to test for existance. - * @return The same file. - */ + * @return The same file. */ private def existing(file: File): File = { if (!file.exists()) log("Element '" + file.toString() + "' does not exist.", @@ -488,27 +412,21 @@ class Scalac extends MatchingTask { } /** Transforms a path into a Scalac-readable string. - * * @param path A path to convert. - * @return A string-representation of the path like a.jar:b.jar. - */ + * @return A string-representation of the path like a.jar:b.jar. */ private def asString(path: List[File]): String = - path.map(asString).mkString("", File.pathSeparator, "") + path.map(asString).mkString(File.pathSeparator) /** Transforms a file into a Scalac-readable string. - * * @param path A file to convert. - * @return A string-representation of the file like /x/k/a.scala. - */ + * @return A string-representation of the file like /x/k/a.scala. */ private def asString(file: File): String = file.getAbsolutePath() /** Generates a build error. Error location will be the current task in the * ant file. - * * @param message A message describing the error. - * @throws BuildException A build error exception thrown in every case. - */ + * @throws BuildException A build error exception thrown in every case. */ private def error(message: String): Nothing = throw new BuildException(message, getLocation()) @@ -563,7 +481,8 @@ class Scalac extends MatchingTask { list } - } yield { + } + yield { log(originFile.toString(), Project.MSG_DEBUG) nameToFile(originDir)(originFile) } @@ -590,13 +509,13 @@ class Scalac extends MatchingTask { settings.debug.value = true } if (!logPhase.isEmpty) settings.log.value = logPhase - settings.nopredefs.value = !usepredefs - settings.debuginfo.value = debugInfo - settings.deprecation.value = deprecation - settings.unchecked.value = unchecked + if (!usepredefs.isEmpty) settings.nopredefs.value = !usepredefs.get + if (!debugInfo.isEmpty) settings.debuginfo.value = debugInfo.get + if (!deprecation.isEmpty) settings.deprecation.value = deprecation.get + if (!unchecked.isEmpty) settings.unchecked.value = unchecked.get - settings.assemname.value = assemname - settings.assemrefs.value = assemrefs + if (!assemname.isEmpty) settings.assemname.value = assemname.get + if (!assemrefs.isEmpty) settings.assemrefs.value = assemrefs.get log("Scalac params = '" + addParams + "'", Project.MSG_DEBUG) var args = @@ -607,7 +526,8 @@ class Scalac extends MatchingTask { if (args.head startsWith "-") { for (setting <- settings.allSettings) args = setting.tryToSet(args); - } else error("Parameter '" + args.head + "' does not start with '-'.") + } + else error("Parameter '" + args.head + "' does not start with '-'.") if (argsBuf eq args) error("Parameter '" + args.head + "' is not recognised by Scalac.") } @@ -623,7 +543,8 @@ class Scalac extends MatchingTask { val compiler = new Global(settings, reporter) try { (new compiler.Run).compile(sourceFiles.map (.toString())) - } catch { + } + catch { case exception: Throwable if (exception.getMessage ne null) => exception.printStackTrace() error("Compile failed because of an internal compiler error (" + -- cgit v1.2.3