Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseReportWriter fails with "No source root found" when source uses symbolic links #150

Closed
nickweeds opened this issue Feb 10, 2016 · 2 comments

Comments

@nickweeds
Copy link

Problem:
I have an sbt project that collects code coverage for source code in another project that it picks up using a symbolic link of the form
ln -s {external_root}/{project}/src/main {root}/{project}/src/main
Everything works fine until I run "sbt coverageReport", but that fails with an error of the form:
No source root found for '{root}/{project}/src/main/.../{source.scala}' (source roots: '{external_root}/{project}/src/main/scala/', ...')

Diagnosis:
The failure occurs because BaseReportWriter applies _.getCanonicalPath to sourceDirectories (when initializing formattedSourcePaths) but not to the source file in relativeSource().

Fix:
I think this can be fixed in relativeSource() by applying getCanonicalPath to the source file name before searching sourcePaths.

@gslowikowski
Copy link
Member

For readers convenience, we are talking about BaseReportWriter class.

I implemented relativeSource method. In fact the easiest way to fix this bug would be to map src to new File(src).getCanonicatPath but I generally don't like calling getCanonicalPath if not absolutely needed.

getCanonicalPath was here since version 1.0.0 (this commit), but why was it introduced there? @sksamuel, do you remember?
Because it was here for so long, I left it here.

src parameter in relativeSource method comes from Statement.source.path and represents absolute path, not canonical. It comes from the internals of Scalac. I cannot find, where and how it's created.
Maybe we could change

  private val formattedSourcePaths: Seq[String] = sourceDirectories filter ( _.isDirectory ) map ( _.getCanonicalPath + File.separator )

to

  private val formattedSourcePaths: Seq[String] = sourceDirectories filter ( _.isDirectory ) map ( _.getAbsolutePath + File.separator )

instead of adding getCanonicalPath mapping to src parameter? This additionally should improve performance.

I can change it and publish new snapshot to test. WDYT?

@gslowikowski
Copy link
Member

Fixed by #159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants