英文:
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 +build
line for older versions IIRC) and run make generate
again => your changes to the file have not been overwritten this time.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论