lint: AST rules fail on any file that #includes a standard header #46
Labels
No labels
bug
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Build#46
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
crafter-build lintcannot produce an AST for a file that textually includes a C++ standard header:#include <algorithm>, or a vendored header-only library that does, such as nlohmann/json. Every rule registered withAddAstLintRulethen fails on that file and the run exits 1, although the same file builds. libclang is never given libc++'s include directory, which the clang driver finds relative to its own binary.Line numbers refer to
a3fe1bd.Details
implementations/Crafter.Build-Lint.cpp:754builds libclang's arguments from the file's compile command throughCommandToArgs, which drops argv[0], the compiler (:367).:759adds-resource-dir=fromclang++ -print-resource-dir(:712), and:774callsclang_parseTranslationUnit.clang++it runs as. In the Flatpak,clang++ -stdlib=libc++ -E -v -x c++ /dev/nulllists/app/bin/../include/c++/v1first, then/app/lib/clang/23/include. libclang never learns where that binary is, so the libc++ directory is missing. The explicit-resource-dircovers the builtin headers such asstddef.h, not libc++.-isystem/app/bin/../include/c++/v1added to the configuration'scompileFlags, the reproduction below lints clean and exits 0.:1331). That misleads here, because the PCMs exist. And--no-astturns the rules off for every file, not only for the ones that fail.Found in nostro: its four files that include
lib/json.hppfail this way under Crafter.LintRules' lite rules, so its lint can never exit 0. Seen with the Flatpak's stable branch (4.0.0, clang 23); the code above is unchanged ona3fe1bd.Reproduction
project.cpp:main.cpp:crafter-buildbuilds it.crafter-build lintthen prints this and exits 1:Suggested fix
Keep the compiler as argv[0] and parse with
clang_parseTranslationUnit2FullArgv, so the driver derives its installation directory from the realclang++, the way the build does. That probably makes the explicit-resource-dirunnecessary as well. Alternatively, ask the driver once for its libc++ include directory, the wayClangResourceDir()asks for the resource directory, and pass it as-isystem.