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/go2go: build tags not supported correctly #39998

Open
rogpeppe opened this issue Jul 2, 2020 · 5 comments
Open

cmd/go2go: build tags not supported correctly #39998

rogpeppe opened this issue Jul 2, 2020 · 5 comments

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Jul 2, 2020

commit d014fca

The go2go tool doesn't seem to recognise go build tags, which means that it's not possible to use external packages that use them (I was bitten when trying to import github.com/frankban/quicktest, for the record).

Here's a testscript reproducer:

exec go tool go2go build

-- go.mod --
module example.com/test

go 1.15
-- x_111.go2 --
// +build go1.11

package foo

var x = 34
-- x_112.go2 --
// +build go1.12

package foo

var x = 34
@tdakkota
Copy link

@tdakkota tdakkota commented Jul 2, 2020

It happens because translator does not copy magic comments from .go2 source.

//go:noinline
func Foo() {
}

becomes

//line <original code line>
func Foo() {
}
@josharian
Copy link
Contributor

@josharian josharian commented Jul 4, 2020

FWIW, how go-fuzz handles this is by looking for initial comments and //go directives, saving them, manipulating the code (inserting coverage), and then re-inserting the comments. See functions initialComments and trimComments and related code in go-fuzz-build.

@cagedmantis cagedmantis added this to the Unreleased milestone Jul 6, 2020
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Jul 6, 2020

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 6, 2020

I don't know off-hand how much effort is needed to make this work, but we may decide to not do anything about it. Keep in mind this is a prototype to explore the generics mechanisms; anything and everything may change as we go forward.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 7, 2020

It's not just a matter of magic comments. The type checker gets a list of files, and it expects that build tags have already been applied at that point to remove files that it shouldn't see.

I don't mind if somebody fixes this, but I don't plan to work on it myself. The go2go tool is meant to be an experimental translation tool, it's not meant to handle all details of how Go packages are built.

@ianlancetaylor ianlancetaylor removed their assignment Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.