summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiles Sabin <miles@milessabin.com>2009-11-15 15:46:52 +0000
committerMiles Sabin <miles@milessabin.com>2009-11-15 15:46:52 +0000
commit31c1983e7264242ea5e35a4cf1ab54105a4d2419 (patch)
treea6bd81c047a5839845856e8438e01584f02413ed
parent046bbed8b7afdb13af1b3f35daf44b72d3a7936d (diff)
downloadscala-31c1983e7264242ea5e35a4cf1ab54105a4d2419.tar.gz
scala-31c1983e7264242ea5e35a4cf1ab54105a4d2419.tar.bz2
scala-31c1983e7264242ea5e35a4cf1ab54105a4d2419.zip
Fixed #2627.
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala51
-rw-r--r--src/compiler/scala/tools/nsc/io/Path.scala18
2 files changed, 35 insertions, 34 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index bae0d624c6..f137a8eb4c 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -10,7 +10,7 @@ import java.io.{File, FileOutputStream, PrintWriter}
import java.io.{IOException, FileNotFoundException}
import java.nio.charset._
import compat.Platform.currentTime
-import scala.tools.nsc.io.{SourceReader, AbstractFile}
+import scala.tools.nsc.io.{SourceReader, AbstractFile, Path}
import scala.tools.nsc.reporters._
import scala.tools.nsc.util.{ClassPath, MsilClassPath, JavaClassPath, SourceFile, BatchSourceFile, OffsetPosition, RangePosition}
@@ -227,28 +227,12 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
settings.dependenciesFile.value match {
case "none" => ()
case x =>
- val jfile = new java.io.File(x)
- if (!jfile.exists) jfile.createNewFile
- else {
- // This logic moved here from scala.tools.nsc.dependencies.File.
- // Note that it will trip an assertion in lookupPathUnchecked
- // if the path being looked at is absolute.
-
- /** The directory where file lookup should start at. */
- val rootDirectory: AbstractFile = {
- AbstractFile.getDirectory(".")
-// val roots = java.io.File.listRoots()
-// assert(roots.length > 0)
-// new PlainFile(roots(0))
- }
-
- def toFile(path: String) = {
- val file = rootDirectory.lookupPathUnchecked(path, false)
- assert(file ne null, path)
- file
- }
-
- dependencyAnalysis.loadFrom(AbstractFile.getFile(jfile), toFile)
+ val depFilePath = Path(x)
+ if (depFilePath.exists) {
+ /** The directory where file lookup should start */
+ val rootPath = Path("")
+ def toFile(path: String) = AbstractFile.getFile(rootPath resolve Path(path))
+ dependencyAnalysis.loadFrom(AbstractFile.getFile(depFilePath), toFile)
}
}
@@ -841,15 +825,20 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
informTime("total", startTime)
if (!dependencyAnalysis.off) {
-
- def fromFile(file: AbstractFile): String = {
- val path = file.path
- if (path.startsWith("./"))
- path.substring(2, path.length)
- else path
+ settings.dependenciesFile.value match {
+ case "none" =>
+ case x =>
+ val depFilePath = Path(x)
+ if (!depFilePath.exists)
+ dependencyAnalysis.dependenciesFile = AbstractFile.getFile(depFilePath.createFile())
+
+ /** The directory where file lookup should start */
+ val rootPath = Path("").normalize
+ def fromFile(file: AbstractFile): String =
+ rootPath.relativize(Path(file.file).normalize).path
+
+ dependencyAnalysis.saveDependencies(fromFile)
}
-
- dependencyAnalysis.saveDependencies(fromFile)
}
}
diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala
index 37cc64cf75..e7a6fddba4 100644
--- a/src/compiler/scala/tools/nsc/io/Path.scala
+++ b/src/compiler/scala/tools/nsc/io/Path.scala
@@ -66,6 +66,7 @@ import Path._
class Path private[io] (val jfile: JFile)
{
val separator = JFile.separatorChar
+ val separatorStr = JFile.separator
// Validation: this verifies that the type of this object and the
// contents of the filesystem are in agreement. All objects are
@@ -91,9 +92,20 @@ class Path private[io] (val jfile: JFile)
def name: String = jfile.getName()
def path: String = jfile.getPath()
def normalize: Path = Path(jfile.getCanonicalPath())
- // todo -
- // def resolve(other: Path): Path
- // def relativize(other: Path): Path
+
+ def resolve(other: Path) = if (other.isAbsolute) other else /(other)
+ def relativize(other: Path) = {
+ assert(isAbsolute == other.isAbsolute, "Paths not of same type: "+this+", "+other)
+
+ def createRelativePath(baseSegs: List[String], otherSegs: List[String]) : String = {
+ (baseSegs, otherSegs) match {
+ case (b :: bs, o :: os) if b == o => createRelativePath(bs, os)
+ case (bs, os) => ((".."+separator)*bs.length)+os.mkString(separatorStr)
+ }
+ }
+
+ Path(createRelativePath(segments, other.segments))
+ }
// derived from identity
def root: Option[Path] = roots find (this startsWith _)