提交Gazelle生成的`BUILD.bazel`文件是否是最佳实践?

I have a Go project that uses rules_go (Bazel) to build the project. I'm using Gazelle to generate BUILD.bazel files. Is it considered best-practise to commit the generated BUILD.bazel files into version control? Or is it best-practise to always do bazel run //:gazelle on new checkout and when new files have been added?

Yes, it's generally best practice to commit build files for several reasons.

  • Build files frequently contain rules, comments, and annotations which are not generated. For example, you might need to write a genrule to replace go generate. Or you might write a test that checks the copyright headers in your source files are up to date. Or you may want to tweak the visibility rules for some of your libraries.
  • If any repository depends on your repository as a remote, it's convenient to have build files already checked in.
  • In general, it's nice not to have to re-run Gazelle and similar tools before a build.