summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ScriptRunner.scala
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2006-07-12 09:05:00 +0000
committerLex Spoon <lex@lexspoon.org>2006-07-12 09:05:00 +0000
commit6147fc43c8e68a3ff20f62e62b5a851fc48dd19b (patch)
tree2bf1de0272ed8f00c328c1acbf951c7611957448 /src/compiler/scala/tools/nsc/ScriptRunner.scala
parent2906c10f80eefef9f9feada239968ecbd251c2cc (diff)
downloadscala-6147fc43c8e68a3ff20f62e62b5a851fc48dd19b.tar.gz
scala-6147fc43c8e68a3ff20f62e62b5a851fc48dd19b.tar.bz2
scala-6147fc43c8e68a3ff20f62e62b5a851fc48dd19b.zip
-savecompiled is now an option that is off by d...
-savecompiled is now an option that is off by default
Diffstat (limited to 'src/compiler/scala/tools/nsc/ScriptRunner.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ScriptRunner.scala76
1 files changed, 48 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala
index fcef8adfdf..593ee60629 100644
--- a/src/compiler/scala/tools/nsc/ScriptRunner.scala
+++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -80,7 +80,7 @@ object ScriptRunner {
addFromDir(sourcePath, "")
jar.close
} catch {
- case _ => jarFile.delete // XXX what errors to catch?
+ case _:Error => jarFile.delete // XXX what errors to catch?
}
}
@@ -146,37 +146,57 @@ object ScriptRunner {
* a classpath for the compiled script.
*/
private def withCompiledScript
- (settings: Settings, scriptFile: String)
- (handler: String=>Unit) =
+ (settings: GenericRunnerSettings, scriptFile: String)
+ (handler: String=>Unit)
+ :Unit =
{
- val jarFile = jarFileFor(scriptFile)
-
- def jarOK = (jarFile.canRead &&
- (jarFile.lastModified > new File(scriptFile).lastModified))
-
- if(jarOK)
- {
- // pre-compiled jar is current
- handler(jarFile.getAbsolutePath)
- } else {
- // The pre-compiled jar is old. Recompile the script.
- jarFile.delete
+ def compileWithInterp: Pair[Interpreter, Boolean] = {
val interpreter = new Interpreter(settings)
interpreter.beQuiet
- if(interpreter.compileSources(List(wrappedScript(scriptFile)))) {
- tryMakeJar(jarFile, interpreter.classfilePath)
- if(jarOK) {
- // use the jar if possible, so that
- // the interpreter gets closed more reliably
- interpreter.close
- handler(jarFile.getAbsolutePath)
- } else {
- try {
- handler(interpreter.classfilePath.getAbsolutePath)
- } finally {
- interpreter.close
+ val ok = interpreter.compileSources(List(wrappedScript(scriptFile)))
+ Pair(interpreter, ok)
+ }
+
+ if(settings.savecompiled.value) {
+ val jarFile = jarFileFor(scriptFile)
+
+ def jarOK = (jarFile.canRead &&
+ (jarFile.lastModified > new File(scriptFile).lastModified))
+
+ if(jarOK) {
+ // pre-compiled jar is current
+ handler(jarFile.getAbsolutePath)
+ } else {
+ // The pre-compiled jar is old. Recompile the script.
+ jarFile.delete
+ val Pair(interpreter, compok) = compileWithInterp
+ try {
+ if(compok) {
+ tryMakeJar(jarFile, interpreter.classfilePath)
+ if(jarOK) {
+ // close the interpreter early and use the
+ // jar file
+ interpreter.close
+ handler(jarFile.getAbsolutePath)
+ } else {
+ // run from the interpreter's temporary
+ // directory
+ handler(interpreter.classfilePath.getAbsolutePath)
+ }
}
+ } finally {
+ interpreter.close
+ }
+ }
+ } else {
+ // don't use the cache; just run from the interpreter's temporary directory
+ val Pair(interpreter, compok) = compileWithInterp
+ try {
+ if(compok) {
+ handler(interpreter.classfilePath.getAbsolutePath)
}
+ } finally {
+ interpreter.close
}
}
}
@@ -185,7 +205,7 @@ object ScriptRunner {
* settings.
*/
def runScript(
- settings: Settings,
+ settings: GenericRunnerSettings,
scriptFile: String,
scriptArgs: List[String]): Unit =
{