mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Get rid of vendor baggage in go-to-proto
This commit is contained in:
		@@ -22,7 +22,6 @@ import (
 | 
				
			|||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
@@ -42,7 +41,6 @@ type Generator struct {
 | 
				
			|||||||
	APIMachineryPackages string
 | 
						APIMachineryPackages string
 | 
				
			||||||
	Packages             string
 | 
						Packages             string
 | 
				
			||||||
	OutputBase           string
 | 
						OutputBase           string
 | 
				
			||||||
	VendorOutputBase     string
 | 
					 | 
				
			||||||
	ProtoImport          []string
 | 
						ProtoImport          []string
 | 
				
			||||||
	Conditional          string
 | 
						Conditional          string
 | 
				
			||||||
	Clean                bool
 | 
						Clean                bool
 | 
				
			||||||
@@ -57,14 +55,9 @@ func New() *Generator {
 | 
				
			|||||||
	common := args.GeneratorArgs{
 | 
						common := args.GeneratorArgs{
 | 
				
			||||||
		OutputBase: defaultSourceTree,
 | 
							OutputBase: defaultSourceTree,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cwd, err := os.Getwd()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		log.Fatalf("Cannot get current directory.")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return &Generator{
 | 
						return &Generator{
 | 
				
			||||||
		Common:           common,
 | 
							Common:     common,
 | 
				
			||||||
		OutputBase:       defaultSourceTree,
 | 
							OutputBase: defaultSourceTree,
 | 
				
			||||||
		VendorOutputBase: filepath.Join(cwd, "vendor"),
 | 
					 | 
				
			||||||
		APIMachineryPackages: strings.Join([]string{
 | 
							APIMachineryPackages: strings.Join([]string{
 | 
				
			||||||
			`+k8s.io/apimachinery/pkg/util/intstr`,
 | 
								`+k8s.io/apimachinery/pkg/util/intstr`,
 | 
				
			||||||
			`+k8s.io/apimachinery/pkg/api/resource`,
 | 
								`+k8s.io/apimachinery/pkg/api/resource`,
 | 
				
			||||||
@@ -85,8 +78,7 @@ func (g *Generator) BindFlags(flag *flag.FlagSet) {
 | 
				
			|||||||
	flag.StringVarP(&g.Packages, "packages", "p", g.Packages, "comma-separated list of directories to get input types from. Directories prefixed with '-' are not generated, directories prefixed with '+' only create types with explicit IDL instructions.")
 | 
						flag.StringVarP(&g.Packages, "packages", "p", g.Packages, "comma-separated list of directories to get input types from. Directories prefixed with '-' are not generated, directories prefixed with '+' only create types with explicit IDL instructions.")
 | 
				
			||||||
	flag.StringVar(&g.APIMachineryPackages, "apimachinery-packages", g.APIMachineryPackages, "comma-separated list of directories to get apimachinery input types from which are needed by any API. Directories prefixed with '-' are not generated, directories prefixed with '+' only create types with explicit IDL instructions.")
 | 
						flag.StringVar(&g.APIMachineryPackages, "apimachinery-packages", g.APIMachineryPackages, "comma-separated list of directories to get apimachinery input types from which are needed by any API. Directories prefixed with '-' are not generated, directories prefixed with '+' only create types with explicit IDL instructions.")
 | 
				
			||||||
	flag.StringVarP(&g.OutputBase, "output-base", "o", g.OutputBase, "Output base; defaults to $GOPATH/src/")
 | 
						flag.StringVarP(&g.OutputBase, "output-base", "o", g.OutputBase, "Output base; defaults to $GOPATH/src/")
 | 
				
			||||||
	flag.StringVar(&g.VendorOutputBase, "vendor-output-base", g.VendorOutputBase, "The vendor/ directory to look for packages in; defaults to $PWD/vendor/.")
 | 
						flag.StringSliceVar(&g.ProtoImport, "proto-import", g.ProtoImport, "A search path for imported protobufs (may be repeated).")
 | 
				
			||||||
	flag.StringSliceVar(&g.ProtoImport, "proto-import", g.ProtoImport, "The search path for the core protobuf .protos, required; defaults $GOPATH/src/k8s.io/kubernetes/vendor/github.com/gogo/protobuf/protobuf.")
 | 
					 | 
				
			||||||
	flag.StringVar(&g.Conditional, "conditional", g.Conditional, "An optional Golang build tag condition to add to the generated Go code")
 | 
						flag.StringVar(&g.Conditional, "conditional", g.Conditional, "An optional Golang build tag condition to add to the generated Go code")
 | 
				
			||||||
	flag.BoolVar(&g.Clean, "clean", g.Clean, "If true, remove all generated files for the specified Packages.")
 | 
						flag.BoolVar(&g.Clean, "clean", g.Clean, "If true, remove all generated files for the specified Packages.")
 | 
				
			||||||
	flag.BoolVar(&g.OnlyIDL, "only-idl", g.OnlyIDL, "If true, only generate the IDL for each package.")
 | 
						flag.BoolVar(&g.OnlyIDL, "only-idl", g.OnlyIDL, "If true, only generate the IDL for each package.")
 | 
				
			||||||
@@ -238,28 +230,19 @@ func Run(g *Generator) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	sort.Sort(positionOrder{topologicalPos, protobufNames.packages})
 | 
						sort.Sort(positionOrder{topologicalPos, protobufNames.packages})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var vendoredOutputPackages generator.Packages
 | 
					 | 
				
			||||||
	var localOutputPackages generator.Packages
 | 
						var localOutputPackages generator.Packages
 | 
				
			||||||
	for _, p := range protobufNames.packages {
 | 
						for _, p := range protobufNames.packages {
 | 
				
			||||||
		if _, ok := nonOutputPackages[p.Name()]; ok {
 | 
							if _, ok := nonOutputPackages[p.Name()]; ok {
 | 
				
			||||||
			// if we're not outputting the package, don't include it in either package list
 | 
								// if we're not outputting the package, don't include it in either package list
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		p.Vendored = strings.Contains(c.Universe[p.PackagePath].SourcePath, "/vendor/")
 | 
							localOutputPackages = append(localOutputPackages, p)
 | 
				
			||||||
		if p.Vendored {
 | 
					 | 
				
			||||||
			vendoredOutputPackages = append(vendoredOutputPackages, p)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			localOutputPackages = append(localOutputPackages, p)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := protobufNames.AssignTypesToPackages(c); err != nil {
 | 
						if err := protobufNames.AssignTypesToPackages(c); err != nil {
 | 
				
			||||||
		log.Fatalf("Failed to identify Common types: %v", err)
 | 
							log.Fatalf("Failed to identify Common types: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := c.ExecutePackages(vendoredOutputPackages); err != nil {
 | 
					 | 
				
			||||||
		log.Fatalf("Failed executing vendor generator: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if err := c.ExecutePackages(localOutputPackages); err != nil {
 | 
						if err := c.ExecutePackages(localOutputPackages); err != nil {
 | 
				
			||||||
		log.Fatalf("Failed executing local generator: %v", err)
 | 
							log.Fatalf("Failed executing local generator: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -301,10 +284,6 @@ func Run(g *Generator) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		path := filepath.Join(g.OutputBase, p.ImportPath())
 | 
							path := filepath.Join(g.OutputBase, p.ImportPath())
 | 
				
			||||||
		outputPath := filepath.Join(g.OutputBase, p.OutputPath())
 | 
							outputPath := filepath.Join(g.OutputBase, p.OutputPath())
 | 
				
			||||||
		if p.Vendored {
 | 
					 | 
				
			||||||
			path = filepath.Join(g.VendorOutputBase, p.ImportPath())
 | 
					 | 
				
			||||||
			outputPath = filepath.Join(g.VendorOutputBase, p.OutputPath())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// generate the gogoprotobuf protoc
 | 
							// generate the gogoprotobuf protoc
 | 
				
			||||||
		cmd := exec.Command("protoc", append(args, path)...)
 | 
							cmd := exec.Command("protoc", append(args, path)...)
 | 
				
			||||||
@@ -358,9 +337,6 @@ func Run(g *Generator) {
 | 
				
			|||||||
			p := outputPackage.(*protobufPackage)
 | 
								p := outputPackage.(*protobufPackage)
 | 
				
			||||||
			p.OmitGogo = true
 | 
								p.OmitGogo = true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err := c.ExecutePackages(vendoredOutputPackages); err != nil {
 | 
					 | 
				
			||||||
			log.Fatalf("Failed executing vendor generator: %v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if err := c.ExecutePackages(localOutputPackages); err != nil {
 | 
							if err := c.ExecutePackages(localOutputPackages); err != nil {
 | 
				
			||||||
			log.Fatalf("Failed executing local generator: %v", err)
 | 
								log.Fatalf("Failed executing local generator: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -374,9 +350,6 @@ func Run(g *Generator) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pattern := filepath.Join(g.OutputBase, p.PackagePath, "*.go")
 | 
							pattern := filepath.Join(g.OutputBase, p.PackagePath, "*.go")
 | 
				
			||||||
		if p.Vendored {
 | 
					 | 
				
			||||||
			pattern = filepath.Join(g.VendorOutputBase, p.PackagePath, "*.go")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		files, err := filepath.Glob(pattern)
 | 
							files, err := filepath.Glob(pattern)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Fatalf("Can't glob pattern %q: %v", pattern, err)
 | 
								log.Fatalf("Can't glob pattern %q: %v", pattern, err)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,10 +57,6 @@ func newProtobufPackage(packagePath, packageDir, packageName string, generateAll
 | 
				
			|||||||
type protobufPackage struct {
 | 
					type protobufPackage struct {
 | 
				
			||||||
	generator.DefaultPackage
 | 
						generator.DefaultPackage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If true, this package has been vendored into our source tree and thus can
 | 
					 | 
				
			||||||
	// only be generated by changing the vendor tree.
 | 
					 | 
				
			||||||
	Vendored bool
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// 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.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user