From de2039479091b6515f182267d2d8046dc11c1531 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 17 Aug 2021 10:38:27 -0700 Subject: [PATCH] deepcopy: gen: match Go 1.17 build tag format The Go team has started the process of replacing the old "// +build" constraints with the new "//go:build" constraints. See the design doc for more details here: https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md What is relevant is that in Go 1.17, gofmt now synchronizes the two styles. In particular, if gofmt is run against a deepcopy generated file, it will add a new "//go:build" constraint. See https://golang.org/doc/go1.17#gofmt for details. This PR intends to make it so that the generated code is compliant with the new gofmt style. --- pkg/deepcopy/gen.go | 3 ++- pkg/deepcopy/testdata/zz_generated.deepcopy.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/deepcopy/gen.go b/pkg/deepcopy/gen.go index 54a72363b..7e674a80a 100644 --- a/pkg/deepcopy/gen.go +++ b/pkg/deepcopy/gen.go @@ -175,7 +175,8 @@ type ObjectGenCtx struct { // writeHeader writes out the build tag, package declaration, and imports func writeHeader(pkg *loader.Package, out io.Writer, packageName string, imports *importsList, headerText string) { // NB(directxman12): blank line after build tags to distinguish them from comments - _, err := fmt.Fprintf(out, `// +build !ignore_autogenerated + _, err := fmt.Fprintf(out, `//go:build !ignore_autogenerated +// +build !ignore_autogenerated %[3]s diff --git a/pkg/deepcopy/testdata/zz_generated.deepcopy.go b/pkg/deepcopy/testdata/zz_generated.deepcopy.go index 837147e78..825f1a4fd 100644 --- a/pkg/deepcopy/testdata/zz_generated.deepcopy.go +++ b/pkg/deepcopy/testdata/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated // Code generated by controller-gen. DO NOT EDIT.