bin/find-unneeded-includes |   27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 930ff2b830ebaf44b8db6fd0d6be9342da814b0a
Author:     Gabor Kelemen <[email protected]>
AuthorDate: Fri Dec 26 21:31:43 2025 +0100
Commit:     Gabor Kelemen <[email protected]>
CommitDate: Fri Jan 2 19:57:07 2026 +0100

    bin/find-unneeded-includes: make --headersfwd work without --recursive
    
    Also add text=True for good output - previously, this did not work at all
    (it let include/vcl/BitmapTools.hxx checked, see it in subsequent patch)
    
    Previously this check was placed a bit incorrectly, which made
    it run only if both --headersfwd and --recursive was provided
    
    Now it runs with simple glob patterns too, such as:
    bin/find-unneeded-includes --headersfwd include/vcl/[A-Z]*
    
    Change-Id: Ib8a5209bac553a74137e3a4ac6fdf88319b03982
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196234
    Reviewed-by: Gabor Kelemen <[email protected]>
    Tested-by: Jenkins

diff --git a/bin/find-unneeded-includes b/bin/find-unneeded-includes
index 154195d5200a..b547ba6d5d13 100755
--- a/bin/find-unneeded-includes
+++ b/bin/find-unneeded-includes
@@ -562,7 +562,18 @@ def tidy(compileCommands, paths, noexclude, 
checknamespaces, finderrors, removef
                 invocation = "include-what-you-use -Xiwyu --no_fwd_decls 
-Xiwyu --max_line_length=200 " + args
             # Suggest headers' replacement with forward declarations
             elif headersfwd:
-                invocation = "include-what-you-use -Xiwyu --cxx17ns -Xiwyu 
--max_line_length=200 " + args
+                # Peek inside the file to check for code behind #ifdef or 
similar
+                # This is the fragile part, skip forward declaration 
suggestions for such
+                p1 = subprocess.Popen(['git', 'grep', '-v', '-e', 'INCLUDED', 
path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
+                p2 = subprocess.Popen(['grep', '-e', '#if'], stdin=p1.stdout, 
stdout=subprocess.PIPE, text=True)
+                p1.stdout.close()
+                output, _ = p2.communicate()
+                if not output:
+                    invocation = "include-what-you-use -Xiwyu --cxx17ns -Xiwyu 
--max_line_length=200 " + args
+                else:
+                    # '#if' found, skipping file
+                    continue
+
             # In --fwdecl mode we ask for fw declaration removal suggestions.
             # In this mode obsolete fw declarations are suggested for removal.
             # Later we ignore the header removal suggestions, which may be
@@ -626,7 +637,7 @@ def main(argv):
     if args.recursive:
         for root, dirs, files in os.walk(args.recursive[0]):
             for file in files:
-                if args.headers:
+                if args.headers or args.headersfwd:
                     if not args.fwdecl:
                         if (file.endswith(".hxx") or file.endswith(".hrc") or 
file.endswith(".h")):
                             list_of_files.append(os.path.join(root,file))
@@ -635,18 +646,6 @@ def main(argv):
                         # used in defines and iwyu (0.21 at least) can not yet 
understand those properly
                         if (file.endswith(".hxx") or file.endswith(".h")):
                             list_of_files.append(os.path.join(root,file))
-                elif args.headersfwd:
-                    if (file.endswith(".hxx") or file.endswith(".hrc") or 
file.endswith(".h")):
-                        # Peek inside the file to check for code behind #ifdef 
or similar
-                        # This is the fragile part, skip forward declaration 
suggestions for such
-                        p1 = subprocess.Popen(['git', 'grep', '-v', '-e', 
'INCLUDED', os.path.join(root,file) ], stdout=subprocess.PIPE)
-                        p2 = subprocess.Popen(['grep', '-e', '#if'], 
stdin=p1.stdout, stdout=subprocess.PIPE)
-                        p1.stdout.close()
-                        output, _ = p2.communicate()
-                        if not output:
-                            list_of_files.append(os.path.join(root,file))
-                        else:
-                            continue
                 else:
                     if (file.endswith(".cxx") or file.endswith(".c")):
                         list_of_files.append(os.path.join(root,file))

Reply via email to