summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/CompileSocket.scala
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2006-07-13 15:35:41 +0000
committerLex Spoon <lex@lexspoon.org>2006-07-13 15:35:41 +0000
commit3f17e1b36f4890e2e9edb5c4844b3cc95f8fda06 (patch)
tree8552c82dd66b75ba3f365765884d0a5d5ffe9815 /src/compiler/scala/tools/nsc/CompileSocket.scala
parent52b71a5564d2517e8fe8ebef52e012f724284279 (diff)
downloadscala-3f17e1b36f4890e2e9edb5c4844b3cc95f8fda06.tar.gz
scala-3f17e1b36f4890e2e9edb5c4844b3cc95f8fda06.tar.bz2
scala-3f17e1b36f4890e2e9edb5c4844b3cc95f8fda06.zip
- try to use scala from ${scala.home}/bin if av...
- try to use scala from ${scala.home}/bin if available - before using /tmp, try to use ${scala.home}/var/scala-devel and then ${user.home}/tmp
Diffstat (limited to 'src/compiler/scala/tools/nsc/CompileSocket.scala')
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala76
1 files changed, 69 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index c5ae8131e1..f0d30ef6f3 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -14,20 +14,82 @@ object CompileSocket {
private val dirName = "scalac-compile-server-port"
/** The vm-part of the command to start a new scala compile server */
- private val vmCommand = "scala"
+ private val vmCommand =
+ System.getProperty("scala.home") match {
+ case null => "scala"
+ case dirname =>
+ val trial = new File(new File(dirname, "bin"), "scala")
+ if(trial.canRead)
+ trial.getPath
+ else
+ "scala"
+ }
/** The class name of the scala compile server */
private val serverClass = "scala.tools.nsc.CompileServer"
/** The temporary directory in which the port identification file is stored */
private val tmpDir = {
- val d = new File(System.getProperty("java.io.tmpdir"), dirName)
- if (!d.isDirectory())
- if (!d.mkdir()) {
- System.err.println("cannot create directory "+dirName+"; exiting")
- exit(1)
+ val totry = List(
+ Pair("scala.home", List("var", "scala-devel")),
+ Pair("user.home", List("tmp")),
+ Pair("java.io.tmpdir", Nil))
+
+ /** Expand a property-extensions pair into a complete File object */
+ def expand(trial: Pair[String, List[String]]): Option[File] = {
+ val Pair(topdirProp, extensions) = trial
+ val topdir = System.getProperty(topdirProp)
+ if(topdir == null)
+ return None
+
+ val fulldir =
+ extensions.foldLeft[File](new File(topdir))(
+ (dir,ext)=>new File(dir, ext))
+
+ Some(fulldir)
+ }
+
+ /** Write a test file to a directory to see if it is writable */
+ def dirWritable(dir: File): Boolean = {
+ dir.mkdirs
+ if(!dir.exists)
+ return false
+
+ val f = new File(dir, "caniwrite")
+
+ try {
+ f.createNewFile
+ if(!f.canWrite)
+ return false
+ f.delete
+ if(f.exists)
+ return false
+ } catch {
+ case _:java.io.IOException =>
+ f.delete
+ return false
}
- d
+
+ return true
+ }
+
+ val potentials =
+ for {
+ val trial <- totry
+ val expanded = expand(trial)
+ !expanded.isEmpty
+ dirWritable(expanded.get)
+ }
+ yield expanded.get
+
+ if(potentials.isEmpty) {
+ Console.println("could not find a directory for port files")
+ exit(1)
+ } else {
+ val d = new File(potentials.head, dirName)
+ d.mkdirs
+ d
+ }
}
/** Maximum number of polls for an available port */