Skip to content

Commit

Permalink
Use generator.NewImportTrackerForPackage for all generators to preven…
Browse files Browse the repository at this point in the history
…t generation of import to package being generated

Co-authored-by: Tim Hockin <thockin@google.com>
  • Loading branch information
jpbetz and thockin committed Sep 3, 2024
1 parent d5555af commit 1606be6
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir
localPkg: outputPkg,
groupVersion: gv,
applyConfig: toGenerate,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
refGraph: refs,
openAPIType: openAPIType,
})
Expand All @@ -211,7 +211,7 @@ func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, gro
OutputFilename: "utils.go",
},
outputPackage: outputPkgBase,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkgBase),
groupVersions: groupVersions,
typesForGroupVersion: applyConfigsForGroupVersion,
groupGoNames: groupGoNames,
Expand All @@ -236,7 +236,7 @@ func targetForInternal(outputDirBase, outputPkgBase string, boilerplate []byte,
OutputFilename: "internal.go",
},
outputPackage: outputPkgBase,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
typeModels: models,
})
return generators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
version: gv.Version.String(),
groupGoName: groupGoName,
typeToMatch: t,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(gvPkg),
})
}

Expand All @@ -177,7 +177,7 @@ func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
groupGoName: groupGoName,
apiPath: apiPath,
types: typeList,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(gvPkg),
})

expansionFileName := "generated_expansion.go"
Expand Down Expand Up @@ -214,7 +214,7 @@ func targetForClientset(args *args.Args, clientsetDir, clientsetPkg string, grou
groups: args.Groups,
groupGoNames: groupGoNames,
clientsetPackage: clientsetPkg,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(clientsetPkg),
},
}
return generators
Expand Down Expand Up @@ -260,7 +260,7 @@ NextGroup:
OutputPath: schemeDir,
Groups: args.Groups,
GroupGoNames: groupGoNames,
ImportTracker: generator.NewImportTracker(),
ImportTracker: generator.NewImportTrackerForPackage(schemePkg),
CreateRegistry: internalClient,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
version: gv.Version.String(),
groupGoName: groupGoName,
typeToMatch: t,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
applyConfigurationPackage: applyBuilderPackage,
})
}
Expand All @@ -78,7 +78,7 @@ func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
version: gv.Version.String(),
groupGoName: groupGoName,
types: typeList,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
})
return generators
},
Expand Down Expand Up @@ -111,7 +111,7 @@ func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, appl
groups: args.Groups,
groupGoNames: groupGoNames,
fakeClientsetPackage: clientsetPkg,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(clientsetPkg),
realClientsetPackage: clientsetPkg,
applyConfigurationPackage: applyConfigurationPkg,
},
Expand All @@ -123,7 +123,7 @@ func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, appl
OutputPkg: clientsetPkg,
Groups: args.Groups,
GroupGoNames: groupGoNames,
ImportTracker: generator.NewImportTracker(),
ImportTracker: generator.NewImportTrackerForPackage(clientsetPkg),
PrivateScheme: true,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
"fakediscovery \"k8s.io/client-go/discovery/fake\"",
"k8s.io/apimachinery/pkg/runtime",
"k8s.io/apimachinery/pkg/watch",
"k8s.io/apimachinery/pkg/api/meta/testrestmapper",
)

return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func NewGenConversion(outputFilename, typesPackage, outputPackage string, manual
outputPackage: outputPackage,
peerPackages: peerPkgs,
manualConversions: manualConversions,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPackage),
types: []*types.Type{},
explicitConversions: []conversionPair{},
skippedFields: map[*types.Type][]string{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func NewGenDeepCopy(outputFilename, targetPackage string, boundingDirs []string,
boundingDirs: boundingDirs,
allTypes: allTypes,
registerTypes: registerTypes,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(targetPackage),
typesForInit: make([]*types.Type, 0),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func factoryTarget(outputDirBase, outputPkgBase string, boilerplate []byte, grou
OutputFilename: "factory.go",
},
outputPackage: outputPkgBase,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkgBase),
groupVersions: groupVersions,
clientSetPackage: clientSetPackage,
internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces),
Expand All @@ -261,7 +261,7 @@ func factoryTarget(outputDirBase, outputPkgBase string, boilerplate []byte, grou
OutputFilename: "generic.go",
},
outputPackage: outputPkgBase,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkgBase),
groupVersions: groupVersions,
pluralExceptions: pluralExceptions,
typesForGroupVersion: typesForGroupVersion,
Expand All @@ -288,7 +288,7 @@ func factoryInterfaceTarget(outputDirBase, outputPkgBase string, boilerplate []b
OutputFilename: "factory_interfaces.go",
},
outputPackage: outputPkg,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
clientSetPackage: clientSetPackage,
})

Expand All @@ -314,7 +314,7 @@ func groupTarget(outputDirBase, outputPackageBase string, groupVersions clientge
},
outputPackage: outputPkg,
groupVersions: groupVersions,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
internalInterfacesPackage: path.Join(outputPackageBase, subdirForInternalInterfaces),
})
return generators
Expand Down Expand Up @@ -342,7 +342,7 @@ func versionTarget(outputDirBase, outputPkgBase string, groupPkgName string, gv
OutputFilename: "interface.go",
},
outputPackage: outputPkg,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
types: typesToGenerate,
internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces),
})
Expand All @@ -357,7 +357,7 @@ func versionTarget(outputDirBase, outputPkgBase string, groupPkgName string, gv
groupVersion: gv,
groupGoName: groupGoName,
typeToGenerate: t,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
clientSetPackage: clientSetPackage,
listersPackage: listersPackage,
internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
groupVersion: gv,
internalGVPkg: internalGVPkg,
typeToGenerate: t,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(outputPkg),
objectMeta: objectMeta,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
gv: gv,
typesToGenerate: typesToRegister,
outputPackage: pkg.Path,
imports: generator.NewImportTracker(),
imports: generator.NewImportTrackerForPackage(pkg.Path),
},
}
},
Expand Down

0 comments on commit 1606be6

Please sign in to comment.