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

Comments

Projects
None yet
3 participants
@alandonovan
Copy link
Contributor

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 this to the Go1.11 milestone Jun 29, 2018

@bcmills

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Aug 10, 2018

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

@gopherbot gopherbot closed this in 64205cd Aug 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.