@@ -18,7 +18,6 @@ package generator
1818
1919import (
2020 "go/token"
21- "path/filepath"
2221 "strings"
2322
2423 "k8s.io/klog/v2"
@@ -46,7 +45,7 @@ import (
4645func NewImportTrackerForPackage (local string , typesToAdd ... * types.Type ) * namer.DefaultImportTracker {
4746 tracker := namer .NewDefaultImportTracker (types.Name {Package : local })
4847 tracker .IsInvalidType = func (* types.Type ) bool { return false }
49- tracker .LocalName = func (name types.Name ) string { return goTrackerLocalName (& tracker , local , name ) }
48+ tracker .LocalName = func (name types.Name ) string { return goTrackerLocalName (& tracker , name ) }
5049 tracker .PrintImport = func (path , name string ) string { return name + " \" " + path + "\" " }
5150
5251 tracker .AddTypes (typesToAdd ... )
@@ -57,15 +56,14 @@ func NewImportTracker(typesToAdd ...*types.Type) *namer.DefaultImportTracker {
5756 return NewImportTrackerForPackage ("" , typesToAdd ... )
5857}
5958
60- func goTrackerLocalName (tracker namer.ImportTracker , localPkg string , t types.Name ) string {
59+ func goTrackerLocalName (tracker namer.ImportTracker , t types.Name ) string {
6160 path := t .Package
6261
6362 // Using backslashes in package names causes gengo to produce Go code which
6463 // will not compile with the gc compiler. See the comment on GoSeperator.
6564 if strings .ContainsRune (path , '\\' ) {
6665 klog .Warningf ("Warning: backslash used in import path '%v', this is unsupported.\n " , path )
6766 }
68- localLeaf := filepath .Base (localPkg )
6967
7068 dirs := strings .Split (path , namer .GoSeperator )
7169 for n := len (dirs ) - 1 ; n >= 0 ; n -- {
@@ -76,13 +74,8 @@ func goTrackerLocalName(tracker namer.ImportTracker, localPkg string, t types.Na
7674 // packages, but aren't legal go names. So we'll sanitize.
7775 name = strings .ReplaceAll (name , "." , "" )
7876 name = strings .ReplaceAll (name , "-" , "" )
79- if _ , found := tracker .PathOf (name ); found || name == localLeaf {
80- // This name collides with some other package.
81- // Or, this name is tne same name as the local package,
82- // which we avoid because it can be confusing. For example,
83- // if the local package is v1, we to avoid importing
84- // another package using the v1 name, and instead import
85- // it with a more qualified name, such as metav1.
77+ if _ , found := tracker .PathOf (name ); found {
78+ // This name collides with some other package
8679 continue
8780 }
8881
0 commit comments