Skip to contentSkip to conversation

.gitignore: ignore temporary files from 'bear'

PATCH In review Brendan Jackman 3 participants 4 messages Aug 27, 2025 – Sep 1, 2025 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 .gitignore: ignore temporary files from 'bear'

Bear [0] is a tool for generating compile_commands.json. For Kbuild, Bear is not useful, since Kbuild already generates the necessary info and that can be converted to compile_commands.json by gen_compile_commads.py.

However, for code in tools/, it's handy. For example, this command updates compile_commands.json so that clangd code navigation will also work for the VMA unit tests:

	bear --append -- make -C tools/testing/vma -j

Bear generates some temporary files. These are usually deleted again but having them show up ephemerally confuses tools that trigger recompilation on source code changes. Ignore them in Git so that these tools can tell they aren't source code.

[0]: https://github.com/rizsotto/Bear

---
 .gitignore | 4 ++++
 1 file changed, 4 insertions(+)
.gitignore +4 -0
index 929054df5212d68a32a1f5ee2b267389fcd1c8db..b07c8c8383bd791e903ce985c14c231cb6928411 100644
@@ -53,6 +53,7 @@
 *.tar
 *.xz
 *.zst
+*.tmp
 Module.symvers
 dtbs-list
 modules.order
@@ -177,6 +178,9 @@ x509.genkey
 
 # Clang's compilation database file
 /compile_commands.json
+# Temporary files created by 'bear', a tool used for generating
+# compile_commands.json for non-Kbuild code.
+*.events.json
 
 # Documentation toolchain
 sphinx_*/

---
base-commit: fab1beda7597fac1cecc01707d55eadb6bbe773c
change-id: 20250827-master-23458abb102d

Best regards,

Signature · 1 line
Brendan Jackman <[email protected]>
#1 lore raw

Hi Brendan,

Quoted 11 lines · Brendan Jackman

Bear [0] is a tool for generating compile_commands.json. For Kbuild, Bear is not useful, since Kbuild already generates the necessary info and that can be converted to compile_commands.json by gen_compile_commads.py.

However, for code in tools/, it's handy. For example, this command updates compile_commands.json so that clangd code navigation will also work for the VMA unit tests:

	bear --append -- make -C tools/testing/vma -j
Quoted 8 lines

Bear generates some temporary files. These are usually deleted again but having them show up ephemerally confuses tools that trigger recompilation on source code changes. Ignore them in Git so that these tools can tell they aren't source code.

[0]: https://github.com/rizsotto/Bear

We can likely take this via the Kbuild tree. I do wonder if this would be better in a tools/.gitignore file since bear is really only of use there but I am not sure it matters much.

.gitignore line 56

Quoted 13 lines
---
 .gitignore | 4 ++++
 1 file changed, 4 insertions(+)
.gitignore +1 -0
index 929054df5212d68a32a1f5ee2b267389fcd1c8db..b07c8c8383bd791e903ce985c14c231cb6928411 100644
@@ -53,6 +53,7 @@
 *.tar
 *.xz
 *.zst
+*.tmp

Please keep the globs alphabetized.

.gitignore x509.genkey · line 183

Quoted 10 lines
.gitignore +3 -0
 Module.symvers
 dtbs-list
 modules.order
@@ -177,6 +178,9 @@ x509.genkey
 
 # Clang's compilation database file
 /compile_commands.json
+# Temporary files created by 'bear', a tool used for generating
+# compile_commands.json for non-Kbuild code.
+*.events.json

Please rebase this on kbuild-next, as '/' is no longer present in the compile_commands.json line:

https://git.kernel.org/kbuild/l/kbuild-next

The comment feels a little lengthy compared to the rest of the file but I am not sure it can really be slimmed down...

I am guessing the pattern cannot be made more specific, as I do wonder if anyone would introduce files with this pattern but that is why we have the check in scripts/misc-check, so it is probably not that big of a deal.

Quoted 13 lines
.gitignore +0 -1
 # Documentation toolchain
 sphinx_*/
 
---

base-commit: fab1beda7597fac1cecc01707d55eadb6bbe773c
change-id: 20250827-master-23458abb102d

Best regards,

