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

x/tools/imports: cannot resolve symlinks #14845

Closed
karalabe opened this issue Mar 17, 2016 · 3 comments
Closed

x/tools/imports: cannot resolve symlinks #14845

karalabe opened this issue Mar 17, 2016 · 3 comments

Comments

@karalabe
Copy link
Contributor

When the import resolver walks GOPATH for possible packages to import, it does not follow symbolic links. This causes issues during automatic code generation when the host environment was not set up for a Go workflow and the generator itself is emulating a Go workspace via symbolic links.

Although some threads mention that Go tools do not like symbolic links, the x/tools/loader seems perfectly happy to load the packages from symlinked paths, so there's an inconsistency in what one tool accepts and another doesn't.

The issue is at two places in the code:

where only real subfolders are followed, but not symlinks.

A simple solution is to add || child.Mode()&os.ModeSymlink == os.ModeSymlink, but that could lead to circular symlinks (which is probably the reason why it wasn't implemented in the first place). However that should be solvable by maintaining a list of physical paths already seen ad ignoring the symlink if it couples back to such a path.

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Mar 17, 2016
@ianlancetaylor
Copy link
Contributor

I think x/tools/importer and x/tools/loader should do whatever cmd/go does. Which, as far as I know, is to ignore symlinks to directories.

@FiloSottile
Copy link
Contributor

cmd/go will build packages that have a symlink along the import path perfectly. The only thing that does not traverse symlinks is wildcard resolution.

goimports should definitely not break code that was compiling before running it.

I have a patch, submitting it.

@gopherbot
Copy link

CL https://golang.org/cl/23803 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants