mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #103847 from liggitt/generator-install-fix
Generator install fix
This commit is contained in:
commit
d9de848739
@ -19,10 +19,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/applyconfiguration-gen/args"
|
||||
@ -33,7 +31,7 @@ import (
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine, "k8s.io/kubernetes/pkg/apis") // TODO: move this input path out of client-gen
|
||||
if err := flag.Set("logtostderr", "true"); err != nil {
|
||||
|
@ -19,10 +19,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/client-gen/args"
|
||||
@ -36,7 +34,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of client-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/clientset_generated/"
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
|
@ -87,10 +87,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/conversion-gen/args"
|
||||
@ -104,7 +102,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of conversion-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine)
|
||||
|
@ -44,10 +44,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/examples/deepcopy-gen/generators"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
@ -61,7 +59,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of deepcopy-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine)
|
||||
|
@ -43,10 +43,8 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/examples/defaulter-gen/generators"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
@ -60,7 +58,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of defaulter-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine)
|
||||
|
@ -57,7 +57,7 @@ func New() *Generator {
|
||||
sourceTree := args.DefaultSourceTree()
|
||||
common := args.GeneratorArgs{
|
||||
OutputBase: sourceTree,
|
||||
GoHeaderFilePath: filepath.Join(sourceTree, util.BoilerplatePath()),
|
||||
GoHeaderFilePath: util.BoilerplatePath(),
|
||||
}
|
||||
defaultProtoImport := filepath.Join(sourceTree, "k8s.io", "kubernetes", "vendor", "github.com", "gogo", "protobuf", "protobuf")
|
||||
cwd, err := os.Getwd()
|
||||
|
@ -19,7 +19,6 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
@ -34,7 +33,7 @@ func main() {
|
||||
arguments := args.Default()
|
||||
|
||||
// Override defaults.
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
arguments.GoHeaderFilePath = util.BoilerplatePath()
|
||||
pflag.CommandLine.BoolVar(&arguments.IncludeTestFiles, "include-test-files", false, "If true, include *_test.go files.")
|
||||
|
||||
if err := arguments.Execute(
|
||||
|
@ -18,12 +18,10 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/code-generator/cmd/informer-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/informer-gen/args"
|
||||
@ -35,7 +33,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move out of informer-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/informers/informers_generated"
|
||||
customArgs.VersionedClientSetPackage = "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
customArgs.InternalClientSetPackage = "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
|
@ -18,12 +18,10 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/code-generator/cmd/lister-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/lister-gen/args"
|
||||
@ -35,7 +33,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of lister-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/listers"
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
|
@ -34,13 +34,11 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
generatorargs "k8s.io/code-generator/cmd/prerelease-lifecycle-gen/args"
|
||||
statusgenerators "k8s.io/code-generator/cmd/prerelease-lifecycle-gen/prerelease-lifecycle-generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@ -50,7 +48,7 @@ func main() {
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of prerelease-lifecycle-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine)
|
||||
|
@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/klog/v2"
|
||||
@ -26,13 +25,12 @@ import (
|
||||
generatorargs "k8s.io/code-generator/cmd/register-gen/args"
|
||||
"k8s.io/code-generator/cmd/register-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
genericArgs := generatorargs.NewDefaults()
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.GoHeaderFilePath = util.BoilerplatePath()
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
flag.Set("logtostderr", "true")
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
|
@ -26,7 +26,6 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
@ -40,7 +39,7 @@ func main() {
|
||||
arguments := args.Default()
|
||||
|
||||
// Override defaults.
|
||||
arguments.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
arguments.GoHeaderFilePath = util.BoilerplatePath()
|
||||
arguments.InputDirs = []string{"k8s.io/kubernetes/pkg/util/sets/types"}
|
||||
arguments.OutputPackagePath = "k8s.io/apimachinery/pkg/util/sets"
|
||||
|
||||
|
@ -47,10 +47,10 @@ GROUPS_WITH_VERSIONS="$4"
|
||||
shift 4
|
||||
|
||||
(
|
||||
# To support running this script from anywhere, we have to first cd into this directory
|
||||
# so we can install the tools.
|
||||
# To support running this script from anywhere, first cd into this directory,
|
||||
# and then install with forced module mode on and fully qualified name.
|
||||
cd "$(dirname "${0}")"
|
||||
go install ./cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
|
||||
GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
|
||||
)
|
||||
# Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
|
||||
GOBIN="$(go env GOBIN)"
|
||||
|
@ -47,7 +47,12 @@ EXT_APIS_PKG="$4"
|
||||
GROUPS_WITH_VERSIONS="$5"
|
||||
shift 5
|
||||
|
||||
go install ./"$(dirname "${0}")"/cmd/{defaulter-gen,conversion-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,openapi-gen}
|
||||
(
|
||||
# To support running this script from anywhere, first cd into this directory,
|
||||
# and then install with forced module mode on and fully qualified name.
|
||||
cd "$(dirname "${0}")"
|
||||
GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,conversion-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,openapi-gen}
|
||||
)
|
||||
|
||||
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
|
||||
|
||||
|
@ -17,7 +17,7 @@ require (
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
|
||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
||||
golang.org/x/tools v0.1.2 // indirect
|
||||
golang.org/x/tools v0.1.2
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027
|
||||
|
@ -18,10 +18,12 @@ package util
|
||||
|
||||
import (
|
||||
gobuild "go/build"
|
||||
"path"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
type empty struct{}
|
||||
@ -55,9 +57,37 @@ func hasSubdir(root, dir string) (rel string, ok bool) {
|
||||
return filepath.ToSlash(dir[len(root):]), true
|
||||
}
|
||||
|
||||
// BoilerplatePath uses the boilerplate in code-generator by calculating the relative path to it.
|
||||
// BoilerplatePath returns the path to the boilerplate file in code-generator,
|
||||
// or "" if the default boilerplate.go.txt file cannot be located.
|
||||
func BoilerplatePath() string {
|
||||
return path.Join(reflect.TypeOf(empty{}).PkgPath(), "/../../hack/boilerplate.go.txt")
|
||||
// set up paths to check
|
||||
paths := []string{
|
||||
// works when run from root of $GOPATH containing k8s.io/code-generator
|
||||
filepath.Join(reflect.TypeOf(empty{}).PkgPath(), "/../../hack/boilerplate.go.txt"),
|
||||
// works when run from root of module vendoring k8s.io/code-generator
|
||||
"vendor/k8s.io/code-generator/hack/boilerplate.go.txt",
|
||||
// works when run from root of $GOPATH containing k8s.io/kubernetes
|
||||
"k8s.io/kubernetes/vendor/k8s.io/code-generator/hack/boilerplate.go.txt",
|
||||
}
|
||||
|
||||
// see if we can locate the module directory and add that to the list
|
||||
config := packages.Config{Mode: packages.NeedModule}
|
||||
if loadedPackages, err := packages.Load(&config, "k8s.io/code-generator/pkg/util"); err == nil {
|
||||
for _, loadedPackage := range loadedPackages {
|
||||
if loadedPackage.Module != nil && loadedPackage.Module.Dir != "" {
|
||||
paths = append(paths, filepath.Join(loadedPackage.Module.Dir, "hack/boilerplate.go.txt"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// try all paths and return the first that exists
|
||||
for _, path := range paths {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return path
|
||||
}
|
||||
}
|
||||
// cannot be located, invoker will have to explicitly specify boilerplate file
|
||||
return ""
|
||||
}
|
||||
|
||||
// Vendorless trims vendor prefix from a package path to make it canonical
|
||||
|
Loading…
Reference in New Issue
Block a user