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

converting source path from absolute to relative #275

Closed
wants to merge 2 commits into from

Conversation

sammy-1234
Copy link

@sammy-1234 sammy-1234 commented Jul 31, 2019

Necessary for #265 :
Currently, at compile time, scoverage stores (as a string) the conical sourcePath (path for the source file) for a statement inside the instrument file scoverage.coverage. This string is then again required during report generation to get the source file in ScoverageHtmlWriter . This breaks in a distributed environment where report generation is happening on a different machine and is unable to locate the source file due to the absolute path.

The current fix makes the path relative when storing and turns it back to a conical one (w.r.t cwd) on retrieving. Thanks

Copy link

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but: is it possible to cover this with a test?

// instead of the canonical path. This is required to make it work with
// remoting or in a distributed environment.
def getRelativePath(filePath: String): String = {
val base = new File(".").getCanonicalPath + File.separator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gslowikowski
Copy link
Member

Hi guys

You assumed that current working directory is project's root directory. This is not always true. For example in Maven you can specify -f pathto/pom.xml option to build a project in different directory.

@sammy-1234
Copy link
Author

sammy-1234 commented Aug 6, 2019

@gslowikowski
Thanks for the comment. I see your point here. How would you then recommend making the project path relative? Is there a variable that I missed which stores the project's root dir? Absolute path cannot work in a distributed setting.

illicitonion pushed a commit to pantsbuild/pants that referenced this pull request Mar 6, 2020
Co-authored-by: Ny Saechao <[email protected]>

The problem is also referenced here : scoverage/scalac-scoverage-plugin#275

### Problem

Currently, at compile time, scoverage stores (as a string) the conical sourcePath (path for the source file) for a statement inside the instrument file `scoverage.coverage`. This string is then again required during report generation to get the source file in `ScoverageHtmlWriter` . This breaks in a distributed environment where report generation is happening on a different machine and is unable to locate the source file due to the absolute path.

### Solution

The current fix makes the path relative when storing and turns it back to a conical one (w.r.t cwd) on retrieving. For now, the fix is merged in twitter forked version of scoverage (version 1.0.2-twitter).

### Result

Scoverage can now work in a distributed environment.
wisechengyi pushed a commit to pantsbuild/pants that referenced this pull request Mar 6, 2020
Co-authored-by: Ny Saechao <[email protected]>

The problem is also referenced here : scoverage/scalac-scoverage-plugin#275

### Problem

Currently, at compile time, scoverage stores (as a string) the conical sourcePath (path for the source file) for a statement inside the instrument file `scoverage.coverage`. This string is then again required during report generation to get the source file in `ScoverageHtmlWriter` . This breaks in a distributed environment where report generation is happening on a different machine and is unable to locate the source file due to the absolute path.

### Solution

The current fix makes the path relative when storing and turns it back to a conical one (w.r.t cwd) on retrieving. For now, the fix is merged in twitter forked version of scoverage (version 1.0.2-twitter).

### Result

Scoverage can now work in a distributed environment.
wisechengyi pushed a commit to pantsbuild/pants that referenced this pull request May 4, 2020
Co-authored-by: Ny Saechao <[email protected]>

The problem is also referenced here : scoverage/scalac-scoverage-plugin#275

### Problem

Currently, at compile time, scoverage stores (as a string) the conical sourcePath (path for the source file) for a statement inside the instrument file `scoverage.coverage`. This string is then again required during report generation to get the source file in `ScoverageHtmlWriter` . This breaks in a distributed environment where report generation is happening on a different machine and is unable to locate the source file due to the absolute path.

### Solution

The current fix makes the path relative when storing and turns it back to a conical one (w.r.t cwd) on retrieving. For now, the fix is merged in twitter forked version of scoverage (version 1.0.2-twitter).

### Result

Scoverage can now work in a distributed environment.
@callicles
Copy link

Still needed?

@ckipp01
Copy link
Member

ckipp01 commented Sep 24, 2021

I'm going to go ahead and close this in favor of #385, which will be merged into the V2 branch. The idea is exactly the same, but we avoid the issue raised here about assuming the source directory being (".") by instead introducing a new config option, sourceRoot which is the same concept that semanticdb uses for this same purpose.

@ckipp01 ckipp01 closed this Sep 24, 2021
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

Successfully merging this pull request may close these issues.

5 participants