mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Convert generated-deep-copies to use golang.org/x/tools/imports
I don't like users to need an external binary which can easily get out of sync. Just include the tools.
This commit is contained in:
parent
4acf86400f
commit
00929ed7d8
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -32,6 +34,7 @@ import (
|
|||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
|
"golang.org/x/tools/imports"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pkgBase = "k8s.io/kubernetes/pkg"
|
const pkgBase = "k8s.io/kubernetes/pkg"
|
||||||
@ -58,12 +61,24 @@ func main() {
|
|||||||
funcOut = file
|
funcOut = file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data := new(bytes.Buffer)
|
||||||
|
|
||||||
group, version := path.Split(*groupVersion)
|
group, version := path.Split(*groupVersion)
|
||||||
group = strings.TrimRight(group, "/")
|
group = strings.TrimRight(group, "/")
|
||||||
registerTo := "api.Scheme"
|
registerTo := "api.Scheme"
|
||||||
if *groupVersion == "api/" {
|
if *groupVersion == "api/" {
|
||||||
registerTo = "Scheme"
|
registerTo = "Scheme"
|
||||||
}
|
}
|
||||||
|
pkgname := group
|
||||||
|
if len(version) != 0 {
|
||||||
|
pkgname = version
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := data.WriteString(fmt.Sprintf("package %s\n", pkgname))
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("error writing package line: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
versionPath := path.Join(pkgBase, group, version)
|
versionPath := path.Join(pkgBase, group, version)
|
||||||
generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw(), versionPath, util.NewStringSet("k8s.io/kubernetes"))
|
generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw(), versionPath, util.NewStringSet("k8s.io/kubernetes"))
|
||||||
generator.AddImport(path.Join(pkgBase, "api"))
|
generator.AddImport(path.Join(pkgBase, "api"))
|
||||||
@ -86,13 +101,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
generator.RepackImports()
|
generator.RepackImports()
|
||||||
if err := generator.WriteImports(funcOut); err != nil {
|
if err := generator.WriteImports(data); err != nil {
|
||||||
glog.Fatalf("error while writing imports: %v", err)
|
glog.Fatalf("error while writing imports: %v", err)
|
||||||
}
|
}
|
||||||
if err := generator.WriteDeepCopyFunctions(funcOut); err != nil {
|
if err := generator.WriteDeepCopyFunctions(data); err != nil {
|
||||||
glog.Fatalf("error while writing deep copy functions: %v", err)
|
glog.Fatalf("error while writing deep copy functions: %v", err)
|
||||||
}
|
}
|
||||||
if err := generator.RegisterDeepCopyFunctions(funcOut, registerTo); err != nil {
|
if err := generator.RegisterDeepCopyFunctions(data, registerTo); err != nil {
|
||||||
glog.Fatalf("error while registering deep copy functions: %v", err)
|
glog.Fatalf("error while registering deep copy functions: %v", err)
|
||||||
}
|
}
|
||||||
|
b, err := imports.Process("", data.Bytes(), nil)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("error while update imports: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := funcOut.Write(b); err != nil {
|
||||||
|
glog.Fatalf("error while writing out the resulting file: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,27 +36,14 @@ function generate_version() {
|
|||||||
|
|
||||||
echo "Generating for ${version}"
|
echo "Generating for ${version}"
|
||||||
|
|
||||||
# version is group/version, so use the version number as the package name unless
|
|
||||||
# this is an internal version, in which case use the group name.
|
|
||||||
pkgname=${version##*/}
|
|
||||||
if [[ -z $pkgname ]]; then
|
|
||||||
pkgname=${version%/*}
|
|
||||||
fi
|
|
||||||
|
|
||||||
sed 's/YEAR/2015/' hack/boilerplate/boilerplate.go.txt > $TMPFILE
|
sed 's/YEAR/2015/' hack/boilerplate/boilerplate.go.txt > $TMPFILE
|
||||||
cat >> $TMPFILE <<EOF
|
cat >> $TMPFILE <<EOF
|
||||||
package $pkgname
|
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY \$KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
"${gendeepcopy}" -v "${version}" -f - -o "${version}=" >> "$TMPFILE"
|
"${gendeepcopy}" -v "${version}" -f - -o "${version}=" >> "$TMPFILE"
|
||||||
|
|
||||||
cat >> "$TMPFILE" <<EOF
|
|
||||||
// AUTO-GENERATED FUNCTIONS END HERE
|
|
||||||
EOF
|
|
||||||
|
|
||||||
goimports -w "$TMPFILE"
|
|
||||||
mv "$TMPFILE" `result_file_name ${version}`
|
mv "$TMPFILE" `result_file_name ${version}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE
|
|
||||||
import (
|
import (
|
||||||
time "time"
|
time "time"
|
||||||
|
|
||||||
@ -2289,5 +2290,3 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS END HERE
|
|
||||||
|
@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||||
|
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE
|
|
||||||
import (
|
import (
|
||||||
time "time"
|
time "time"
|
||||||
|
|
||||||
@ -2291,5 +2292,3 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS END HERE
|
|
||||||
|
@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||||
|
|
||||||
package expapi
|
package expapi
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE
|
|
||||||
import (
|
import (
|
||||||
time "time"
|
time "time"
|
||||||
|
|
||||||
@ -232,5 +233,3 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS END HERE
|
|
||||||
|
@ -14,9 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.
|
||||||
|
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS START HERE
|
|
||||||
import (
|
import (
|
||||||
time "time"
|
time "time"
|
||||||
|
|
||||||
@ -233,5 +234,3 @@ func init() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AUTO-GENERATED FUNCTIONS END HERE
|
|
||||||
|
Loading…
Reference in New Issue
Block a user