-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/go/packages: Load returns different results depending on build cache state #33687
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
Comments
CC @matloob |
The "Java/..." packages are special package paths introduced to support for reverse-binding (See #16876, and also x/mobile/bind/genclasses.go files). @eliasnaur Is it possible to generate those packages early? I hope we are not facing a chicken-and-egg problem. |
I think this is not a mobile-specific issue, but an issue with unknown package. For example, // $GOPATH/go/src/github.com/hajimehoshi/testpkg/foo.go
package foo
import (
"Fooooooo"
) can cause the same issue: // main.go
package main
import (
"fmt"
"golang.org/x/tools/go/packages"
)
func main() {
cfg := &packages.Config{
Mode: packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles |
packages.NeedImports | packages.NeedDeps |
packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo,
}
allPkg, err := packages.Load(cfg, "github.com/hajimehoshi/testpkg")
if err != nil {
panic(err)
}
fmt.Println(allPkg)
} and run:
The result is:
|
I'm not sure what you mean by "early". The Java/... and ObjC/... packages are generated as a first step before the actual generating of bindings.
The reverse bindings work similarly to Cgo, where the AST of Go source files are analyzed for their imports matching Java/... or ObjC/... and for references using those imports. In a sense this is a chicken-and-egg problem because Go source that imports the magic packages are not buildable yet. However, since the analysis only needs the AST the chicken-and-egg problem didn't apply when using go/build. I don't know about go/packages. |
@hajimehoshi Indeed! Thanks for the small example for reproducing the issue. go clean -cache | env GO111MODULE=off GOPACKAGESDEBUG=true go run . && env GO111MODULE=off GOPACKAGESDEBUG=true go run . 2019/08/16 17:33:53 26.264922ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "env" "GOMOD", stderr: <<>> 2019/08/16 17:33:53 26.415485ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "list" "-m" "-json" "all", stderr: <> 2019/08/16 17:33:54 25.019105ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "env" "GOPATH", stderr: <<>> 2019/08/16 17:33:54 52.135849ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "list" "-e" "-json" "-compiled=true" "-test=false" "-export=false" "-deps=true" "-find=false" "--" "foo.com/cool", stderr: <> [Foo] 2019/08/16 17:33:54 26.189039ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "env" "GOMOD", stderr: <<>> 2019/08/16 17:33:54 26.442476ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "list" "-m" "-json" "all", stderr: <> 2019/08/16 17:33:54 37.745538ms for GOROOT= GOPATH= GO111MODULE=off PWD=/Users/hakim/go/src/bar go "list" "-e" "-json" "-compiled=true" "-test=false" "-export=false" "-deps=true" "-find=false" "--" "foo.com/cool", stderr: <<>> [foo.com/cool] I will move this to |
@hajimehoshi is it possible to work around the issue temporarily while we figure out what's going on with go/packages, by running Load twice to warm the cache? |
Change https://golang.org/cl/190479 mentions this issue: |
I thought yes, but the trybots are still unhappy: https://storage.googleapis.com/go-build-log/c485506b/linux-amd64-androidemu_0afe1c3b.log Apparently the error message comes from the Go compiler (the message "type-checking package ..." is defined at I'm fine reverting my change to use go/packages once, if we cannot find a good solution. |
@hajimehoshi I ran trybot after reverting your change (https://golang.org/cl/190837), and still got the same error https://storage.googleapis.com/go-build-log/0dd120df/linux-amd64-androidemu_d1e7d4ed.log |
@hyangah That's interesting. Then I'd like to move on the CL https://go-review.googlesource.com/c/mobile/+/190479, that should make the situation better. Could you take a look? Thanks! |
* Correctly format build tags to pass into go/packages * Removes CGO_ENABLED=0 from a packages.Load configuration * Calls go/packages.Load twice to work around a build cache * staleness issue These bugs were introduced by CL 189597. Updates golang/go#27234. Updates golang/go#33687. Change-Id: I3ae6737bf53bbecda0c7e25885b9c6aea5779332 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/190479 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Emmanuel Odeke <[email protected]>
Is this still an issue in Go 1.13? I can't reproduce it now
I'm also wondering whether this is a tools issue or a cmd/go issue if it's still a problem. |
Me neither: I could not reproduce this with Go 1.13. |
Okay, I'll mark this as fixed? Please reopen if this shows up again. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Maybe yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Clear the cache by
and run the below code:
What did you expect to see?
What did you see instead?
In the second time with cache, the result became expected one.
CC @hyangah
The text was updated successfully, but these errors were encountered: