mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Fix package
This commit is contained in:
parent
454468f5c2
commit
62dc80c9a2
@ -347,8 +347,6 @@ type protoField struct {
|
|||||||
Extras map[string]string
|
Extras map[string]string
|
||||||
|
|
||||||
CommentLines string
|
CommentLines string
|
||||||
|
|
||||||
OptionalSet bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -473,6 +471,7 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
|
|||||||
}
|
}
|
||||||
field.Tag = protoTag
|
field.Tag = protoTag
|
||||||
// TODO: we are converting a Protobuf type back into an internal type, which is questionable
|
// TODO: we are converting a Protobuf type back into an internal type, which is questionable
|
||||||
|
// TODO; Allow a way to unambiguously represent a type into two systems at the same time, like Go and Protobuf.
|
||||||
if last := strings.LastIndex(parts[0], "."); last != -1 {
|
if last := strings.LastIndex(parts[0], "."); last != -1 {
|
||||||
prefix := parts[0][:last]
|
prefix := parts[0][:last]
|
||||||
field.Type = &types.Type{
|
field.Type = &types.Type{
|
||||||
@ -498,7 +497,6 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
field.OptionalSet = true
|
|
||||||
|
|
||||||
protoExtra := make(map[string]string)
|
protoExtra := make(map[string]string)
|
||||||
for i, extra := range parts[3:] {
|
for i, extra := range parts[3:] {
|
||||||
@ -511,6 +509,7 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
|
|||||||
parts[0] = fmt.Sprintf("(gogoproto.%s)", parts[0])
|
parts[0] = fmt.Sprintf("(gogoproto.%s)", parts[0])
|
||||||
protoExtra[parts[0]] = parts[1]
|
protoExtra[parts[0]] = parts[1]
|
||||||
}
|
}
|
||||||
|
// TODO: Should we parse castkey and castvalue too?
|
||||||
}
|
}
|
||||||
|
|
||||||
field.Extras = protoExtra
|
field.Extras = protoExtra
|
||||||
@ -710,18 +709,6 @@ func (ft protoIDLFileType) assemble(w io.Writer, f *generator.File) {
|
|||||||
w.Write(f.Body.Bytes())
|
w.Write(f.Body.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPackable(t *types.Type) bool {
|
|
||||||
if t.Kind != typesKindProtobuf {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
switch t.Name.Name {
|
|
||||||
case "int32", "int64", "varint":
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func isPrivateGoName(name string) bool {
|
func isPrivateGoName(name string) bool {
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return true
|
return true
|
||||||
|
@ -27,6 +27,8 @@ import (
|
|||||||
//
|
//
|
||||||
// TODO: pay attention to the package name (instead of renaming every package).
|
// TODO: pay attention to the package name (instead of renaming every package).
|
||||||
// TODO: Figure out the best way to make names for packages that collide.
|
// TODO: Figure out the best way to make names for packages that collide.
|
||||||
|
//
|
||||||
|
// TODO: Try to merge this into generator.ImportTracker (or refactor common parts).
|
||||||
type ImportTracker struct {
|
type ImportTracker struct {
|
||||||
pathToName map[string]string
|
pathToName map[string]string
|
||||||
// forbidden names are in here. (e.g. "go" is a directory in which
|
// forbidden names are in here. (e.g. "go" is a directory in which
|
||||||
|
@ -32,44 +32,37 @@ import (
|
|||||||
|
|
||||||
func newProtobufPackage(packagePath, packageName string, generateAll bool, omitFieldTypes map[types.Name]struct{}) *protobufPackage {
|
func newProtobufPackage(packagePath, packageName string, generateAll bool, omitFieldTypes map[types.Name]struct{}) *protobufPackage {
|
||||||
pkg := &protobufPackage{
|
pkg := &protobufPackage{
|
||||||
|
DefaultPackage: generator.DefaultPackage{
|
||||||
// The protobuf package name (foo.bar.baz)
|
// The protobuf package name (foo.bar.baz)
|
||||||
PackageName: packageName,
|
PackageName: packageName,
|
||||||
// A path segment relative to the GOPATH root (foo/bar/baz)
|
// A path segment relative to the GOPATH root (foo/bar/baz)
|
||||||
PackagePath: packagePath,
|
PackagePath: packagePath,
|
||||||
GenerateAll: generateAll,
|
|
||||||
OmitFieldTypes: omitFieldTypes,
|
|
||||||
HeaderText: []byte(
|
HeaderText: []byte(
|
||||||
`
|
`
|
||||||
// This file was autogenerated by the command:
|
// This file was autogenerated by go-to-protobuf. Do not edit it manually!
|
||||||
// $ ` + os.Args[0] + `
|
|
||||||
// Do not edit it manually!
|
|
||||||
|
|
||||||
`),
|
`),
|
||||||
PackageDocumentation: []byte(fmt.Sprintf(
|
PackageDocumentation: []byte(fmt.Sprintf(
|
||||||
`// Package %s is an autogenerated protobuf IDL.
|
`// Package %s is an autogenerated protobuf IDL.
|
||||||
`, packageName)),
|
`, packageName)),
|
||||||
|
},
|
||||||
|
GenerateAll: generateAll,
|
||||||
|
OmitFieldTypes: omitFieldTypes,
|
||||||
}
|
}
|
||||||
|
pkg.FilterFunc = pkg.filterFunc
|
||||||
|
pkg.GeneratorFunc = pkg.generatorFunc
|
||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
|
|
||||||
// protobufPackage contains the protobuf implementation of Package.
|
// protobufPackage contains the protobuf implementation of Package.
|
||||||
type protobufPackage struct {
|
type protobufPackage struct {
|
||||||
// Short name of package, used in the "package xxxx" line.
|
generator.DefaultPackage
|
||||||
PackageName string
|
|
||||||
// Import path of the package, and the location on disk of the package.
|
|
||||||
PackagePath string
|
|
||||||
// If true, generate protobuf serializations for all public types.
|
// If true, generate protobuf serializations for all public types.
|
||||||
// If false, only generate protobuf serializations for structs that
|
// If false, only generate protobuf serializations for structs that
|
||||||
// request serialization.
|
// request serialization.
|
||||||
GenerateAll bool
|
GenerateAll bool
|
||||||
|
|
||||||
// Emitted at the top of every file.
|
|
||||||
HeaderText []byte
|
|
||||||
|
|
||||||
// Emitted only for a "doc.go" file; appended to the HeaderText for
|
|
||||||
// that file.
|
|
||||||
PackageDocumentation []byte
|
|
||||||
|
|
||||||
// A list of types to filter to; if not specified all types will be included.
|
// A list of types to filter to; if not specified all types will be included.
|
||||||
FilterTypes map[types.Name]struct{}
|
FilterTypes map[types.Name]struct{}
|
||||||
|
|
||||||
@ -106,10 +99,7 @@ func (p *protobufPackage) ProtoTypeName() types.Name {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *protobufPackage) Name() string { return p.PackageName }
|
func (p *protobufPackage) filterFunc(c *generator.Context, t *types.Type) bool {
|
||||||
func (p *protobufPackage) Path() string { return p.PackagePath }
|
|
||||||
|
|
||||||
func (p *protobufPackage) Filter(c *generator.Context, t *types.Type) bool {
|
|
||||||
switch t.Kind {
|
switch t.Kind {
|
||||||
case types.Func, types.Chan:
|
case types.Func, types.Chan:
|
||||||
return false
|
return false
|
||||||
@ -175,7 +165,7 @@ func (p *protobufPackage) ExtractGeneratedType(t *ast.TypeSpec) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *protobufPackage) Generators(c *generator.Context) []generator.Generator {
|
func (p *protobufPackage) generatorFunc(c *generator.Context) []generator.Generator {
|
||||||
generators := []generator.Generator{}
|
generators := []generator.Generator{}
|
||||||
|
|
||||||
p.Imports.AddNullable()
|
p.Imports.AddNullable()
|
||||||
@ -194,13 +184,6 @@ func (p *protobufPackage) Generators(c *generator.Context) []generator.Generator
|
|||||||
return generators
|
return generators
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *protobufPackage) Header(filename string) []byte {
|
|
||||||
if filename == "doc.go" {
|
|
||||||
return append(p.HeaderText, p.PackageDocumentation...)
|
|
||||||
}
|
|
||||||
return p.HeaderText
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *protobufPackage) GoPackageName() string {
|
func (p *protobufPackage) GoPackageName() string {
|
||||||
return filepath.Base(p.PackagePath)
|
return filepath.Base(p.PackagePath)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user