Object files/libraries produced by Gradle contain absolute paths
The object files created via gcc contain an absolute path to the source file. I suspect this is due to the way we call the compiler.
This can kill cacheability when a shared library is packaged into a jar when everything else is "the same".
Your Environment
Linux, gcc.
@lacasseio FYI, this is something we'll need to keep in mind for native caching.
You are completely right. This is indeed related to how we call the compiler and manage the file path to the source files. We use absolute path everywhere. This issue is true for all supported compilers (MSVC included). The only way I can think of right now to fix this is to relativize the path before calling the compiler.
The other option is to use identical file paths (and sync files to/from a working directory), but I think just doing relative paths is a good first step.
For the paths that are there due to debug symbols, there are other options:
- Generate a separate symbol file and don't cache this. Or cache it and reuse it only when the source paths happen to be the same.
- Ignore the paths when I don't need to be able to debug the binaries.
- Copy the source files to the location expected by the binaries when I want to be able to debug them.
It also happens without debugging symbols because things like __FILE__ expand to the full file path (due to the way we pass the path to the compiler). That was the case with the build I found this in.
One question would be what this actually breaks. We don't care that the object files aren't byte-wise equivalent to what they would be if compiled locally, we care only that they behave the same way for whatever purpose they're being used for.
That said, we have other options to deal with this too, such as transforming between preprocessor and the compiler, or detecting usages of __FILE__ during our dependency analysis and not caching these object files, or caching only when the source paths are the same. Or we might allow you to normalize this input away if you don't care.
FTR, tracking is what CCACHE does with macros like __FILE__ and __TIME__ etc.: https://ccache.samba.org/manual.html#_performance