Why does kubebuilder include // +build !ignore_autogenerated in zz_generated.deepcopy.go files?

huangapple go评论84阅读模式
英文:

Why does kubebuilder include // +build !ignore_autogenerated in zz_generated.deepcopy.go files?

问题

每个由make和kubebuilder生成的深拷贝文件,在顶部都会有一个// +build !ignore_autogenerated的构建标签指令。

这个特定的构建标签指令被添加到这些生成的文件中的目的是什么?它的作用是什么?

英文:

Every deepcopy generated file that is produced by make with kubebuilder produces a file with a // +build !ignore_autogenerated build tag directive at the top.

//go:build !ignore_autogenerated
// +build !ignore_autogenerated

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Code generated by controller-gen. DO NOT EDIT.

Why is this specific build tag directive added to these generated files? What's its purpose?

答案1

得分: 1

这是由 controller-gen 用来识别它生成的文件,它只会覆盖那些文件。

例如,编辑一个生成的 zz_generated.deepcopy.go 文件,然后运行 make generate => 文件被覆盖。

现在再次编辑该文件,同时删除两行构建约束(go:build 行是针对 go >= 1.17 的,+build 行是针对旧版本的,如果我没记错的话),然后再次运行 make generate => 这次你对文件的更改没有被覆盖。

英文:

It's used by controller-gen to identify files it generated, it will only overwrite those.

E.g. edit a generated zz_generated.deepcopy.go and run make generate => the file is overwritten.

Now edit the file again, also remove the two lines with the build constraints (the go:build line is for go >= 1.17, the +buildline for older versions IIRC) and run make generate again => your changes to the file have not been overwritten this time.

huangapple
  • 本文由 发表于 2022年8月31日 07:04:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/73549283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定