Skip to content

Commit

Permalink
quic: add go1.21 build constraint
Browse files Browse the repository at this point in the history
This package will add on crypto/tls features added in Go 1.21,
so use a build constraint to restrict ourselves to that version.

Unlocks the ability to use other features from Go versions more recent
than what's in x/net's go.mod file.

For golang/go#58547

Change-Id: I14011c7506b047e389d9b3e995c0bafcd5e74d44
Reviewed-on: https://go-review.googlesource.com/c/net/+/499283
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
neild committed May 31, 2023
1 parent f7250ea commit f16447c
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/quic/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
51 changes: 51 additions & 0 deletions internal/quic/files_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
"bytes"
"os"
"strings"
"testing"
)

// TestFiles checks that every file in this package has a build constraint on Go 1.21.
//
// The QUIC implementation depends on crypto/tls features added in Go 1.21,
// so there's no point in trying to build on anything older.
//
// Drop this test when the x/net go.mod depends on 1.21 or newer.
func TestFiles(t *testing.T) {
f, err := os.Open(".")
if err != nil {
t.Fatal(err)
}
names, err := f.Readdirnames(-1)
if err != nil {
t.Fatal(err)
}
for _, name := range names {
if !strings.HasSuffix(name, ".go") {
continue
}
b, err := os.ReadFile(name)
if err != nil {
t.Fatal(err)
}
// Check for copyright header while we're in here.
if !bytes.Contains(b, []byte("The Go Authors.")) {
t.Errorf("%v: missing copyright", name)
}
// doc.go doesn't need a build constraint.
if name == "doc.go" {
continue
}
if !bytes.Contains(b, []byte("//go:build go1.21")) {
t.Errorf("%v: missing constraint on go1.21", name)
}
}
}
2 changes: 2 additions & 0 deletions internal/quic/frame_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

// packetType is a QUIC packet type.
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

// A packetNumber is a QUIC packet number.
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/packet_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/rangeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

// A rangeset is a set of int64s, stored as an ordered list of non-overlapping,
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/rangeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down
4 changes: 3 additions & 1 deletion internal/quic/sent_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down Expand Up @@ -32,7 +34,7 @@ type sentPacket struct {
}

var sentPool = sync.Pool{
New: func() interface{} {
New: func() any {
return &sentPacket{}
},
}
Expand Down
4 changes: 3 additions & 1 deletion internal/quic/sent_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import "testing"

func TestSentPacket(t *testing.T) {
frames := []interface{}{
frames := []any{
byte(frameTypePing),
byte(frameTypeStreamBase),
uint64(1),
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/sent_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

// A sentVal tracks sending some piece of information to the peer.
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/sent_val_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import "testing"
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import "encoding/binary"
Expand Down
2 changes: 2 additions & 0 deletions internal/quic/wire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
Expand Down

0 comments on commit f16447c

Please sign in to comment.