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: continue conversion to bug-resistant //go:build constraints #41184

Open
rsc opened this issue Sep 2, 2020 · 23 comments
Open

cmd/go: continue conversion to bug-resistant //go:build constraints #41184

rsc opened this issue Sep 2, 2020 · 23 comments

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Sep 2, 2020

In June I posted a draft design for moving from // +build lines with ad-hoc syntax to //go:build lines with standard Boolean expressions; that doc also has links to a video overview and a prototype implementation.

I propose that we adopt this design, with N = 17 in the Transition section, meaning that the prep work would happen in Go 1.16, the main change would land in Go 1.17, and the transition would be finalized in Go 1.18.

@rsc rsc added this to the Proposal milestone Sep 2, 2020
@gopherbot gopherbot added the Proposal label Sep 2, 2020
@rsc rsc added this to Active in Proposals Sep 2, 2020
@rsc rsc changed the title proposal: start conversion to bug-resistant //go:build constraints proposal: cmd/go: start conversion to bug-resistant //go:build constraints Sep 2, 2020
@rsc
Copy link
Contributor Author

@rsc rsc commented Sep 16, 2020

Based on the emoji above and the lack of any objections (along with the overwhelmingly positive Reddit thread), this seems like a likely accept.

@rsc rsc moved this from Active to Likely Accept in Proposals Sep 16, 2020
@rsc
Copy link
Contributor Author

@rsc rsc commented Sep 23, 2020

No change in consensus, so accepted.

@rsc rsc moved this from Likely Accept to Accepted in Proposals Sep 23, 2020
@rsc
Copy link
Contributor Author

@rsc rsc commented Sep 23, 2020

Please note that accepting this means that //go:build lines will start working in Go 1.17, not Go 1.16.
Don't everyone rush to put them in.

@rsc rsc modified the milestones: Proposal, Go1.16 Sep 23, 2020
@rsc rsc changed the title proposal: cmd/go: start conversion to bug-resistant //go:build constraints cmd/go: start conversion to bug-resistant //go:build constraints Sep 23, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 12, 2020

Change https://golang.org/cl/240600 mentions this issue: go/build: reject //go:build without // +build

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 12, 2020

Change https://golang.org/cl/240553 mentions this issue: cmd/go: add IgnoredOtherFiles to go list; pass IgnoredFiles to vet

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 12, 2020

Change https://golang.org/cl/240601 mentions this issue: cmd/compile: reject misplaced go:build comments

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 12, 2020

Change https://golang.org/cl/240602 mentions this issue: cmd/asm: reject misplaced go:build comments

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 12, 2020

Change https://golang.org/cl/240554 mentions this issue: cmd/vet: look at ignored files in buildtag check

gopherbot pushed a commit that referenced this issue Oct 12, 2020
Show constraint-ignored non-.go files in go list, as Package.IgnoredOtherFiles
(same as go/build's IgnoredOtherFiles).

Pass full list of ignored files to vet, to help buildtag checker.

For #41184.

Change-Id: I749868de9082cbbc1efbc59370783c8c82fe735f
Reviewed-on: https://go-review.googlesource.com/c/go/+/240553
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
gopherbot pushed a commit that referenced this issue Oct 13, 2020
We are converting from using error-prone ad-hoc syntax // +build lines
to less error-prone, standard boolean syntax //go:build lines.
The timeline is:

Go 1.16: prepare for transition
 - Builds still use // +build for file selection.
 - Source files may not contain //go:build without // +build.
 - Builds fail when a source file contains //go:build lines without // +build lines. <<<

Go 1.17: start transition
 - Builds prefer //go:build for file selection, falling back to // +build
   for files containing only // +build.
 - Source files may contain //go:build without // +build (but they won't build with Go 1.16).
 - Gofmt moves //go:build and // +build lines to proper file locations.
 - Gofmt introduces //go:build lines into files with only // +build lines.
 - Go vet rejects files with mismatched //go:build and // +build lines.

Go 1.18: complete transition
 - Go fix removes // +build lines, leaving behind equivalent // +build lines.

This CL provides part of the <<< marked line above in the Go 1.16 step:
rejecting files containing //go:build but not // +build.
The standard go command checks only consider the top of the file.
This compiler check, along with a separate go vet check for ignored files,
handles the remainder of the file.

For #41184.

Change-Id: I014006eebfc84ab5943de18bc90449e534f150a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/240601
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
gopherbot pushed a commit that referenced this issue Oct 13, 2020
We are converting from using error-prone ad-hoc syntax // +build lines
to less error-prone, standard boolean syntax //go:build lines.
The timeline is:

Go 1.16: prepare for transition
 - Builds still use // +build for file selection.
 - Source files may not contain //go:build without // +build.
 - Builds fail when a source file contains //go:build lines without // +build lines. <<<

Go 1.17: start transition
 - Builds prefer //go:build for file selection, falling back to // +build
   for files containing only // +build.
 - Source files may contain //go:build without // +build (but they won't build with Go 1.16).
 - Gofmt moves //go:build and // +build lines to proper file locations.
 - Gofmt introduces //go:build lines into files with only // +build lines.
 - Go vet rejects files with mismatched //go:build and // +build lines.

Go 1.18: complete transition
 - Go fix removes // +build lines, leaving behind equivalent // +build lines.

This CL provides part of the <<< marked line above in the Go 1.16 step:
rejecting files containing //go:build but not // +build.

Reject any //go:build comments found after actual assembler code
(include #include etc directives), because the go command itself
doesn't read that far.

For #41184.

Change-Id: Ib460bfd380cce4239993980dd208afd07deff3f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/240602
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
gopherbot pushed a commit that referenced this issue Oct 13, 2020
We are converting from using error-prone ad-hoc syntax // +build lines
to less error-prone, standard boolean syntax //go:build lines.
The timeline is:

Go 1.16: prepare for transition
 - Builds still use // +build for file selection.
 - Source files may not contain //go:build without // +build.
 - Builds fail when a source file contains //go:build lines without // +build lines. <<<

Go 1.17: start transition
 - Builds prefer //go:build for file selection, falling back to // +build
   for files containing only // +build.
 - Source files may contain //go:build without // +build (but they won't build with Go 1.16).
 - Gofmt moves //go:build and // +build lines to proper file locations.
 - Gofmt introduces //go:build lines into files with only // +build lines.
 - Go vet rejects files with mismatched //go:build and // +build lines.

Go 1.18: complete transition
 - Go fix removes // +build lines, leaving behind equivalent // +build lines.

This CL provides part of the <<< marked line above in the Go 1.16 step:
rejecting files containing //go:build but not // +build.

For #41184.

Change-Id: I29b8a789ab1526ab5057f613d5533bd2060ba9cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/240600
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 13, 2020

Change https://golang.org/cl/261958 mentions this issue: cmd: go get golang.org/x/tools@d88ec18 && go mod vendor

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 16, 2020

Change https://golang.org/cl/240607 mentions this issue: go/build: prefer //go:build over // +build lines

gopherbot pushed a commit that referenced this issue Jan 8, 2021
This package implements a parser for the new //go:build constraint lines.
The parser also handles // +build lines, to be able to process legacy files.

This will not be used in the standard library until Go 1.17,
but it seems worth publishing in Go 1.16 so that code that
needs to process both kinds of lines once Go 1.17 comes out
will be able to build using Go 1.16 as well.

For #41184. Design in https://golang.org/design/draft-gobuild.

Change-Id: I756c0de4081c5039e8b7397200e5274f223ab111
Reviewed-on: https://go-review.googlesource.com/c/go/+/240604
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@dmitshur dmitshur mentioned this issue Jan 27, 2021
469 of 481 tasks complete
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 27, 2021

Change https://golang.org/cl/287412 mentions this issue: api/go1.16: add build/constraint APIs

gopherbot pushed a commit that referenced this issue Jan 27, 2021
These APIs were added in CL 240604 as part of an approved proposal. It
was submitted after the initial api/go1.16.txt creation.

For #41184
For #43407

Change-Id: Ifb54df2b61c554c32bd9d17afbb74f4e42e0b228
Reviewed-on: https://go-review.googlesource.com/c/go/+/287412
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 27, 2021

Change https://golang.org/cl/287472 mentions this issue: doc/go1.16: document go/build/constraint package

gopherbot pushed a commit that referenced this issue Jan 28, 2021
For #40700
For #41184
Fixes #43957

Change-Id: Ia346f4cf160431b721efeba7dc5f1fb8814efd95
Reviewed-on: https://go-review.googlesource.com/c/go/+/287472
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 17, 2021

Change https://golang.org/cl/240611 mentions this issue: cmd/fix: add buildtag fix

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 19, 2021

Change https://golang.org/cl/294430 mentions this issue: all: go fmt std cmd (but revert vendor)

gopherbot pushed a commit that referenced this issue Feb 20, 2021
Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

- Reject files with multiple //go:build lines.
- If a file has both //go:build and // +build lines, only use the //go:build line.
- Otherwise fall back to // +build lines
- Use go/build/constraint for parsing both //go:build and // +build lines.

For Go 1.17.

Change-Id: I32e2404d8ce266230f767718dc7cc24e77b425e8
Reviewed-on: https://go-review.googlesource.com/c/go/+/240607
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
gopherbot pushed a commit that referenced this issue Feb 20, 2021
Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Gofmt and any other go/printer-using program will now:

 - move //go:build and //+build lines to the appropriate file location
 - if there's no //go:build line, add one derived from the // +build lines
 - if there is a //go:build line, recompute and replace any // +build lines
   to match what the //go:build line says

For Go 1.17.

Change-Id: Ide5cc3b4a07507ba9ed6f8b0de846e840876f49f
Reviewed-on: https://go-review.googlesource.com/c/go/+/240608
Trust: Russ Cox <rsc@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
gopherbot pushed a commit that referenced this issue Feb 20, 2021
Brings in golang.org/x/tools@2363391a
and adjusts, adds cmd/vet tests accordingly.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

This brings in the new //go:build checks in cmd/vet.

Change-Id: I8a9735cc014171691012b307ec30e94c81aadfe1
Reviewed-on: https://go-review.googlesource.com/c/go/+/240609
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
gopherbot pushed a commit that referenced this issue Feb 20, 2021
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/294430
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@zephyr
Copy link

@zephyr zephyr commented Feb 20, 2021

How will this effect the Go1.4-bootstrap once the transition will be finalized in Go 1.18?

I just took master@d4b2638234 and crudely removed all //+build lines:

$ find . -name '*.go' -exec sed -i '/\/\/ +build /d' {} \;

After that, i could no longer bootstrap master with go1.4:

dennis@inara:/opt/golang$ update-golang.py dennis
Building Go cmd/dist using /opt/golang1.4. (go1.4-bootstrap-20170531 linux/amd64)
# _/opt/golang/src/cmd/dist
cmd/dist/util_gccgo.go:9: useVFPv1 redeclared in this block
	previous declaration at cmd/dist/util_gc.go:11
cmd/dist/util_gccgo.go:11: useVFPv3 redeclared in this block
	previous declaration at cmd/dist/util_gc.go:15
cmd/dist/util_gccgo.go:13: useARMv6K redeclared in this block
	previous declaration at cmd/dist/util_gc.go:20
Error: /opt/golang/src/make.bash returned

So should go/build/constraint be backported to Go1.4?

@rsc
Copy link
Contributor Author

@rsc rsc commented Feb 20, 2021

The compiler has to be kept building with Go 1.4 for now.
That means it has to keep its // +build comments.
I do plan to propose bumping the bootstrap version to Go 1.17,
though, for a variety of reasons, and after we've done that,
we'd be able to remove the // +build comments.

@rsc rsc modified the milestones: Go1.17, Go1.18 Feb 20, 2021
@rsc
Copy link
Contributor Author

@rsc rsc commented Feb 20, 2021

All the Go 1.17 prep work for //go:build lines is now landed.
I've remilestoned the issue to track the Go 1.18 work
(submitting golang.org/cl/240611).

tklauser added a commit to tklauser/sys that referenced this issue Feb 26, 2021
The //+go:build lines were added by running Go 1.17 gofmt in CL 294490.
Make sure to retain them when re-generating files in this package.

For golang/go#41184.

Change-Id: Ia418b8c0eb4291a0db3f4bb97685bde78d0ff016
tklauser added a commit to tklauser/sys that referenced this issue Feb 26, 2021
The //+go:build lines were added by running Go 1.17 gofmt in CL 294490.
Make sure to retain them when re-generating files in this package.

For golang/go#41184.

Change-Id: Ia418b8c0eb4291a0db3f4bb97685bde78d0ff016
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 26, 2021

Change https://golang.org/cl/296889 mentions this issue: unix: add //go:build lines when generating files

gopherbot pushed a commit to golang/sys that referenced this issue Mar 9, 2021
The //+go:build lines were added by running Go 1.17 gofmt in CL 294490.
Make sure to retain them when re-generating files in this package.

For golang/go#41184.

Change-Id: Ia418b8c0eb4291a0db3f4bb97685bde78d0ff016
Reviewed-on: https://go-review.googlesource.com/c/sys/+/296889
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Accepted
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants