diff --git a/examples/deepcopy-gen/generators/deepcopy.go b/examples/deepcopy-gen/generators/deepcopy.go index c126b925..68be1fc4 100644 --- a/examples/deepcopy-gen/generators/deepcopy.go +++ b/examples/deepcopy-gen/generators/deepcopy.go @@ -196,7 +196,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat expandedPath := strings.TrimPrefix(pkg.SourcePath, arguments.OutputBase) if strings.Contains(expandedPath, "/vendor/") { path = expandedPath - glog.V(3).Infof(" %s", path) } } packages = append(packages, diff --git a/examples/defaulter-gen/generators/defaulter.go b/examples/defaulter-gen/generators/defaulter.go index f72a5e3b..d293cb6b 100644 --- a/examples/defaulter-gen/generators/defaulter.go +++ b/examples/defaulter-gen/generators/defaulter.go @@ -328,10 +328,25 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat glog.V(5).Infof("no defaulters in package %s", pkg.Name) } + 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 + } + } + packages = append(packages, &generator.DefaultPackage{ PackageName: filepath.Base(pkg.Path), - PackagePath: pkg.Path, + PackagePath: path, HeaderText: header, GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { return []generator.Generator{