mirror of https://github.com/k3s-io/k3s
bump(k8s.io/gengo):c118aa8edfff53fe5b69127a970f54b6cf3a7563
parent
df831db360
commit
c5059bd772
|
@ -2663,43 +2663,43 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/args",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/import-boss/generators",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/set-gen/generators",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/set-gen/sets",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/generator",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/namer",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/parser",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/types",
|
||||
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed"
|
||||
"Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/heapster/metrics/api/v1/types",
|
||||
|
|
|
@ -184,10 +184,25 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
|
||||
if pkgNeedsGeneration {
|
||||
glog.V(3).Infof("Package %q needs generation", i)
|
||||
path := pkg.Path
|
||||
// if the source path is within a /vendor/ directory (for example,
|
||||
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1), allow
|
||||
// generation to output to the proper relative path (under vendor).
|
||||
// Otherwise, the generator will create the file in the wrong location
|
||||
// in the output directory.
|
||||
// TODO: build a more fundamental concept in gengo for dealing with modifications
|
||||
// to vendored packages.
|
||||
if strings.HasPrefix(pkg.SourcePath, arguments.OutputBase) {
|
||||
expandedPath := strings.TrimPrefix(pkg.SourcePath, arguments.OutputBase)
|
||||
if strings.Contains(expandedPath, "/vendor/") {
|
||||
path = expandedPath
|
||||
glog.V(3).Infof(" %s", path)
|
||||
}
|
||||
}
|
||||
packages = append(packages,
|
||||
&generator.DefaultPackage{
|
||||
PackageName: strings.Split(filepath.Base(pkg.Path), ".")[0],
|
||||
PackagePath: pkg.Path,
|
||||
PackagePath: path,
|
||||
HeaderText: header,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
return []generator.Generator{
|
||||
|
@ -524,15 +539,25 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) {
|
|||
}
|
||||
|
||||
func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) {
|
||||
if hasDeepCopyMethod(t) {
|
||||
sw.Do("*out = in.DeepCopy()\n", nil)
|
||||
return
|
||||
}
|
||||
|
||||
sw.Do("*out = make($.|raw$, len(*in))\n", t)
|
||||
if t.Elem.Kind == types.Builtin {
|
||||
if hasDeepCopyMethod(t.Elem) {
|
||||
sw.Do("for i := range *in {\n", nil)
|
||||
sw.Do("(*out)[i] = (*in)[i].DeepCopy()\n", nil)
|
||||
sw.Do("}\n", nil)
|
||||
} else if t.Elem.Kind == types.Builtin || t.Elem.IsAssignable() {
|
||||
sw.Do("copy(*out, *in)\n", nil)
|
||||
} else {
|
||||
sw.Do("for i := range *in {\n", nil)
|
||||
if hasDeepCopyMethod(t.Elem) {
|
||||
sw.Do("(*out)[i] = (*in)[i].DeepCopy()\n", nil)
|
||||
} else if t.Elem.IsAssignable() {
|
||||
sw.Do("(*out)[i] = (*in)[i]\n", nil)
|
||||
if t.Elem.Kind == types.Slice {
|
||||
sw.Do("if (*in)[i] != nil {\n", nil)
|
||||
sw.Do("in, out := &(*in)[i], &(*out)[i]\n", nil)
|
||||
g.generateFor(t.Elem, sw)
|
||||
sw.Do("}\n", nil)
|
||||
} else if g.copyableAndInBounds(t.Elem) {
|
||||
sw.Do("if err := $.type|dcFnName$(&(*in)[i], &(*out)[i], c); err != nil {\n", argsFromType(t.Elem))
|
||||
sw.Do("return err\n", nil)
|
||||
|
@ -582,7 +607,7 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
|
|||
sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args)
|
||||
sw.Do("}\n", nil)
|
||||
} else {
|
||||
// Fixup non-nil reference-sematic types.
|
||||
// Fixup non-nil reference-semantic types.
|
||||
sw.Do("if in.$.name$ != nil {\n", args)
|
||||
sw.Do("in, out := &in.$.name$, &out.$.name$\n", args)
|
||||
g.generateFor(t, sw)
|
||||
|
|
|
@ -695,16 +695,16 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
|
|||
}
|
||||
return out
|
||||
case *tc.Named:
|
||||
var out *types.Type
|
||||
switch t.Underlying().(type) {
|
||||
case *tc.Named, *tc.Basic, *tc.Map, *tc.Slice:
|
||||
name := tcNameToName(t.String())
|
||||
out := u.Type(name)
|
||||
out = u.Type(name)
|
||||
if out.Kind != types.Unknown {
|
||||
return out
|
||||
}
|
||||
out.Kind = types.Alias
|
||||
out.Underlying = b.walkType(u, nil, t.Underlying())
|
||||
return out
|
||||
default:
|
||||
// tc package makes everything "named" with an
|
||||
// underlying anonymous type--we remove that annoying
|
||||
|
@ -714,20 +714,19 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
|
|||
if out := u.Type(name); out.Kind != types.Unknown {
|
||||
return out // short circuit if we've already made this.
|
||||
}
|
||||
out := b.walkType(u, &name, t.Underlying())
|
||||
if len(out.Methods) == 0 {
|
||||
// If the underlying type didn't already add
|
||||
// methods, add them. (Interface types will
|
||||
// have already added methods.)
|
||||
for i := 0; i < t.NumMethods(); i++ {
|
||||
if out.Methods == nil {
|
||||
out.Methods = map[string]*types.Type{}
|
||||
}
|
||||
out.Methods[t.Method(i).Name()] = b.walkType(u, nil, t.Method(i).Type())
|
||||
}
|
||||
}
|
||||
return out
|
||||
out = b.walkType(u, &name, t.Underlying())
|
||||
}
|
||||
// If the underlying type didn't already add methods, add them.
|
||||
// (Interface types will have already added methods.)
|
||||
if len(out.Methods) == 0 {
|
||||
for i := 0; i < t.NumMethods(); i++ {
|
||||
if out.Methods == nil {
|
||||
out.Methods = map[string]*types.Type{}
|
||||
}
|
||||
out.Methods[t.Method(i).Name()] = b.walkType(u, nil, t.Method(i).Type())
|
||||
}
|
||||
}
|
||||
return out
|
||||
default:
|
||||
out := u.Type(name)
|
||||
if out.Kind != types.Unknown {
|
||||
|
|
|
@ -163,7 +163,7 @@ func (p *Package) Function(funcName string) *Type {
|
|||
return t
|
||||
}
|
||||
|
||||
// Variable gets the given varaible Type in this Package. If the variable is
|
||||
// Variable gets the given variable Type in this Package. If the variable is
|
||||
// not already defined, this will add it. If a variable is added, it's the caller's
|
||||
// responsibility to finish construction of the variable by setting Underlying
|
||||
// to the correct type.
|
||||
|
|
Loading…
Reference in New Issue