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/cgo: godefs doesn't work nicely with multiple input files #14919

Open
mundaym opened this Issue Mar 22, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@mundaym
Member

mundaym commented Mar 22, 2016

It would be nice if the output of the command cgo -godefs with multiple input files resulted in a legal source file. Currently it duplicates the package declaration (and the generated comments) rendering the output useless without post-processing (since all the output goes straight to stdout):

$ cat a.go
package ex

/*
typedef int a;
*/
import "C"

type Atype C.a
$ cat b.go
package ex

/*
typedef int b;
*/
import "C"

type Btype C.b
$ go tool cgo -godefs a.go b.go
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs a.go b.go

package ex

type Atype int32
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs a.go b.go

package ex

type Btype int32

It would be nice if the output were instead:

$ go tool cgo -godefs a.go b.go
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs a.go b.go

package ex

type Atype int32

type Btype int32

This would be useful in situations where cgo -godefs requires extra/different information on different platforms. It is generally fairly easy to workaround though and the lack of this feature in previous versions of go might limit its usefulness.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 22, 2016

@minux

This comment has been minimized.

Member

minux commented Mar 22, 2016

@mundaym

This comment has been minimized.

Member

mundaym commented Mar 22, 2016

My use case is the syscall package in std and maybe x/sys/unix. Both for the s390x port. We need to add some new struct types to types_linux.go and I haven't thought of a clean way to do it without either adding to the APIs on other platforms or adding a new autogenerated (z*.go) file. It probably isn't worth adding this feature just for this use case, but I thought I'd create an issue in case there was any other interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment