mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Bump gengo/v2 to pick up FormatOnly setting for imports
Co-authored-by: Tim Hockin <thockin@google.com>
This commit is contained in:
9
vendor/k8s.io/gengo/v2/generator/execute.go
generated
vendored
9
vendor/k8s.io/gengo/v2/generator/execute.go
generated
vendored
@@ -26,6 +26,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/imports"
|
||||
|
||||
"k8s.io/gengo/v2/namer"
|
||||
"k8s.io/gengo/v2/types"
|
||||
"k8s.io/klog/v2"
|
||||
@@ -114,7 +115,13 @@ func assembleGoFile(w io.Writer, f *File) {
|
||||
}
|
||||
|
||||
func importsWrapper(src []byte) ([]byte, error) {
|
||||
return imports.Process("", src, nil)
|
||||
opt := imports.Options{
|
||||
Comments: true,
|
||||
TabIndent: true,
|
||||
TabWidth: 8,
|
||||
FormatOnly: true, // Disable the insertion and deletion of imports
|
||||
}
|
||||
return imports.Process("", src, &opt)
|
||||
}
|
||||
|
||||
func NewGoFile() *DefaultFileType {
|
||||
|
||||
15
vendor/k8s.io/gengo/v2/generator/import_tracker.go
generated
vendored
15
vendor/k8s.io/gengo/v2/generator/import_tracker.go
generated
vendored
@@ -18,6 +18,7 @@ package generator
|
||||
|
||||
import (
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
@@ -45,7 +46,7 @@ import (
|
||||
func NewImportTrackerForPackage(local string, typesToAdd ...*types.Type) *namer.DefaultImportTracker {
|
||||
tracker := namer.NewDefaultImportTracker(types.Name{Package: local})
|
||||
tracker.IsInvalidType = func(*types.Type) bool { return false }
|
||||
tracker.LocalName = func(name types.Name) string { return goTrackerLocalName(&tracker, name) }
|
||||
tracker.LocalName = func(name types.Name) string { return goTrackerLocalName(&tracker, local, name) }
|
||||
tracker.PrintImport = func(path, name string) string { return name + " \"" + path + "\"" }
|
||||
|
||||
tracker.AddTypes(typesToAdd...)
|
||||
@@ -56,7 +57,7 @@ func NewImportTracker(typesToAdd ...*types.Type) *namer.DefaultImportTracker {
|
||||
return NewImportTrackerForPackage("", typesToAdd...)
|
||||
}
|
||||
|
||||
func goTrackerLocalName(tracker namer.ImportTracker, t types.Name) string {
|
||||
func goTrackerLocalName(tracker namer.ImportTracker, localPkg string, t types.Name) string {
|
||||
path := t.Package
|
||||
|
||||
// Using backslashes in package names causes gengo to produce Go code which
|
||||
@@ -64,6 +65,7 @@ func goTrackerLocalName(tracker namer.ImportTracker, t types.Name) string {
|
||||
if strings.ContainsRune(path, '\\') {
|
||||
klog.Warningf("Warning: backslash used in import path '%v', this is unsupported.\n", path)
|
||||
}
|
||||
localLeaf := filepath.Base(localPkg)
|
||||
|
||||
dirs := strings.Split(path, namer.GoSeperator)
|
||||
for n := len(dirs) - 1; n >= 0; n-- {
|
||||
@@ -74,8 +76,13 @@ func goTrackerLocalName(tracker namer.ImportTracker, t types.Name) string {
|
||||
// packages, but aren't legal go names. So we'll sanitize.
|
||||
name = strings.ReplaceAll(name, ".", "")
|
||||
name = strings.ReplaceAll(name, "-", "")
|
||||
if _, found := tracker.PathOf(name); found {
|
||||
// This name collides with some other package
|
||||
if _, found := tracker.PathOf(name); found || name == localLeaf {
|
||||
// This name collides with some other package.
|
||||
// Or, this name is tne same name as the local package,
|
||||
// which we avoid because it can be confusing. For example,
|
||||
// if the local package is v1, we to avoid importing
|
||||
// another package using the v1 name, and instead import
|
||||
// it with a more qualified name, such as metav1.
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -1119,7 +1119,7 @@ gopkg.in/yaml.v3
|
||||
## explicit; go 1.22.0
|
||||
# k8s.io/endpointslice v0.0.0 => ./staging/src/k8s.io/endpointslice
|
||||
## explicit; go 1.22.0
|
||||
# k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7
|
||||
# k8s.io/gengo/v2 v2.0.0-20240903080316-fb7743ff00a0
|
||||
## explicit; go 1.20
|
||||
k8s.io/gengo/v2
|
||||
k8s.io/gengo/v2/generator
|
||||
|
||||
Reference in New Issue
Block a user