Open gofenix opened 4 years ago
Path lengths on macOS are quite limiting, unfortunately.
I can't tell what exactly causes this without further information, but the very long last path component (Users-lucas-Documents-demos-crystals-scry-Users-lucas-.cache-crysta-Users-lucas-Documents-demos-crystals-scry-Users-lucas-.cache-crysta-Users-lucas-Documents-demos-crystals-scry-Users-lucas-.cache-crysta-Users-lucas-Documents-demos-crystals-scry-src-scry.cr
) indicates that the compiler is asked to compile a file that exists at the path that you get when replacing all the -
with /
. This already long path is not generated by the compiler. The compiler only prepends the path to the temp dir, which makes it exceed the file limit.
So to me it seems like the problem originates somewhere else, maybe scry produces such a long file name?
Still, the compiler should be able to handle this better.
At the very least, such a file system error should not be indicated as a compiler bug. It should be a normal compiler error (wrap the error in Crystal::Error
).
As an additional enhancement, we could consider mitigating the problem by shortening paths for cache files if they threaten to exceed the maximum file name length. Replacing (part of) the cache key by a hash should work for this.
Reproduction is simple by setting CRYSTAL_COMPILER_PATH
to a ridiculously long path (4K on linux, 1K on mac) and compiling a file. (NOTE: In that case the compiler should genuinely fail and not try to recover in some way.)
I just noticed that the Program#cache_dir
property (which is getting populated when the error occurs) appears to be not actually used anywhere.
$ grep -R cache_dir src/compiler/
src/compiler/crystal/program.cr: setter cache_dir : String?
src/compiler/crystal/compiler.cr: program.cache_dir = CacheDir.instance.directory_for(sources)
Removing that doesn't fix the problem though, it just appears later in the codegen stage.
hello, when i use scry in vscode.
there are some errors like this:
and this is my crystal info:
hope your help, thanks