From 60e50904a39315950e186eefc8d12b1f30978d15 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 7 Mar 2010 06:02:38 +0000 Subject: Still working my way through all the classpath ... Still working my way through all the classpath manipulations in partest. No review. --- .../scala/tools/partest/nest/CompileManager.scala | 74 ++++++++-------------- .../tools/partest/nest/ConsoleFileManager.scala | 3 - .../scala/tools/partest/nest/TestFile.scala | 59 +++++++---------- src/partest/scala/tools/partest/package.scala | 4 ++ 4 files changed, 56 insertions(+), 84 deletions(-) diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala index 9e58cfbf36..5f564f7324 100644 --- a/src/partest/scala/tools/partest/nest/CompileManager.scala +++ b/src/partest/scala/tools/partest/nest/CompileManager.scala @@ -8,10 +8,11 @@ package scala.tools.partest package nest -import scala.tools.nsc.{ Global, Settings, CompilerCommand, FatalError } -import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} +import scala.tools.nsc.{ Global, Settings, CompilerCommand, FatalError, io } +import scala.tools.nsc.reporters.{ Reporter, ConsoleReporter } import scala.tools.nsc.util.ClassPath import scala.tools.util.PathResolver +import io.Path import java.io.{ File, BufferedReader, PrintWriter, FileReader, Writer, FileWriter, StringWriter } import File.pathSeparator @@ -40,14 +41,15 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { newGlobal(settings, rep) } - def newSettings = { + def newSettings(out: Option[String]) = { val settings = new TestSettings(fileManager) settings.deprecation.value = true settings.nowarnings.value = false - settings.encoding.value = "iso-8859-1" - settings.classpath.value += (pathSeparator + fileManager.LATEST_LIB) - // XXX - // settings.javabootAppend.value = fileManager.LATEST_LIB + settings.encoding.value = "ISO-8859-1" // XXX why? + + val classpathElements = settings.classpath.value :: fileManager.LATEST_LIB :: out.toList + settings.classpath.value = ClassPath.join(classpathElements: _*) + out foreach (settings.outdir.value = _) settings } @@ -56,50 +58,36 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { new ExtConsoleReporter(sett, Console.in, new PrintWriter(writer)) private def updatePluginPath(options: String): String = { - val (opt1, opt2) = - (options split "\\s").toList partition (_ startsWith "-Xplugin:") - (opt2 mkString " ")+( - if (opt1.isEmpty) "" - else { - def absolutize(path: String): List[String] = { - val args = (path substring 9 split pathSeparator).toList - val plugins = args map (arg => - if (new File(arg).isAbsolute) arg - else fileManager.testRootPath+File.separator+arg - ) - plugins - } - " -Xplugin:"+((opt1 flatMap absolutize) mkString pathSeparator) - } - ) + val dir = fileManager.testRootDir + def absolutize(path: String) = Path(path) match { + case x if x.isAbsolute => x.path + case x => (fileManager.testRootDir / x).toAbsolute.path + } + + val (opt1, opt2) = (options split "\\s").toList partition (_ startsWith "-Xplugin:") + val plugins = opt1 map (_ stripPrefix "-Xplugin:") flatMap (_ split pathSeparator) map absolutize + val pluginOption = if (opt1.isEmpty) Nil else List("-Xplugin:" + (plugins mkString pathSeparator)) + + (opt2 ::: pluginOption) mkString " " } def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean = { - val testSettings = newSettings + val testSettings = newSettings(out map (_.getAbsolutePath)) val logWriter = new FileWriter(log) // check whether there is a ".flags" file - val testBase = { - val logBase = basename(log.getName) - logBase.substring(0, logBase.length-4) - } - val argsFile = new File(log.getParentFile, testBase+".flags") - val argString = if (argsFile.exists) { - val fileReader = new FileReader(argsFile) - val reader = new BufferedReader(fileReader) - val options = updatePluginPath(reader.readLine()) - reader.close() - options - } else "" + val flagsFileName = "%s.flags" format (basename(log.getName) dropRight 4) // 4 is "-run" or similar + val argString = (io.File(log).parent / flagsFileName) ifFile (x => updatePluginPath(x.slurp())) getOrElse "" val allOpts = fileManager.SCALAC_OPTS+" "+argString + val args = (allOpts split "\\s").toList + NestUI.verbose("scalac options: "+allOpts) - val args = (allOpts split "\\s").toList val command = new CompilerCommand(args, testSettings, _ => (), false) val global = newGlobal(command.settings, logWriter) val testRep: ExtConsoleReporter = global.reporter.asInstanceOf[ExtConsoleReporter] - val testFileFn: (File, FileManager, Boolean) => TestFile = kind match { + val testFileFn: (File, FileManager) => TestFile = kind match { case "pos" => PosTestFile.apply case "neg" => NegTestFile.apply case "run" => RunTestFile.apply @@ -108,14 +96,8 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { case "scalap" => ScalapTestFile.apply case "scalacheck" => ScalaCheckTestFile.apply } - val test: TestFile = testFileFn(files.head, fileManager, out.isEmpty) - test defineSettings command.settings - - out map { outDir => - command.settings.outdir.value = outDir.getAbsolutePath - command.settings.classpath.value += (pathSeparator + outDir.getAbsolutePath) - } - + val test: TestFile = testFileFn(files.head, fileManager) + test.defineSettings(command.settings, out.isEmpty) val toCompile = files map (_.getPath) try { diff --git a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala index e2d28abba8..4fa20c4c13 100644 --- a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala +++ b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala @@ -23,9 +23,6 @@ import RunnerUtils._ class ConsoleFileManager extends FileManager { - implicit private def temporaryPath2File(x: Path): File = x.jfile - implicit private def temporaryFile2Path(x: File): Path = Path(x) - var testBuild: Option[String] = PartestDefaults.testBuild def testBuildFile = testBuild map (testParent / _) diff --git a/src/partest/scala/tools/partest/nest/TestFile.scala b/src/partest/scala/tools/partest/nest/TestFile.scala index 9eb6f63351..397ae4ba04 100644 --- a/src/partest/scala/tools/partest/nest/TestFile.scala +++ b/src/partest/scala/tools/partest/nest/TestFile.scala @@ -8,53 +8,42 @@ package scala.tools.partest package nest -import java.io.File +import java.io.{ File => JFile } import scala.tools.nsc.Settings -import scala.tools.nsc.io.{ Path, Directory } +import scala.tools.nsc.io._ abstract class TestFile(kind: String) { - def file: File + def file: JFile def fileManager: FileManager - def createOutDir: Boolean - val dir = file.getParentFile - val dirpath = dir.getAbsolutePath - val fileBase: String = basename(file.getName) - def objDir = fileBase + "-" + kind + ".obj" + val dir = file.toAbsolute.parent + val fileBase = file.stripExtension + lazy val objectDir = dir / "%s-%s.obj".format(fileBase, kind) createDirectory true + val flags: Option[String] = dir / "%s.flags".format(fileBase) ifFile { _.slurp().trim } - def defineSettings(settings: Settings) { - settings appendToClasspath dirpath + def setOutDirTo = objectDir - if (createOutDir) { - val d = (Path(dirpath) / objDir) createDirectory true - settings.outdir.value = d.toAbsolute.path - } - - // add additional flags found in 'testname.flags' - def flagsPath = Path(dir) / (fileBase + ".flags") - flagsPath ifFile { _.slurp().trim } foreach (settings processArgumentString _) + def defineSettings(settings: Settings, setOutDir: Boolean) = { + settings appendToClasspath dir.path + if (setOutDir) + settings.outdir.value = setOutDirTo.path + flags foreach (settings processArgumentString _) settings appendToClasspath fileManager.CLASSPATH } - override def toString(): String = kind+" "+file + override def toString(): String = "%s %s".format(kind, file) } -case class PosTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("pos") -case class NegTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("neg") -case class RunTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("run") -case class BuildManagerTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("bm") -case class ScalaCheckTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("scalacheck") -case class JvmTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("jvm") -case class ShootoutTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("shootout") { - override def defineSettings(settings: Settings) { - super.defineSettings(settings) - settings.outdir.value = file.getParent - } +case class PosTestFile(file: JFile, fileManager: FileManager) extends TestFile("pos") +case class NegTestFile(file: JFile, fileManager: FileManager) extends TestFile("neg") +case class RunTestFile(file: JFile, fileManager: FileManager) extends TestFile("run") +case class BuildManagerTestFile(file: JFile, fileManager: FileManager) extends TestFile("bm") +case class ScalaCheckTestFile(file: JFile, fileManager: FileManager) extends TestFile("scalacheck") +case class JvmTestFile(file: JFile, fileManager: FileManager) extends TestFile("jvm") +case class ShootoutTestFile(file: JFile, fileManager: FileManager) extends TestFile("shootout") { + override def setOutDirTo = file.parent } -case class ScalapTestFile(file: File, fileManager: FileManager, createOutDir: Boolean) extends TestFile("scalap") { - override def defineSettings(settings: Settings) { - super.defineSettings(settings) - settings.outdir.value = file.getParent - } +case class ScalapTestFile(file: JFile, fileManager: FileManager) extends TestFile("scalap") { + override def setOutDirTo = file.parent } diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala index f47aa4c8f1..e9eda6fb75 100644 --- a/src/partest/scala/tools/partest/package.scala +++ b/src/partest/scala/tools/partest/package.scala @@ -4,6 +4,7 @@ package scala.tools +import java.io.{ File => JFile } import nsc.io.{ Path, Process, Directory } import util.{ PathResolver } import nsc.Properties.{ propOrElse, propOrNone, propOrEmpty } @@ -11,6 +12,9 @@ import nsc.Properties.{ propOrElse, propOrNone, propOrEmpty } package object partest { import nest.NestUI + implicit private[partest] def temporaryPath2File(x: Path): JFile = x.jfile + implicit private[partest] def temporaryFile2Path(x: JFile): Path = Path(x) + def basename(name: String): String = Path(name).stripExtension def resultsToStatistics(results: Iterable[(_, Int)]): (Int, Int) = { val (files, failures) = results map (_._2 == 0) partition (_ == true) -- cgit v1.2.3