20 Commits

Author SHA1 Message Date
kadir çetinkaya
7e3fb372b0
[include-cleaner] Check emptiness instead of occurences (#79154)
Our internal integration relies on injecting some default values to
ignore/keep lists.
That means we can have filters, despite of not having occurences
for the flag.
2024-01-24 07:26:00 +01:00
Sam McCall
3de5d8e125
[include-cleaner] Add --only-headers flag, opposite of --ignore-headers (#78714) 2024-01-22 16:03:37 +01:00
Haojian Wu
67963d384b
[include-cleaner] Fix a race issue when editing multiple files. (#76960)
We have a previous fix
be861b64d9,
which snapshots all processing files.

It works most of times, the snapshot (InMemoryFileSystem) is based on
the file path. The file-path-based lookup can fail in a subtle way for
some tricky cases (we encounter it internally), which will result in
reading a corrupted file.

This is a different fix, we don't modify files on the fly, instead, we
write files when the tool finishes for all files.
2024-01-05 10:13:33 +01:00
Kadir Cetinkaya
90ecadde62
[include-cleaner] Filter references to identity macros
Despite being true positives, these results just confuse users. So
filter them out.

Differential Revision: https://reviews.llvm.org/D157905
2023-08-18 14:40:03 +02:00
Haojian Wu
be861b64d9 [include-cleaner] Avoid a caching issue when running --edit mode on multiple files.
Snapshot all analysing files before running the tool, this makes sure
that we analyse all files statelessly and avoid the FileManager caching issue
when running `-edit` on multiple files.

Differential Revision: https://reviews.llvm.org/D155195
2023-07-18 13:21:23 +02:00
Haojian Wu
7a328cf539 [include-cleaner] Bail out in the standalone tool for invalid ignore-headers
flag
2023-07-14 10:05:22 +02:00
Haojian Wu
7f3d2cd7ec [include-cleaner] Fix the fixIncludes API not respect main-file header.
The fixIncludes was using the `input` as the main file path, this will
results in inserting header at wrong places.

We need the main file path to so that we can get the real main-file
header.

Differential Revision: https://reviews.llvm.org/D154950
2023-07-11 15:02:26 +02:00
Haojian Wu
507d766d76 [include-cleaner] Add an IgnoreHeaders flag to the command-line tool.
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D153340
2023-07-06 11:18:44 +02:00
Haojian Wu
67e94c9dc8 [include-cleaner] Ignore the layering-violation errors for the standalone tool
If the source code is compilable-but-layering-violation, we still want
the tool to be functional on it (rather than bailing out).

Differential Revision: https://reviews.llvm.org/D154477
2023-07-05 13:30:26 +02:00
Haojian Wu
e339b07944 [include-cleaner] No need to overwrite the source file if there is no
cleanups
2023-06-22 14:37:11 +02:00
Haojian Wu
ab32cc6c02 [include-cleaner] Bailout on invalid code for the command-line tool
The binary tool only works on working source code, if the source code is
not compilable, don't perform any analysis and edits.

Differential Revision: https://reviews.llvm.org/D153271
2023-06-20 09:07:27 +02:00
Haojian Wu
b6f48341c5 [include-cleaner] Fix an unintended early return when checking the
incompatible flags in the CLI tool.
2023-02-27 10:09:40 +01:00
Haojian Wu
4702d8d9cf [include-cleaner] Print the line number of removal #includes.
I found that this information is helpful when using this tool.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D139715
2022-12-14 10:52:13 +01:00
Haojian Wu
14af1ad4ee [include-cleaner] Add two command-line flags to the include-cleaner
category.
2022-12-05 12:20:34 +01:00
Sam McCall
1a8dd74258 [include-cleaner] clang-include-cleaner can print/apply edits
This adds command-line flags to the tool:
+ -print: prints changed source code
+ -print=changes: prints headers added/removed
+ -edit: rewrites code in place
+ -insert=0/-remove=0: disables additions/deletions for the above

These are supported by a couple of new functions dumped into Analysis:
analyze() sits on top of walkUsed and makes used/unused decisions for
Includes. fixIncludes() applies those results to source code.

Differential Revision: https://reviews.llvm.org/D139013
2022-12-02 13:16:58 +01:00
Sam McCall
6a95e67323 [include-cleaner] HTMLReport shows headers that would be inserted
Demo: 7911d8251c/PathMapping.cpp.html

Header insertion doesn't actually work that well (not this patch's fault):
- we don't have ranking of locations/headers yet, so inserted header is pretty
  random
- on my system, we get a lot of absolute "/usr/bin/../include/..." paths.
  This is a HeaderSearch bug introduced in D60873 that I'll send a fix for

Differential Revision: https://reviews.llvm.org/D138676
2022-11-25 11:57:35 +01:00
Sam McCall
19ab2a671e [include-cleaner] Show includes matched by refs in HTML report.
Demo: 8736e64c45/ASTTests.html%25202

Differential Revision: https://reviews.llvm.org/D138219
2022-11-23 13:41:24 +01:00
Fangrui Song
f962dafbbd [include-cleaner] Fix -DBUILD_SHARED_LIBS=on build
and apply an include-cleaner fix for the tool itself:)

addPPCallbacks requires the vtable of PPChainedCallbacks and needs a clangLex
dependency.
2022-11-18 00:56:04 +00:00
Sam McCall
2675773258 [include-cleaner] add macro symbols and implicit refs to HTML report
Demo: 8c5c5ad927/ASTTests.html

Differential Revision: https://reviews.llvm.org/D137677
2022-11-17 17:29:41 +01:00
Sam McCall
6fa0e026c8 [include-cleaner] Add include-cleaner tool, with initial HTML report
The immediate goal is to start producing an HTML report to debug and explain
include-cleaner recommendations.
For now, this includes only the lowest-level piece: a list of the references
found in the source code.

How this fits into future ideas:
 - under refs we can also show the headers providing the symbol, which includes
   match those headers etc
 - we can also annotate the #include lines with which symbols they cover, and
   add whichever includes we're suggesting too
 - the include-cleaner tool will likely have modes where it emits diagnostics
   and/or applies edits, so the HTML report is behind a flag

Differential Revision: https://reviews.llvm.org/D135956
2022-10-18 18:09:41 +02:00