-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/go/analysis/cmd/vet: add -cgoinclude check for #include of code in subdirectories #26506
Comments
What's the bullet point for this issue? Would love to work on it if @shivakumargn isn't |
Yes, look at the cgo preamble comment and the C/C++ files (including header files) in the directory, and warn about uses of #include "" (not #include <>, <> is always OK) with a relative path that contains at least one path separator. |
I'm on it! |
Includes that fall outside the Go source tree aren't our responsibility to warn about: |
OK, so I throw an error only when the include is in a subdir of the project, but not when it is directly in the same dir as the go file, and not when it's outside the src tree. Got you right? Should I throw a warning for the third case or just leave it be? |
If it's outside the source tree, just leave it be. (It's not portable, but that is likely intentional: for example, the Go program may be a command-line tool for managing some aspect of a particular OS or distribution.) |
Change https://golang.org/cl/126375 mentions this issue: |
Hello @iamoryanmoshe, thank you for sending the CL and for taking this on! As @mvdan and @thepudds had mentioned in the CL, these checks have moved from the standard library to https://godoc.org/golang.org/x/tools/go/analysis/cmd/vet aka https://github.com/golang/tools/tree/master/go/analysis/cmd/vet perhaps we can close the original CL and resurrect it by sending a CL to x/tools but also then I'll retitle this issue and we can even no longer tie it down to a specific release. |
The go build model is that all code for a package is in one directory.
The cache relies on this.
Vendoring tools rely on this.
Probably many other things rely on this.
One of the few ways a package can violate this rule is by using
#include in cgo source code to access code in nearby directories.
This appears to work, in that the package builds,
but it doesn't cache properly, doesn't vendor properly, and so on.
It seems reasonable for cmd/vet to notice such #includes and
complain about them, and we could enable that check as one
of the automatic ones run during go test.
Suggested in #26366.
The text was updated successfully, but these errors were encountered: