Skip to content

Commit e65c543

Browse files
committed
go/build/constraint: add parser for build tag constraint expressions
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 <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Russ Cox <[email protected]> Trust: Jay Conrod <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 0c5afc4 commit e65c543

File tree

4 files changed

+896
-1
lines changed

4 files changed

+896
-1
lines changed

src/go/build/build_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestMatch(t *testing.T) {
2828
ctxt := Default
2929
what := "default"
3030
match := func(tag string, want map[string]bool) {
31+
t.Helper()
3132
m := make(map[string]bool)
3233
if !ctxt.match(tag, m) {
3334
t.Errorf("%s context should match %s, does not", what, tag)
@@ -37,6 +38,7 @@ func TestMatch(t *testing.T) {
3738
}
3839
}
3940
nomatch := func(tag string, want map[string]bool) {
41+
t.Helper()
4042
m := make(map[string]bool)
4143
if ctxt.match(tag, m) {
4244
t.Errorf("%s context should NOT match %s, does", what, tag)
@@ -57,7 +59,6 @@ func TestMatch(t *testing.T) {
5759
nomatch(runtime.GOOS+","+runtime.GOARCH+",!foo", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "foo": true})
5860
match(runtime.GOOS+","+runtime.GOARCH+",!bar", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "bar": true})
5961
nomatch(runtime.GOOS+","+runtime.GOARCH+",bar", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "bar": true})
60-
nomatch("!", map[string]bool{})
6162
}
6263

6364
func TestDotSlashImport(t *testing.T) {

0 commit comments

Comments
 (0)