~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to src/partest/scala/tools/partest/nest/CompileManager.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* NEST (New Scala Test)
2
 
 * Copyright 2007-2011 LAMP/EPFL
 
2
 * Copyright 2007-2013 LAMP/EPFL
3
3
 * @author Philipp Haller
4
4
 */
5
5
 
9
9
package nest
10
10
 
11
11
import scala.tools.nsc.{ Global, Settings, CompilerCommand, FatalError, io }
 
12
import scala.tools.nsc.io.{ File => SFile }
 
13
import scala.tools.nsc.interactive.RangePositions
12
14
import scala.tools.nsc.reporters.{ Reporter, ConsoleReporter }
13
15
import scala.tools.nsc.util.{ ClassPath, FakePos }
 
16
import scala.tools.nsc.Properties.{ setProp, propOrEmpty }
14
17
import scala.tools.util.PathResolver
15
18
import io.Path
16
19
import java.io.{ File, BufferedReader, PrintWriter, FileReader, Writer, FileWriter, StringWriter }
17
20
import File.pathSeparator
18
21
 
 
22
sealed abstract class CompilationOutcome {
 
23
  def merge(other: CompilationOutcome): CompilationOutcome
 
24
  def isPositive = this eq CompileSuccess
 
25
  def isNegative = this eq CompileFailed
 
26
}
 
27
case object CompileSuccess extends CompilationOutcome {
 
28
  def merge(other: CompilationOutcome) = other
 
29
}
 
30
case object CompileFailed extends CompilationOutcome {
 
31
  def merge(other: CompilationOutcome) = if (other eq CompileSuccess) this else other
 
32
}
 
33
case object CompilerCrashed extends CompilationOutcome {
 
34
  def merge(other: CompilationOutcome) = this
 
35
}
 
36
 
19
37
class ExtConsoleReporter(settings: Settings, val writer: PrintWriter) extends ConsoleReporter(settings, Console.in, writer) {
20
38
  shortname = true
21
39
}
23
41
class TestSettings(cp: String, error: String => Unit) extends Settings(error) {
24
42
  def this(cp: String) = this(cp, _ => ())
25
43
 
26
 
  deprecation.value = true
27
44
  nowarnings.value  = false
28
 
  encoding.value    = "ISO-8859-1"
 
45
  encoding.value    = "UTF-8"
29
46
  classpath.value   = cp
30
47
}
31
48
 
32
49
abstract class SimpleCompiler {
33
 
  def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean
 
50
  def compile(out: Option[File], files: List[File], kind: String, log: File): CompilationOutcome
34
51
}
35
52
 
36
53
class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler {
37
54
  def newGlobal(settings: Settings, reporter: Reporter): Global =
38
 
    new Global(settings, reporter)
 
55
    if (settings.Yrangepos.value)
 
56
      new Global(settings, reporter) with RangePositions
 
57
    else
 
58
      new Global(settings, reporter)
39
59
 
40
60
  def newGlobal(settings: Settings, logWriter: FileWriter): Global =
41
61
    newGlobal(settings, new ExtConsoleReporter(settings, new PrintWriter(logWriter)))
63
83
    (opt2 ::: pluginOption) mkString " "
64
84
  }
65
85
 
