From fadb306fdf3d37284fd29c50aa3956cabe79480d Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 26 Sep 2012 11:36:01 -0700 Subject: PluginComponent contributes description to -Xshow-phases. In Global, SubComponent is called a phase descriptor, but it doesn't actually have a description. (Phase itself does.) This fix adds a description to PluginComponent so that plugins can describe what they do in -Xshow-phases. Elliptical descriptions Exploded archives Plugged-in partest Roundup at the Little h! --- .../scala/tools/partest/nest/CompileManager.scala | 43 +++++++++++++++++----- .../tools/partest/nest/ReflectiveRunner.scala | 3 ++ .../scala/tools/partest/nest/RunnerManager.scala | 17 +++++---- 3 files changed, 45 insertions(+), 18 deletions(-) (limited to 'src/partest') diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala index 3f005d143e..9a48c5ce2b 100644 --- a/src/partest/scala/tools/partest/nest/CompileManager.scala +++ b/src/partest/scala/tools/partest/nest/CompileManager.scala @@ -9,7 +9,7 @@ package scala.tools.partest package nest import scala.tools.nsc.{ Global, Settings, CompilerCommand, FatalError, io } -import scala.tools.nsc.io.{ File => SFile } +import scala.reflect.io.{ Directory, File => SFile, FileOperationException } import scala.tools.nsc.interactive.RangePositions import scala.tools.nsc.reporters.{ Reporter, ConsoleReporter } import scala.tools.nsc.util.{ ClassPath, FakePos } @@ -70,10 +70,27 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { s } - private def updatePluginPath(options: String): String = { - def absolutize(path: String) = Path(path) match { + implicit class Copier(f: SFile) { + // But what if f is bigger than CHUNK?! + def copyTo(dest: Path) { + dest.toFile writeAll f.slurp + } + } + + // plugin path can be relative to test root, or cwd is out + private def updatePluginPath(options: String, out: Option[File], srcdir: Directory): String = { + val dir = fileManager.testRootDir + def pathOrCwd(p: String) = + if (p == "." && out.isDefined) { + val plugxml = "scalac-plugin.xml" + val pout = Path(out.get) + val pd = (srcdir / plugxml).toFile + if (pd.exists) pd copyTo (pout / plugxml) + pout + } else Path(p) + def absolutize(path: String) = pathOrCwd(path) match { case x if x.isAbsolute => x.path - case x => (fileManager.testRootDir / x).toAbsolute.path + case x => (dir / x).toAbsolute.path } val (opt1, opt2) = (options split "\\s").toList partition (_ startsWith "-Xplugin:") @@ -90,17 +107,21 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { } val logWriter = new FileWriter(log) + // this api has no notion of srcdir, so fake it + val fstFile = SFile(files(0)) + val srcdir = fstFile.parent + // check whether there is a ".flags" file + def convertFlags(f: SFile) = updatePluginPath(f.slurp(), out, srcdir) val logFile = basename(log.getName) val flagsFileName = "%s.flags" format (logFile.substring(0, logFile.lastIndexOf("-"))) - val argString = (io.File(log).parent / flagsFileName) ifFile (x => updatePluginPath(x.slurp())) getOrElse "" + val argString = (SFile(log).parent / flagsFileName) ifFile (convertFlags) getOrElse "" // slurp local flags (e.g., "A_1.flags") - val fstFile = SFile(files(0)) def isInGroup(num: Int) = fstFile.stripExtension endsWith ("_" + num) val inGroup = (1 to 9) flatMap (group => if (isInGroup(group)) List(group) else List()) val localFlagsList = if (inGroup.nonEmpty) { - val localArgString = (fstFile.parent / (fstFile.stripExtension + ".flags")) ifFile (x => updatePluginPath(x.slurp())) getOrElse "" + val localArgString = (srcdir / (fstFile.stripExtension + ".flags")) ifFile (convertFlags) getOrElse "" localArgString.split(' ').toList.filter(_.length > 0) } else List() @@ -140,8 +161,10 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { NestUI.verbose("compiling "+toCompile) NestUI.verbose("with classpath: "+global.classPath.toString) NestUI.verbose("and java classpath: "+ propOrEmpty("java.class.path")) - try new global.Run compile toCompile - catch { + try { + if (command.shouldStopWithInfo) logWriter append (command getInfoMessage global) + else new global.Run compile toCompile + } catch { case FatalError(msg) => testRep.error(null, "fatal error: " + msg) return CompilerCrashed @@ -152,7 +175,7 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { } finally logWriter.close() - if (testRep.hasErrors) CompileFailed + if (testRep.hasErrors || command.shouldStopWithInfo) CompileFailed else CompileSuccess } } diff --git a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala index d3a40718c6..3446dd0f72 100644 --- a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala +++ b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala @@ -81,6 +81,9 @@ class ReflectiveRunner { val newClasspath = ClassPath.join(paths: _*) setProp("java.class.path", newClasspath) + + // don't let partest find pluginsdir; in ant build, standard plugin has dedicated test suite + //setProp("scala.home", latestLibFile.parent.parent.path) setProp("scala.home", "") if (isPartestDebug) diff --git a/src/partest/scala/tools/partest/nest/RunnerManager.scala b/src/partest/scala/tools/partest/nest/RunnerManager.scala index f2ce19a950..fbef97dab4 100644 --- a/src/partest/scala/tools/partest/nest/RunnerManager.scala +++ b/src/partest/scala/tools/partest/nest/RunnerManager.scala @@ -344,21 +344,22 @@ class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunP * compiler expects and how to implement them. (see SI-1240 for the full story) * * In practice, this happens in 3 steps: - * STEP1: feed all the files to scalac - * it will parse java files and obtain their expected signatures and generate bytecode for scala files - * STEP2: feed the java files to javac - * it will generate the bytecode for the java files and link to the scalac-generated bytecode for scala - * STEP3: only if there are both scala and java files, recompile the scala sources so they link to the correct + * STEP1: Feed all the files to scalac if there are also non-Scala sources. + * It will parse java files and obtain their expected signatures and generate bytecode for scala files + * STEP2: Feed the java files to javac if there are any. + * It will generate the bytecode for the java files and link to the scalac-generated bytecode for scala + * STEP3: (Re-)compile the scala sources so they link to the correct * java signatures, in case the signatures deduced by scalac from the source files were wrong. Since the * bytecode for java is already in place, we only feed the scala files to scalac so it will take the - * java signatures from the existing javac-generated bytecode + * java signatures from the existing javac-generated bytecode. + * Note that no artifacts are deleted before this step. */ List(1, 2, 3).foldLeft(CompileSuccess: CompilationOutcome) { - case (CompileSuccess, 1) if scalaFiles.nonEmpty => + case (CompileSuccess, 1) if scalaFiles.nonEmpty && javaFiles.nonEmpty => compileMgr.attemptCompile(Some(outDir), allFiles, kind, logFile) case (CompileSuccess, 2) if javaFiles.nonEmpty => javac(outDir, javaFiles, logFile) - case (CompileSuccess, 3) if scalaFiles.nonEmpty && javaFiles.nonEmpty => + case (CompileSuccess, 3) if scalaFiles.nonEmpty => // TODO: Do we actually need this? SI-1240 is known to require this, but we don't know if other tests // require it: https://groups.google.com/forum/?fromgroups#!topic/scala-internals/rFDKAcOKciU compileMgr.attemptCompile(Some(outDir), scalaFiles, kind, logFile) -- cgit v1.2.3