Use path instead of filepath for pkg-paths

This commit is contained in:
Tim Hockin 2024-02-28 14:38:03 -08:00
parent 70d803c1ff
commit ac5664086b
No known key found for this signature in database
18 changed files with 69 additions and 71 deletions

View File

@ -18,7 +18,7 @@ package generators
import ( import (
"io" "io"
"path/filepath" "path"
"strings" "strings"
"k8s.io/gengo/v2/generator" "k8s.io/gengo/v2/generator"
@ -49,7 +49,7 @@ func (g *applyConfigurationGenerator) Filter(_ *generator.Context, t *types.Type
} }
func (g *applyConfigurationGenerator) Namers(*generator.Context) namer.NameSystems { func (g *applyConfigurationGenerator) Namers(*generator.Context) namer.NameSystems {
localPkg := filepath.Join(g.outPkgBase, g.groupVersion.Group.PackageName(), g.groupVersion.Version.PackageName()) localPkg := path.Join(g.outPkgBase, g.groupVersion.Group.PackageName(), g.groupVersion.Version.PackageName())
return namer.NameSystems{ return namer.NameSystems{
"raw": namer.NewRawNamer(localPkg, g.imports), "raw": namer.NewRawNamer(localPkg, g.imports),
"singularKind": namer.NewPublicNamer(0), "singularKind": namer.NewPublicNamer(0),
@ -92,7 +92,7 @@ func (g *applyConfigurationGenerator) GenerateType(c *generator.Context, t *type
Tags: genclientTags(t), Tags: genclientTags(t),
APIVersion: g.groupVersion.ToAPIVersion(), APIVersion: g.groupVersion.ToAPIVersion(),
ExtractInto: extractInto, ExtractInto: extractInto,
ParserFunc: types.Ref(filepath.Join(g.outPkgBase, "internal"), "Parser"), ParserFunc: types.Ref(path.Join(g.outPkgBase, "internal"), "Parser"),
OpenAPIType: g.openAPIType, OpenAPIType: g.openAPIType,
} }

View File

@ -161,7 +161,7 @@ func typeName(t *types.Type) string {
func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir string, boilerplate []byte, gv clientgentypes.GroupVersion, typesToGenerate []applyConfig, refs refGraph, models *typeModels) generator.Target { func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir string, boilerplate []byte, gv clientgentypes.GroupVersion, typesToGenerate []applyConfig, refs refGraph, models *typeModels) generator.Target {
outputDir := filepath.Join(outputDirBase, pkgSubdir) outputDir := filepath.Join(outputDirBase, pkgSubdir)
outputPkg := filepath.Join(outputPkgBase, pkgSubdir) outputPkg := path.Join(outputPkgBase, pkgSubdir)
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: gv.Version.PackageName(), PkgName: gv.Version.PackageName(),
@ -199,7 +199,7 @@ func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir
func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, groupVersions map[string]clientgentypes.GroupVersions, applyConfigsForGroupVersion map[clientgentypes.GroupVersion][]applyConfig, groupGoNames map[string]string) generator.Target { func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, groupVersions map[string]clientgentypes.GroupVersions, applyConfigsForGroupVersion map[clientgentypes.GroupVersion][]applyConfig, groupGoNames map[string]string) generator.Target {
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: filepath.Base(outputPkgBase), PkgName: path.Base(outputPkgBase),
PkgPath: outputPkgBase, PkgPath: outputPkgBase,
PkgDir: outputDirBase, PkgDir: outputDirBase,
HeaderComment: boilerplate, HeaderComment: boilerplate,
@ -221,9 +221,9 @@ func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, gro
func targetForInternal(outputDirBase, outputPkgBase string, boilerplate []byte, models *typeModels) generator.Target { func targetForInternal(outputDirBase, outputPkgBase string, boilerplate []byte, models *typeModels) generator.Target {
outputDir := filepath.Join(outputDirBase, "internal") outputDir := filepath.Join(outputDirBase, "internal")
outputPkg := filepath.Join(outputPkgBase, "internal") outputPkg := path.Join(outputPkgBase, "internal")
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: filepath.Base(outputPkg), PkgName: path.Base(outputPkg),
PkgPath: outputPkg, PkgPath: outputPkg,
PkgDir: outputDir, PkgDir: outputDir,
HeaderComment: boilerplate, HeaderComment: boilerplate,
@ -263,7 +263,7 @@ func packageTypesForInputs(context *generator.Context, outPkgBase string) map[st
// For example, if openshift/api/cloudnetwork/v1 contains an apigroup cloud.network.openshift.io, the client-gen // For example, if openshift/api/cloudnetwork/v1 contains an apigroup cloud.network.openshift.io, the client-gen
// builds a package called cloudnetwork/v1 to contain it. This change makes the applyconfiguration-gen use the same. // builds a package called cloudnetwork/v1 to contain it. This change makes the applyconfiguration-gen use the same.
_, gvPackageString := util.ParsePathGroupVersion(p.Path) _, gvPackageString := util.ParsePathGroupVersion(p.Path)
pkg := filepath.Join(outPkgBase, strings.ToLower(gvPackageString)) pkg := path.Join(outPkgBase, strings.ToLower(gvPackageString))
pkgTypes[pkg] = p pkgTypes[pkg] = p
} }
return pkgTypes return pkgTypes

View File

@ -19,6 +19,7 @@ package generators
import ( import (
"fmt" "fmt"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -128,9 +129,9 @@ func DefaultNameSystem() string {
} }
func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetDir, clientsetPkg string, groupPkgName string, groupGoName string, apiPath string, inputPkg string, applyBuilderPkg string, boilerplate []byte) generator.Target { func targetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetDir, clientsetPkg string, groupPkgName string, groupGoName string, apiPath string, inputPkg string, applyBuilderPkg string, boilerplate []byte) generator.Target {
subdir := filepath.Join("typed", strings.ToLower(groupPkgName), strings.ToLower(gv.Version.NonEmpty())) subdir := []string{"typed", strings.ToLower(groupPkgName), strings.ToLower(gv.Version.NonEmpty())}
gvDir := filepath.Join(clientsetDir, subdir) gvDir := filepath.Join(clientsetDir, filepath.Join(subdir...))
gvPkg := filepath.Join(clientsetPkg, subdir) gvPkg := path.Join(clientsetPkg, path.Join(subdir...))
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: strings.ToLower(gv.Version.NonEmpty()), PkgName: strings.ToLower(gv.Version.NonEmpty()),
@ -223,7 +224,7 @@ func targetForClientset(args *args.Args, clientsetDir, clientsetPkg string, grou
func targetForScheme(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target { func targetForScheme(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target {
schemeDir := filepath.Join(clientsetDir, "scheme") schemeDir := filepath.Join(clientsetDir, "scheme")
schemePkg := filepath.Join(clientsetPkg, "scheme") schemePkg := path.Join(clientsetPkg, "scheme")
// create runtime.Registry for internal client because it has to know about group versions // create runtime.Registry for internal client because it has to know about group versions
internalClient := false internalClient := false
@ -394,7 +395,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
} }
clientsetDir := filepath.Join(args.OutputDir, args.ClientsetName) clientsetDir := filepath.Join(args.OutputDir, args.ClientsetName)
clientsetPkg := filepath.Join(args.OutputPkg, args.ClientsetName) clientsetPkg := path.Join(args.OutputPkg, args.ClientsetName)
var targetList []generator.Target var targetList []generator.Target

View File

@ -17,6 +17,7 @@ limitations under the License.
package fake package fake
import ( import (
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -31,10 +32,10 @@ import (
func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetDir, clientsetPkg string, groupPkgName string, groupGoName string, inputPkg string, applyBuilderPackage string, boilerplate []byte) generator.Target { func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetDir, clientsetPkg string, groupPkgName string, groupGoName string, inputPkg string, applyBuilderPackage string, boilerplate []byte) generator.Target {
// TODO: should make this a function, called by here and in client-generator.go // TODO: should make this a function, called by here and in client-generator.go
subdir := filepath.Join("typed", strings.ToLower(groupPkgName), strings.ToLower(gv.Version.NonEmpty())) subdir := []string{"typed", strings.ToLower(groupPkgName), strings.ToLower(gv.Version.NonEmpty())}
outputDir := filepath.Join(clientsetDir, subdir, "fake") outputDir := filepath.Join(clientsetDir, filepath.Join(subdir...), "fake")
outputPkg := filepath.Join(clientsetPkg, subdir, "fake") outputPkg := path.Join(clientsetPkg, path.Join(subdir...), "fake")
realClientPkg := filepath.Join(clientsetPkg, subdir) realClientPkg := path.Join(clientsetPkg, path.Join(subdir...))
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: "fake", PkgName: "fake",
@ -92,7 +93,7 @@ func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, grou
// TODO: we'll generate fake clientset for different release in the future. // TODO: we'll generate fake clientset for different release in the future.
// Package name and path are hard coded for now. // Package name and path are hard coded for now.
PkgName: "fake", PkgName: "fake",
PkgPath: filepath.Join(clientsetPkg, "fake"), PkgPath: path.Join(clientsetPkg, "fake"),
PkgDir: filepath.Join(clientsetDir, "fake"), PkgDir: filepath.Join(clientsetDir, "fake"),
HeaderComment: boilerplate, HeaderComment: boilerplate,
PkgDocComment: []byte("// This package has the automatically generated fake clientset.\n"), PkgDocComment: []byte("// This package has the automatically generated fake clientset.\n"),

View File

@ -19,7 +19,7 @@ package fake
import ( import (
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"strings" "strings"
clientgentypes "k8s.io/code-generator/cmd/client-gen/types" clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
@ -59,8 +59,8 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
imports = append(imports, g.imports.ImportLines()...) imports = append(imports, g.imports.ImportLines()...)
for _, group := range g.groups { for _, group := range g.groups {
for _, version := range group.Versions { for _, version := range group.Versions {
groupClientPackage := filepath.Join(g.fakeClientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty())) groupClientPackage := path.Join(g.fakeClientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty()))
fakeGroupClientPackage := filepath.Join(groupClientPackage, "fake") fakeGroupClientPackage := path.Join(groupClientPackage, "fake")
groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}]) groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}])
imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), groupClientPackage)) imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), groupClientPackage))

View File

@ -19,7 +19,7 @@ package fake
import ( import (
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"strings" "strings"
"k8s.io/gengo/v2/generator" "k8s.io/gengo/v2/generator"
@ -64,7 +64,7 @@ func (g *genFakeForGroup) Namers(c *generator.Context) namer.NameSystems {
func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) { func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) {
imports = g.imports.ImportLines() imports = g.imports.ImportLines()
if len(g.types) != 0 { if len(g.types) != 0 {
imports = append(imports, fmt.Sprintf("%s \"%s\"", strings.ToLower(filepath.Base(g.realClientPackage)), g.realClientPackage)) imports = append(imports, fmt.Sprintf("%s \"%s\"", strings.ToLower(path.Base(g.realClientPackage)), g.realClientPackage))
} }
return imports return imports
} }
@ -90,7 +90,7 @@ func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io
"type": t, "type": t,
"GroupGoName": g.groupGoName, "GroupGoName": g.groupGoName,
"Version": namer.IC(g.version), "Version": namer.IC(g.version),
"realClientPackage": strings.ToLower(filepath.Base(g.realClientPackage)), "realClientPackage": strings.ToLower(path.Base(g.realClientPackage)),
} }
if tags.NonNamespaced { if tags.NonNamespaced {
sw.Do(getterImplNonNamespaced, wrapper) sw.Do(getterImplNonNamespaced, wrapper)

View File

@ -18,7 +18,7 @@ package fake
import ( import (
"io" "io"
"path/filepath" "path"
"strings" "strings"
"k8s.io/gengo/v2/generator" "k8s.io/gengo/v2/generator"
@ -86,7 +86,7 @@ func hasObjectMeta(t *types.Type) bool {
// GenerateType makes the body of a file implementing the individual typed client for type t. // GenerateType makes the body of a file implementing the individual typed client for type t.
func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$") sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package) pkg := path.Base(t.Name.Package)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil { if err != nil {
return err return err
@ -152,7 +152,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
if generateApply { if generateApply {
// Generated apply builder type references required for generated Apply function // Generated apply builder type references required for generated Apply function
_, gvString := util.ParsePathGroupVersion(g.inputPackage) _, gvString := util.ParsePathGroupVersion(g.inputPackage)
m["inputApplyConfig"] = types.Ref(filepath.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration") m["inputApplyConfig"] = types.Ref(path.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration")
} }
if tags.NonNamespaced { if tags.NonNamespaced {
@ -236,7 +236,7 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
m["resultType"] = &resultType m["resultType"] = &resultType
m["subresourcePath"] = e.SubResourcePath m["subresourcePath"] = e.SubResourcePath
if e.HasVerb("apply") { if e.HasVerb("apply") {
m["inputApplyConfig"] = types.Ref(filepath.Join(g.applyConfigurationPackage, inputGVString), inputType.Name.Name+"ApplyConfiguration") m["inputApplyConfig"] = types.Ref(path.Join(g.applyConfigurationPackage, inputGVString), inputType.Name.Name+"ApplyConfiguration")
} }
if e.HasVerb("get") { if e.HasVerb("get") {

View File

@ -19,7 +19,7 @@ package generators
import ( import (
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"strings" "strings"
clientgentypes "k8s.io/code-generator/cmd/client-gen/types" clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
@ -57,7 +57,7 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
imports = append(imports, g.imports.ImportLines()...) imports = append(imports, g.imports.ImportLines()...)
for _, group := range g.groups { for _, group := range g.groups {
for _, version := range group.Versions { for _, version := range group.Versions {
typedClientPath := filepath.Join(g.clientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty())) typedClientPath := path.Join(g.clientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty()))
groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}]) groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}])
imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), typedClientPath)) imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), typedClientPath))
} }

View File

@ -18,7 +18,7 @@ package generators
import ( import (
"io" "io"
"path/filepath" "path"
"k8s.io/gengo/v2" "k8s.io/gengo/v2"
"k8s.io/gengo/v2/generator" "k8s.io/gengo/v2/generator"
@ -64,7 +64,7 @@ func (g *genGroup) Namers(c *generator.Context) namer.NameSystems {
func (g *genGroup) Imports(c *generator.Context) (imports []string) { func (g *genGroup) Imports(c *generator.Context) (imports []string) {
imports = append(imports, g.imports.ImportLines()...) imports = append(imports, g.imports.ImportLines()...)
imports = append(imports, filepath.Join(g.clientsetPackage, "scheme")) imports = append(imports, path.Join(g.clientsetPackage, "scheme"))
return return
} }

View File

@ -19,7 +19,6 @@ package generators
import ( import (
"io" "io"
"path" "path"
"path/filepath"
"strings" "strings"
"k8s.io/gengo/v2/generator" "k8s.io/gengo/v2/generator"
@ -81,7 +80,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
defaultVerbTemplates := buildDefaultVerbTemplates(generateApply) defaultVerbTemplates := buildDefaultVerbTemplates(generateApply)
subresourceDefaultVerbTemplates := buildSubresourceDefaultVerbTemplates(generateApply) subresourceDefaultVerbTemplates := buildSubresourceDefaultVerbTemplates(generateApply)
sw := generator.NewSnippetWriter(w, c, "$", "$") sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package) pkg := path.Base(t.Name.Package)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil { if err != nil {
return err return err
@ -171,7 +170,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
"ApplyPatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "ApplyPatchType"}), "ApplyPatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "ApplyPatchType"}),
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}), "watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}),
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}), "RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
"schemeParameterCodec": c.Universe.Variable(types.Name{Package: filepath.Join(g.clientsetPackage, "scheme"), Name: "ParameterCodec"}), "schemeParameterCodec": c.Universe.Variable(types.Name{Package: path.Join(g.clientsetPackage, "scheme"), Name: "ParameterCodec"}),
"jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}), "jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}),
} }

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -65,9 +66,9 @@ func (g *GenScheme) Imports(c *generator.Context) (imports []string) {
if g.CreateRegistry { if g.CreateRegistry {
// import the install package for internal clientsets instead of the type package with register.go // import the install package for internal clientsets instead of the type package with register.go
if version.Version != "" { if version.Version != "" {
packagePath = filepath.Dir(packagePath) packagePath = path.Dir(packagePath)
} }
packagePath = filepath.Join(packagePath, "install") packagePath = path.Join(packagePath, "install")
imports = append(imports, fmt.Sprintf("%s \"%s\"", groupAlias, packagePath)) imports = append(imports, fmt.Sprintf("%s \"%s\"", groupAlias, packagePath))
break break

View File

@ -20,7 +20,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"reflect" "reflect"
"sort" "sort"
"strings" "strings"
@ -319,7 +319,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
targets = append(targets, targets = append(targets,
&generator.SimpleTarget{ &generator.SimpleTarget{
PkgName: filepath.Base(pkg.Path), PkgName: path.Base(pkg.Path),
PkgPath: pkg.Path, PkgPath: pkg.Path,
PkgDir: pkg.Dir, // output pkg is the same as the input PkgDir: pkg.Dir, // output pkg is the same as the input
HeaderComment: boilerplate, HeaderComment: boilerplate,

View File

@ -19,7 +19,7 @@ package generators
import ( import (
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"sort" "sort"
"strings" "strings"
@ -184,7 +184,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
klog.V(3).Infof("Package %q needs generation", i) klog.V(3).Infof("Package %q needs generation", i)
targets = append(targets, targets = append(targets,
&generator.SimpleTarget{ &generator.SimpleTarget{
PkgName: strings.Split(filepath.Base(pkg.Path), ".")[0], PkgName: strings.Split(path.Base(pkg.Path), ".")[0],
PkgPath: pkg.Path, PkgPath: pkg.Path,
PkgDir: pkg.Dir, // output pkg is the same as the input PkgDir: pkg.Dir, // output pkg is the same as the input
HeaderComment: boilerplate, HeaderComment: boilerplate,

View File

@ -21,7 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"reflect" "reflect"
"regexp" "regexp"
"strconv" "strconv"
@ -256,7 +256,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
// this is a relative dir, which will not work under gomodules. // this is a relative dir, which will not work under gomodules.
// join with the local package path, but warn // join with the local package path, but warn
klog.Warningf("relative path %s=%s will not work under gomodule mode; use full package path (as used by 'import') instead", inputTagName, inputPath) klog.Warningf("relative path %s=%s will not work under gomodule mode; use full package path (as used by 'import') instead", inputTagName, inputPath)
inputPath = filepath.Join(pkg.Path, inputTags[0]) inputPath = path.Join(pkg.Path, inputTags[0])
} }
klog.V(5).Infof(" input pkg %v", inputPath) klog.V(5).Infof(" input pkg %v", inputPath)
@ -409,7 +409,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
targets = append(targets, targets = append(targets,
&generator.SimpleTarget{ &generator.SimpleTarget{
PkgName: filepath.Base(pkg.Path), PkgName: path.Base(pkg.Path),
PkgPath: pkg.Path, PkgPath: pkg.Path,
PkgDir: pkg.Dir, // output pkg is the same as the input PkgDir: pkg.Dir, // output pkg is the same as the input
HeaderComment: boilerplate, HeaderComment: boilerplate,

View File

@ -18,7 +18,7 @@ package generators
import ( import (
"io" "io"
"path/filepath" "path"
"strings" "strings"
clientgentypes "k8s.io/code-generator/cmd/client-gen/types" clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
@ -70,7 +70,7 @@ func (g *groupInterfaceGenerator) GenerateType(c *generator.Context, t *types.Ty
versions := make([]versionData, 0, len(g.groupVersions.Versions)) versions := make([]versionData, 0, len(g.groupVersions.Versions))
for _, version := range g.groupVersions.Versions { for _, version := range g.groupVersions.Versions {
gv := clientgentypes.GroupVersion{Group: g.groupVersions.Group, Version: version.Version} gv := clientgentypes.GroupVersion{Group: g.groupVersions.Group, Version: version.Version}
versionPackage := filepath.Join(g.outputPackage, strings.ToLower(gv.Version.NonEmpty())) versionPackage := path.Join(g.outputPackage, strings.ToLower(gv.Version.NonEmpty()))
iface := c.Universe.Type(types.Name{Package: versionPackage, Name: "Interface"}) iface := c.Universe.Type(types.Name{Package: versionPackage, Name: "Interface"})
versions = append(versions, versionData{ versions = append(versions, versionData{
Name: namer.IC(version.Version.NonEmpty()), Name: namer.IC(version.Version.NonEmpty()),

View File

@ -84,12 +84,7 @@ func isInternal(m types.Member) bool {
return !strings.Contains(m.Tags, "json") return !strings.Contains(m.Tags, "json")
} }
// subdirForInternalInterfaces returns a string which is a subdir of the const subdirForInternalInterfaces = "internalinterfaces"
// provided base, which can be a Go import-path or a directory path, depending
// on what the caller needs.
func subdirForInternalInterfaces(base string) string {
return filepath.Join(base, "internalinterfaces")
}
// GetTargets makes the client target definition. // GetTargets makes the client target definition.
func GetTargets(context *generator.Context, args *args.Args) []generator.Target { func GetTargets(context *generator.Context, args *args.Args) []generator.Target {
@ -104,9 +99,9 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
externalVersionOutputPkg := args.OutputPkg externalVersionOutputPkg := args.OutputPkg
if !args.SingleDirectory { if !args.SingleDirectory {
internalVersionOutputDir = filepath.Join(internalVersionOutputDir, "internalversion") internalVersionOutputDir = filepath.Join(internalVersionOutputDir, "internalversion")
internalVersionOutputPkg = filepath.Join(internalVersionOutputPkg, "internalversion") internalVersionOutputPkg = path.Join(internalVersionOutputPkg, "internalversion")
externalVersionOutputDir = filepath.Join(externalVersionOutputDir, "externalversions") externalVersionOutputDir = filepath.Join(externalVersionOutputDir, "externalversions")
externalVersionOutputPkg = filepath.Join(externalVersionOutputPkg, "externalversions") externalVersionOutputPkg = path.Join(externalVersionOutputPkg, "externalversions")
} }
var targetList []generator.Target var targetList []generator.Target
@ -244,7 +239,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
func factoryTarget(outputDirBase, outputPkgBase string, boilerplate []byte, groupGoNames, pluralExceptions map[string]string, groupVersions map[string]clientgentypes.GroupVersions, clientSetPackage string, func factoryTarget(outputDirBase, outputPkgBase string, boilerplate []byte, groupGoNames, pluralExceptions map[string]string, groupVersions map[string]clientgentypes.GroupVersions, clientSetPackage string,
typesForGroupVersion map[clientgentypes.GroupVersion][]*types.Type) generator.Target { typesForGroupVersion map[clientgentypes.GroupVersion][]*types.Type) generator.Target {
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: filepath.Base(outputDirBase), PkgName: path.Base(outputDirBase),
PkgPath: outputPkgBase, PkgPath: outputPkgBase,
PkgDir: outputDirBase, PkgDir: outputDirBase,
HeaderComment: boilerplate, HeaderComment: boilerplate,
@ -257,7 +252,7 @@ func factoryTarget(outputDirBase, outputPkgBase string, boilerplate []byte, grou
imports: generator.NewImportTracker(), imports: generator.NewImportTracker(),
groupVersions: groupVersions, groupVersions: groupVersions,
clientSetPackage: clientSetPackage, clientSetPackage: clientSetPackage,
internalInterfacesPackage: subdirForInternalInterfaces(outputPkgBase), internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces),
gvGoNames: groupGoNames, gvGoNames: groupGoNames,
}) })
@ -279,11 +274,11 @@ func factoryTarget(outputDirBase, outputPkgBase string, boilerplate []byte, grou
} }
func factoryInterfaceTarget(outputDirBase, outputPkgBase string, boilerplate []byte, clientSetPackage string) generator.Target { func factoryInterfaceTarget(outputDirBase, outputPkgBase string, boilerplate []byte, clientSetPackage string) generator.Target {
outputDir := subdirForInternalInterfaces(outputDirBase) outputDir := filepath.Join(outputDirBase, subdirForInternalInterfaces)
outputPkg := subdirForInternalInterfaces(outputPkgBase) outputPkg := path.Join(outputPkgBase, subdirForInternalInterfaces)
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: filepath.Base(outputDir), PkgName: path.Base(outputDir),
PkgPath: outputPkg, PkgPath: outputPkg,
PkgDir: outputDir, PkgDir: outputDir,
HeaderComment: boilerplate, HeaderComment: boilerplate,
@ -304,7 +299,7 @@ func factoryInterfaceTarget(outputDirBase, outputPkgBase string, boilerplate []b
func groupTarget(outputDirBase, outputPackageBase string, groupVersions clientgentypes.GroupVersions, boilerplate []byte) generator.Target { func groupTarget(outputDirBase, outputPackageBase string, groupVersions clientgentypes.GroupVersions, boilerplate []byte) generator.Target {
outputDir := filepath.Join(outputDirBase, groupVersions.PackageName) outputDir := filepath.Join(outputDirBase, groupVersions.PackageName)
outputPkg := filepath.Join(outputPackageBase, groupVersions.PackageName) outputPkg := path.Join(outputPackageBase, groupVersions.PackageName)
groupPkgName := strings.Split(string(groupVersions.PackageName), ".")[0] groupPkgName := strings.Split(string(groupVersions.PackageName), ".")[0]
return &generator.SimpleTarget{ return &generator.SimpleTarget{
@ -320,7 +315,7 @@ func groupTarget(outputDirBase, outputPackageBase string, groupVersions clientge
outputPackage: outputPkg, outputPackage: outputPkg,
groupVersions: groupVersions, groupVersions: groupVersions,
imports: generator.NewImportTracker(), imports: generator.NewImportTracker(),
internalInterfacesPackage: subdirForInternalInterfaces(outputPackageBase), internalInterfacesPackage: path.Join(outputPackageBase, subdirForInternalInterfaces),
}) })
return generators return generators
}, },
@ -332,9 +327,9 @@ func groupTarget(outputDirBase, outputPackageBase string, groupVersions clientge
} }
func versionTarget(outputDirBase, outputPkgBase string, groupPkgName string, gv clientgentypes.GroupVersion, groupGoName string, boilerplate []byte, typesToGenerate []*types.Type, clientSetPackage, listersPackage string) generator.Target { func versionTarget(outputDirBase, outputPkgBase string, groupPkgName string, gv clientgentypes.GroupVersion, groupGoName string, boilerplate []byte, typesToGenerate []*types.Type, clientSetPackage, listersPackage string) generator.Target {
subdir := filepath.Join(groupPkgName, strings.ToLower(gv.Version.NonEmpty())) subdir := []string{groupPkgName, strings.ToLower(gv.Version.NonEmpty())}
outputDir := filepath.Join(outputDirBase, subdir) outputDir := filepath.Join(outputDirBase, filepath.Join(subdir...))
outputPkg := filepath.Join(outputPkgBase, subdir) outputPkg := path.Join(outputPkgBase, path.Join(subdir...))
return &generator.SimpleTarget{ return &generator.SimpleTarget{
PkgName: strings.ToLower(gv.Version.NonEmpty()), PkgName: strings.ToLower(gv.Version.NonEmpty()),
@ -349,7 +344,7 @@ func versionTarget(outputDirBase, outputPkgBase string, groupPkgName string, gv
outputPackage: outputPkg, outputPackage: outputPkg,
imports: generator.NewImportTracker(), imports: generator.NewImportTracker(),
types: typesToGenerate, types: typesToGenerate,
internalInterfacesPackage: subdirForInternalInterfaces(outputPkgBase), internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces),
}) })
for _, t := range typesToGenerate { for _, t := range typesToGenerate {
@ -365,7 +360,7 @@ func versionTarget(outputDirBase, outputPkgBase string, groupPkgName string, gv
imports: generator.NewImportTracker(), imports: generator.NewImportTracker(),
clientSetPackage: clientSetPackage, clientSetPackage: clientSetPackage,
listersPackage: listersPackage, listersPackage: listersPackage,
internalInterfacesPackage: subdirForInternalInterfaces(outputPkgBase), internalInterfacesPackage: path.Join(outputPkgBase, subdirForInternalInterfaces),
}) })
} }
return generators return generators

View File

@ -19,6 +19,7 @@ package generators
import ( import (
"fmt" "fmt"
"io" "io"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -118,9 +119,9 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)} orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
typesToGenerate = orderer.OrderTypes(typesToGenerate) typesToGenerate = orderer.OrderTypes(typesToGenerate)
subdir := filepath.Join(groupPackageName, strings.ToLower(gv.Version.NonEmpty())) subdir := []string{groupPackageName, strings.ToLower(gv.Version.NonEmpty())}
outputDir := filepath.Join(args.OutputDir, subdir) outputDir := filepath.Join(args.OutputDir, filepath.Join(subdir...))
outputPkg := filepath.Join(args.OutputPkg, subdir) outputPkg := path.Join(args.OutputPkg, path.Join(subdir...))
targetList = append(targetList, &generator.SimpleTarget{ targetList = append(targetList, &generator.SimpleTarget{
PkgName: strings.ToLower(gv.Version.NonEmpty()), PkgName: strings.ToLower(gv.Version.NonEmpty()),
PkgPath: outputPkg, PkgPath: outputPkg,

View File

@ -19,7 +19,7 @@ package prereleaselifecyclegenerators
import ( import (
"fmt" "fmt"
"io" "io"
"path/filepath" "path"
"strconv" "strconv"
"strings" "strings"
@ -225,7 +225,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
if pkgNeedsGeneration { if pkgNeedsGeneration {
targets = append(targets, targets = append(targets,
&generator.SimpleTarget{ &generator.SimpleTarget{
PkgName: strings.Split(filepath.Base(pkg.Path), ".")[0], PkgName: strings.Split(path.Base(pkg.Path), ".")[0],
PkgPath: pkg.Path, PkgPath: pkg.Path,
PkgDir: pkg.Dir, // output pkg is the same as the input PkgDir: pkg.Dir, // output pkg is the same as the input
HeaderComment: boilerplate, HeaderComment: boilerplate,