66
 
  def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean = {
 
86
  def compile(out: Option[File], files: List[File], kind: String, log: File): CompilationOutcome = {
67
87
    val testSettings = out match {
68
88
      case Some(f)  => newSettings(f.getAbsolutePath)
69
89
      case _        => newSettings()
71
91
    val logWriter = new FileWriter(log)
72
92
 
73
93
    // check whether there is a ".flags" file
74
 
    val flagsFileName = "%s.flags" format (basename(log.getName) dropRight 4) // 4 is "-run" or similar
 
94
    val logFile = basename(log.getName)
 
95
    val flagsFileName = "%s.flags" format (logFile.substring(0, logFile.lastIndexOf("-")))
75
96
    val argString = (io.File(log).parent / flagsFileName) ifFile (x => updatePluginPath(x.slurp())) getOrElse ""
76
 
    val allOpts = fileManager.SCALAC_OPTS+" "+argString
77
 
    val args = (allOpts split "\\s").toList
 
97
 
 
98
    // slurp local flags (e.g., "A_1.flags")
 
99
    val fstFile = SFile(files(0))
 
100
    def isInGroup(num: Int) = fstFile.stripExtension endsWith ("_" + num)
 
101
    val inGroup = (1 to 9) flatMap (group => if (isInGroup(group)) List(group) else List())
 
102
    val localFlagsList = if (inGroup.nonEmpty) {
 
103
      val localArgString = (fstFile.parent / (fstFile.stripExtension + ".flags")) ifFile (x => updatePluginPath(x.slurp())) getOrElse ""
 
104
      localArgString.split(' ').toList.filter(_.length > 0)
 
105
    } else List()
 
106
 
 
107
    val allOpts = fileManager.SCALAC_OPTS.toList ::: argString.split(' ').toList.filter(_.length > 0) ::: localFlagsList
 
108
    val args = allOpts.toList
78
109
 
79
110
    NestUI.verbose("scalac options: "+allOpts)
80
111
 
91
122
      case "scalap"       => ScalapTestFile.apply
92
123
      case "scalacheck"   => ScalaCheckTestFile.apply
93
124
      case "specialized"  => SpecializedTestFile.apply
 
125
      case "instrumented" => InstrumentedTestFile.apply
94
126
      case "presentation" => PresentationTestFile.apply
 
127
      case "ant"          => AntTestFile.apply
95
128
    }
96
129
    val test: TestFile = testFileFn(files.head, fileManager)
97
130
    if (!test.defineSettings(command.settings, out.isEmpty)) {
105
138
 
106
139
    try {
107
140
      NestUI.verbose("compiling "+toCompile)
 
141
      NestUI.verbose("with classpath: "+global.classPath.toString)
 
142
      NestUI.verbose("and java classpath: "+ propOrEmpty("java.class.path"))
108
143
      try new global.Run compile toCompile
109
144
      catch {
110
145
        case FatalError(msg) =>
111
146
          testRep.error(null, "fatal error: " + msg)
 
147
          return CompilerCrashed
112
148
      }
113
149
 
114
150
      testRep.printSummary()
116
152
    }
117
153
    finally logWriter.close()
118
154
 
119
 
    !testRep.hasErrors
 
155
    if (testRep.hasErrors) CompileFailed
 
156
    else CompileSuccess
120
157
  }
121
158
}
122
159
 
123
 
// class ReflectiveCompiler(val fileManager: ConsoleFileManager) extends SimpleCompiler {
124
 
//   import fileManager.{latestCompFile, latestPartestFile}
125
 
//
126
 
//   val sepUrls = Array(latestCompFile.toURI.toURL, latestPartestFile.toURI.toURL)
127
 
//   //NestUI.verbose("constructing URLClassLoader from URLs "+latestCompFile+" and "+latestPartestFile)
128
 
//
129
 
//   val sepLoader = new java.net.URLClassLoader(sepUrls, null)
130
 
//
131
 
//   val sepCompilerClass =
132
 
//     sepLoader.loadClass("scala.tools.partest.nest.DirectCompiler")
133
 
//   val sepCompiler = sepCompilerClass.newInstance()
134
 
//
135
 
//   // needed for reflective invocation
136
 
//   val fileClass = Class.forName("java.io.File")
137
 
//   val stringClass = Class.forName("java.lang.String")
138
 
//   val sepCompileMethod =
139
 
//     sepCompilerClass.getMethod("compile", fileClass, stringClass)
140
 
//   val sepCompileMethod2 =
141
 
//     sepCompilerClass.getMethod("compile", fileClass, stringClass, fileClass)
142
 
//
143
 
//   /* This method throws java.lang.reflect.InvocationTargetException
144
 
//    * if the compiler crashes.
145
 
//    * This exception is handled in the shouldCompile and shouldFailCompile
146
 
//    * methods of class CompileManager.
147
 
//    */
148
 
//   def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean = {
149
 
//     val res = sepCompileMethod2.invoke(sepCompiler, out, files, kind, log).asInstanceOf[java.lang.Boolean]
150
 
//     res.booleanValue()
151
 
//   }
152
 
// }
153
 
 
154
160
class CompileManager(val fileManager: FileManager) {
155
 
  var compiler: SimpleCompiler = new DirectCompiler(fileManager)
156
 
 
157
 
  var numSeparateCompilers = 1
158
 
  def createSeparateCompiler() = {
159
 
    numSeparateCompilers += 1
160
 
    compiler = new /*ReflectiveCompiler*/ DirectCompiler(fileManager)
161
 
  }
162
 
 
163
 
  /* This method returns true iff compilation succeeds.
164
 
   */
165
 
  def shouldCompile(files: List[File], kind: String, log: File): Boolean = {
166
 
    createSeparateCompiler()
167
 
    compiler.compile(None, files, kind, log)
168
 
  }
169
 
 
170
 
  /* This method returns true iff compilation succeeds.
171
 
   */
172
 
  def shouldCompile(out: File, files: List[File], kind: String, log: File): Boolean = {
173
 
    createSeparateCompiler()
174
 
    compiler.compile(Some(out), files, kind, log)
175
 
  }
176
 
 
177
 
  /* This method returns true iff compilation fails
178
 
   * _and_ the compiler does _not_ crash or loop.
179
 
   *
180
 
   * If the compiler crashes, this method returns false.
181
 
   */
182
 
  def shouldFailCompile(files: List[File], kind: String, log: File): Boolean = {
183
 
    createSeparateCompiler()
184
 
    !compiler.compile(None, files, kind, log)
185
 
  }
186
 
 
187
 
  /* This method returns true iff compilation fails
188
 
   * _and_ the compiler does _not_ crash or loop.
189
 
   *
190
 
   * If the compiler crashes, this method returns false.
191
 
   */
192
 
  def shouldFailCompile(out: File, files: List[File], kind: String, log: File): Boolean = {
193
 
    createSeparateCompiler()
194
 
    !compiler.compile(Some(out), files, kind, log)
195
 
  }
 
161
  private def newCompiler = new DirectCompiler(fileManager)
 
162
  def attemptCompile(outdir: Option[File], sources: List[File], kind: String, log: File): CompilationOutcome =
 
163
    newCompiler.compile(outdir, sources, kind, log)
196
164
}