Signature · 1 line
Brendan Jackman <[email protected]>
maintainer
#2 lore raw
Quoted 19 lines · Nathan Chancellor

Hi Brendan,

Quoted 16 lines · Brendan Jackman

Bear [0] is a tool for generating compile_commands.json. For Kbuild, Bear is not useful, since Kbuild already generates the necessary info and that can be converted to compile_commands.json by gen_compile_commads.py.

However, for code in tools/, it's handy. For example, this command updates compile_commands.json so that clangd code navigation will also work for the VMA unit tests:

	bear --append -- make -C tools/testing/vma -j

Bear generates some temporary files. These are usually deleted again but having them show up ephemerally confuses tools that trigger recompilation on source code changes. Ignore them in Git so that these tools can tell they aren't source code.

Quoted 7 lines
Quoted 3 lines

[0]: https://github.com/rizsotto/Bear

We can likely take this via the Kbuild tree. I do wonder if this would be better in a tools/.gitignore file since bear is really only of use there but I am not sure it matters much.

yeah, please consider using tools/.gitignore. Please have a look at this thread about ignoring files from "external" tools:

https://lore.kernel.org/lkml/CAHk-=wiJHMje8cpiTajqrLrM23wZK0SWetuK1Bd67c0OGM_BzQ@mail.gmail.com/

If using tools/.gitignore is not possible, I think the best way for ignoring files that are not natively related to kernel build tools is to update the local ~/.config/git/ignore, as suggested in

https://lore.kernel.org/lkml/CAK7LNAQas0cK7pgi72tYC3yU=ZkQxnr41YYW1mXd-sWiHtG+UA@mail.gmail.com/

compare to:

https://docs.github.com/en/get-started/git-basics/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer

Kind regards,
Nicolas

#3 lore raw
Quoted 22 lines · Nicolas Schier
Quoted 21 lines · Nathan Chancellor

Hi Brendan,

Quoted 18 lines · Brendan Jackman

Bear [0] is a tool for generating compile_commands.json. For Kbuild, Bear is not useful, since Kbuild already generates the necessary info and that can be converted to compile_commands.json by gen_compile_commads.py.

However, for code in tools/, it's handy. For example, this command updates compile_commands.json so that clangd code navigation will also work for the VMA unit tests:

	bear --append -- make -C tools/testing/vma -j

Bear generates some temporary files. These are usually deleted again but having them show up ephemerally confuses tools that trigger recompilation on source code changes. Ignore them in Git so that these tools can tell they aren't source code.

[0]: https://github.com/rizsotto/Bear

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

We can likely take this via the Kbuild tree. I do wonder if this would be better in a tools/.gitignore file since bear is really only of use there but I am not sure it matters much.

yeah, please consider using tools/.gitignore.

I don't believe that works here, because AFAIK clangd assumes a single compile_commands.json, so while we could git-ignore tools/compile_commands.json that wouldn't really serve the usecase I have here with 'bear --append'.

Quoted 4 lines

Please have a look at
this thread about ignoring files from "external" tools:

https://lore.kernel.org/lkml/CAHk-=wiJHMje8cpiTajqrLrM23wZK0SWetuK1Bd67c0OGM_BzQ@mail.gmail.com/

Hm, I would read the spirit of that thread as not being about things from 'external tools', rather Linus' objection seems to be that the _lifetime_ of the mbox files is unrelated to the kernel build. Well, to be honest the only coherent principle I can get from it is "don't break Linus' workflow". Which... yeah, is still a pretty valid concern.

Quoted 5 lines

If using tools/.gitignore is not possible, I think the best way for ignoring files that are not natively related to kernel build tools is to update the local ~/.config/git/ignore, as suggested in

https://lore.kernel.org/lkml/CAK7LNAQas0cK7pgi72tYC3yU=ZkQxnr41YYW1mXd-sWiHtG+UA@mail.gmail.com/

Given this alternative, and given the fact that I'm ignoring a very generic suffix in *.tmp (if it was just *.events.json I'd say the practical risk has gotta be close to nil), I think we could just drop this unless anyone else pops up with evidence that 'bear' is important to lots of people or something.

Cheers,
Brendan