graphbuddy icon indicating copy to clipboard operation
graphbuddy copied to clipboard

[sourcefile] is not located within sourceroot '~/.gradle/workers'

Open aishfenton opened this issue 4 years ago • 2 comments

Gradle does it's Scala compilation in a directory other than the project root (each worker process in Gradle runs in $GRADLE_HOME/workers). This causes the above error to occur.

Semanticdb compiler plugin gets around this by having a -Psourceroot plugin parameter that you specify. However, it's important that this parameter can also be specified relative to the output directory (aka scalac -d), which should already be available to the plugin through scalac's settings.

Longer explanation on above point. Gradle (like Bazel) supports task caching across machines. So that for larger projects, Gradle will download the compilation results (i.e. class and other files) from a remote cache, saving each users from having to do compilation themselves. For big projects this is a huge productivity gain. But for this to work, all the compiler flags have to exactly match between machines, otherwise Gradle can't be sure that the results are equivalent. This mostly works out great, but obviously breaks if you start sticking things like absolute paths in the compiler options (which are different between machines). And unfortunately you also can't make the sourceroot relative to the worker directory, because even that could be different between different machines.

So the only fixed point of reference you have to make it relative too is the scalac output directory. This itself will also be different across machines, but since it's set internally by Gradle/Zinc/Scalac rather than through a compiler option, it works out.

aishfenton avatar Dec 29 '21 18:12 aishfenton

The related issue for SemenaticDB: https://github.com/scalameta/scalameta/issues/2515

aishfenton avatar Dec 29 '21 18:12 aishfenton

Hi @aishfenton :) thanks for detailed reporting. As far as I understand the issue, we could add similar -Psourceroot parameter to our semantigraphs-scalac plugin, which will workaround the issue for projects which are not using gradle caching mechanism. To have it working for cache using projects as well, what you propose is to compute the sourceroot based on scalac output directory, correct? And this scalac output directory we should be able to extract from scalac plugin internals 🤔 I will try to look into this closer.

liosedhel avatar Jan 12 '22 07:01 liosedhel