[SERVER-78890] clang-tidy MongoHeaderBracketCheck false positive Created: 12/Jul/23  Updated: 02/Feb/24  Resolved: 12/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Ben Shteinfeld Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Development Platform
Participants:

 Description   

When VSCode lints src/mongo/db/query/plan_executor.cpp, I get the error:

non-mongo include 'mongo/base/error_codes.h' should use angle bracketsclang-tidy(["<mongo/base/error_codes.h>",1657,26]) 

This seems like a false positive as the referenced import is a mongo import and should not use angle brackets.



 Comments   
Comment by David Percy [ 30/Jan/24 ]

and reloading the window fixes the issue

Thanks, I think another thing that threw me off was that "clangd: restart language server" didn't fix it. Now that I think about it, that must be because clang-tidy is separate from clangd.

Comment by David Percy [ 30/Jan/24 ]

I had this problem again today.  It looks like .clang-tidy is overwritten by other build profiles:

$ rm -rf build/ *.ninja
$ buildscripts/scons.py --build-profile=compiledb compiledb
$ buildscripts/scons.py --build-profile=opt generate-ninja
$ diff .clang-tidy.in .clang-tidy
134c134
< HeaderFilterRegex: '(mongo/.*|@MONGO_BUILD_DIR@/.*)'
---
> HeaderFilterRegex: '(mongo/.*|build/opt/mongo/.*)'
139c139
<     value:           'src/mongo;@MONGO_BUILD_DIR@'
---
>     value:           'src/mongo;build/opt/mongo'

Rerunning scons compiledb does fix it:

$ buildscripts/scons.py --build-profile=compiledb compiledb
$ diff .clang-tidy.in .clang-tidy
134c134
< HeaderFilterRegex: '(mongo/.*|@MONGO_BUILD_DIR@/.*)'
---
> HeaderFilterRegex: '(mongo/.*|build/compiledb/mongo/.*)'
139c139
<     value:           'src/mongo;@MONGO_BUILD_DIR@'
---
>     value:           'src/mongo;build/compiledb/mongo'

And it stays fixed even if I rebuild a .o file or rerun generated-sources:

$ rm build/opt/mongo/db/query/optimizer/algebra/algebra_test.o
$ ninja -f opt.ninja build/opt/mongo/db/query/optimizer/algebra/algebra_test.o
[1/1 (100%) 0.703s] Compiled build/opt/mongo/db/query/optimizer/algebra/algebra_test.o
$ ninja -f opt.ninja generated-sources
ninja: no work to do.
$ diff .clang-tidy.in .clang-tidy
134c134
< HeaderFilterRegex: '(mongo/.*|@MONGO_BUILD_DIR@/.*)'
---
> HeaderFilterRegex: '(mongo/.*|build/compiledb/mongo/.*)'
139c139
<     value:           'src/mongo;@MONGO_BUILD_DIR@'
---
>     value:           'src/mongo;build/compiledb/mongo'

But if I re-create the 'opt' build profile it gets overwritten the first time that profile runs 'generated-sources':

$ rm -rf build/opt/ opt.ninja 
$ buildscripts/scons.py --build-profile=opt generate-ninja
$ ninja -f opt.ninja generated-sources
$ diff .clang-tidy.in .clang-tidy
134c134
< HeaderFilterRegex: '(mongo/.*|@MONGO_BUILD_DIR@/.*)'
---
> HeaderFilterRegex: '(mongo/.*|build/opt/mongo/.*)'
139c139
<     value:           'src/mongo;@MONGO_BUILD_DIR@'
---
>     value:           'src/mongo;build/opt/mongo'

This must be because the rule that creates .clang-tidy has multiple targets, some of which are prefixed build/opt/:

1149151 build .clang-tidy build/aib_make_archive.py build/opt/mongo/config.h $
1149152     build/opt/mongo/db/feature_flag_test.idl build/opt/mongo/resmoke/resmoke.py $
1149153     build/opt/mongo/util/version_constants.h build/opt/third_party/third_party_shim.cpp $
...

So it looks like .clang-tidy will break whenever you create or re-create a build profile (or any ninjafile with a different VARIANT_DIR).

If the contents of .clang-tidy depend on the build profile, maybe we should put it into build/opt/ build/compiledb/ etc?

Comment by Ben Shteinfeld [ 12/Jul/23 ]

Seems like `./buildscripts/scons.py --build-profile=compiledb compiledb` and reloading the window fixes the issue. Thanks!

Not sure how I got into the bad state.

Comment by Daniel Moody [ 12/Jul/23 ]

I believe this is likely due to some configuration issue where the build dir where error_codes.h gets generated to is not being reflected in the generated .clang-tidy file. Did you some how regenerate the compile_commands.json with out regenerating .clang-tidy?

I believe regenerating the .clang-tidy file (via "compiledb" target) with the intended build configuration should fix the issue.

Generated at Thu Feb 08 06:39:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.