On Thu, 29 Aug 2013 10:52:16 -0700
Paul Phillips <
pa...@improving.org> wrote:
> On Thu, Aug 29, 2013 at 9:21 AM, Mark Harrah <
dmha...@gmail.com> wrote:
>
> > The first is relative to the current working directory instead of the
> > project's base directory.
>
>
> That seems like a dangerous thing to have at all. Does cwd change if I
> start sbt in the base directory and then say "project sub" which is in a
> subdirectory?
Right, you should not depend on the cwd. That you can ever end up with relative paths is not desirable- I don't know how to prevent it. If `file` didn't exist, people would use new File, same problem. Sometimes you want to construct absolute paths.
In Project construction (either Project.apply or Project.in(File)), you can pass a relative path because it will resolve it against the base directory of the build. This is before settings, so baseDirectory.value / "sub" doesn't make sense yet. (From a consistency standpoint, this isn't great.)
Every task that accepts Files could also pull the baseDirectory and resolve everything against it. This isn't great because you check and/or convert to absolute paths everywhere you might possibly want to use a file. Plugin authors would have to do this consistently as well.
`file` could be removed and `absFile` added, which checks isAbsolute. I'm not sure if there are use cases not covered, but at least Project.in(File) would have to change somehow.
> Either way though it took me hours to pinpoint what was
> happening here, so it would be great to fix whatever it is that is
> comparing paths. Comparing paths for equality in general is fraught with
> traps, as I think you have already found, as has scalac.
The fix is very likely to be catching all relative paths and making them absolute because there are lookups of Files in maps everywhere in the incremental compiler. These files come from lots of places, so it would be ideal to catch them at the source (the `file` method). I'm pretty sure the hooks sbt puts into the compiler convert things to absolute there at that source.
-Mark