-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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/packages: Load returned packages with errors when specifying GOOS #36547
Comments
CC @matloob |
If GOOS is not specified, does it work? I wonder if this is the same issue as #36441. |
Hmm, I thought yes, but it looks like this depends on the cache state. Let me double check. |
Oops, now I found this issue even without GOOS. Then this is the same as #36441. |
Removing |
Updated the first comment, but I'm fine to close this marking 'duplicated'. |
Now I realized I omitted packages.Need*, and this was wrong. I updated the issue again. Sorry for the confusion.
Then yes it worked without GOOS. This can be reproduced when specifying various packages.Mode* values. This sounds a different issue from #36441. |
I'm taking a look at this. |
Change https://golang.org/cl/214738 mentions this issue: |
Change https://golang.org/cl/214738 mentions this issue: |
Change https://golang.org/cl/214943 mentions this issue: |
Hm okay, I'll take another look. |
I think I'll need some help filling in my knowledge of android: I tried to go a go list in your example module:
I don't totally see what's going on but it looks like the problem is that we need the android C libs (like I'm really hesitant about stubbing out the C package with a fake empty package because the results are not totally correct. I wonder what our other options are. Can gomobile guarantee the android C libs exist by setting the right environment variables, etc? Can it inject a fake C package if it knows it will work? |
Just FYI: this issue is reproduced not only with GOOS=android but also other values like GOOS=windows |
Right: windows returns an error like the following:
I don't think we can get this to work in general. |
I think assuming this makes sense. I'd want a proper way to skip/ignore the reported issues around importing C.
I was wondering how. |
We discussed and the conclusion is that we should specify C compilers, or go/packages cannot do type-checking correctly. Then, the current error makes sense to me. In the context of gomobile, we should specify environment variables like CC or CXX when calling packages.Load. These variables are defined cmd/gomobile/env.go, so we should be able to utilize them. If these do not work, we would need to ignore pkg.Errors as the final resort... |
@matloob I don't know much about Is there any option to skip cgo but still analyze the go part? |
It's okay to ignore errors. go/packages already tries to do the best it can, and if the information that gomobile needs doesn't depend on perfect code then it should work fine as is. Specifically for this bug, what I meant was that if we can't depend on Load returning a package if cgo can't run. That's what this bug was originally filed for. But that doesn't mean that tools can't work on the results of go/packagse. |
Change https://golang.org/cl/214498 mentions this issue: |
OK I'll adopt the way to just ignore Errors for #27234. |
This CL gives CGO_ENABLED=1 explicitly when executing gobind since Cgo is disabled by default when GOOS is given. This CL also adds importing C to the tests to confirm that Cgo works correctly. This CL also updates go.mod since this change requries the change in go/packages: golang.org/cl/214943 Updates golang/go#27234 Updates golang/go#36547 Change-Id: I66f9697f992f15b52fca7871e4e0ed64ca2b4965 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214498 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This CL gives CGO_ENABLED=1 explicitly when executing gobind since Cgo is disabled by default when GOOS is given. This CL also adds importing C to the tests to confirm that Cgo works correctly. This CL also updates go.mod since this change requries the change in go/packages: golang.org/cl/214943 Updates golang/go#27234 Updates golang/go#36547 Change-Id: I66f9697f992f15b52fca7871e4e0ed64ca2b4965 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214498 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This CL gives CGO_ENABLED=1 explicitly when executing gobind since Cgo is disabled by default when GOOS is given. This CL also adds importing C to the tests to confirm that Cgo works correctly. This CL also updates go.mod since this change requries the change in go/packages: golang.org/cl/214943 Updates golang/go#27234 Updates golang/go#36547 Change-Id: I66f9697f992f15b52fca7871e4e0ed64ca2b4965 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/214498 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Created these files in one directory.
go.mod
:main.go
:c.go
:What did you expect to see?
No error
What did you see instead?
This is similar to #36441
The text was updated successfully, but these errors were encountered: