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

cmd/go: list -json -cgo omits Imports in files generated by cgo #26136

Closed
alandonovan opened this issue Jun 29, 2018 · 2 comments
Closed

cmd/go: list -json -cgo omits Imports in files generated by cgo #26136

alandonovan opened this issue Jun 29, 2018 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@alandonovan
Copy link
Contributor

alandonovan commented Jun 29, 2018

$ go version
go version devel +4f172e7a75 Mon Jun 25 18:17:49 2018 +0000 linux/amd64
$ ls ./cgo/
a.go
$ cat ./cgo/a.go 
package cgo

import "C"

var V = C.malloc(1)
$ go list -json ./cgo
{
        "Dir": ".../src/golang.org/x/tools/cgo",
        "ImportPath": "golang.org/x/tools/cgo",
        "Name": "cgo",
        "CgoFiles": [
                "a.go"
        ],
        "Imports": [
                "C"
        ],
        "Deps": [
                "internal/bytealg",
                "internal/cpu",
                "internal/race",
                "runtime",
                "runtime/cgo",
                "runtime/internal/atomic",
                "runtime/internal/sys",
                "sync",
                "sync/atomic",
                "syscall",
                "unsafe"
        ]
}
$ go list -json -cgo ./cgo
{
        "Dir": ".../src/golang.org/x/tools/cgo",
        "ImportPath": "golang.org/x/tools/cgo",
        "Name": "cgo",
        "CgoFiles": [
                "~/.cache/go-build/f3/f3242b8ad8bca1ad043e6df53b8b2887d860942c44c657b28f91bafead6f475b-d",
                "~/.cache/go-build/75/75d0efe60532158a29872e4b53737ce3eb1c5f3b0311bea3cca2a20d7f65b8d2-d",
                "~/.cache/go-build/55/55b3e499038558b20ae1f6fb3f86f1fbe98f77c6dd0a2afd2dc29036a25edbc9-d"
        ],
        "Imports": [
                "C"
        ],
        "Deps": [
                "internal/bytealg",
                "internal/cpu",
                "internal/race",
                "runtime",
                "runtime/cgo",
                "runtime/internal/atomic",
                "runtime/internal/sys",
                "sync",
                "sync/atomic",
                "syscall",
                "unsafe"
        ]
}

When the -cgo flag is enabled, go list processes Go source files that import "C" and lists the resulting generated files. However, the Imports list continues to contain "C" and does not reflect the actual imports of the generated files: unsafe, runtime/cgo, syscall.

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 29, 2018
@bcmills bcmills added this to the Go1.11 milestone Jun 29, 2018
@bcmills
Copy link
Contributor

bcmills commented Jun 29, 2018

(CC: @rsc, but I'll try to get to this if he doesn't first.)

@ianlancetaylor ianlancetaylor changed the title cmd/vgo: list -json -cgo omits Imports in files generated by cgo cmd/go: list -json -cgo omits Imports in files generated by cgo Jun 29, 2018
@gopherbot
Copy link

Change https://golang.org/cl/128935 mentions this issue: cmd/go: report implicit cgo inputs in go list -compiled

@golang golang locked and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants