kubernetes / code-generator

Generators for kube-like API types
Apache License 2.0
1.71k stars 411 forks source link

`deepcopy-gen` relative output without symlinks #133

Closed austince closed 2 years ago

austince commented 3 years ago

deepcopy-gen currently writes output exclusively to the GOPATH. In kubernetes, a local go tree structure is created and symlinked to the working directory. It would be nice if this symlinking was not necessary for correct placement of the generated files.

An additional argument might look like:

deepcopy-gen -i github.com/austince/apiserver/apis/v1 \
  -O zz_generated.deepcopy \
  -o . \
  --pkg-mappings github.com/austince/apiserver=./apiserver

where we could map package roots to directories relative to the -o input, so the output github.com/austince/apiserver/apis/v1/zz_generated.deepcopy.go would be written to ./apiserver/apis/v1/zz_generated.deepcopy.go.

austince commented 3 years ago

/sig api-machinery

jpbetz commented 3 years ago

/cc @jpbetz /triage accepted

ncdc commented 2 years ago

I have some local changes to gengo (used by code-generator) that enables (hopefully) all generators to output files while stripping a base path prefix from the output path. For example, if your project is github.com/foo/bar, and you want to generate a package github.com/foo/bar/generated, running $some-generator --output-base . --output-package github.com/foo/bar/generated --trim-path-prefix github.com/foo/bar, it will output to ./generated while retaining the correct github.com/foo/bar/generated package name inside the generated files.

I'd also considered doing something like --go-module-mode=true/false to automatically determine the "trim path prefix" value from go.mod. Definitely open to suggestions for which approach (or possibly others) make the most sense.

Will open a PR shortly for what I currently have.

ncdc commented 2 years ago

PR: https://github.com/kubernetes/gengo/pull/221

ncdc commented 2 years ago

/assign

ncdc commented 2 years ago

/lifecycle active

ncdc commented 2 years ago

Sorry it took so long - just opened a PR for this in Kubernetes.