[PATCH] D48410: Script to find redundant includes.

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 18:22:40 PDT 2018


mzolotukhin created this revision.
Herald added a subscriber: llvm-commits.

How to use:
===========

Edit `remove_redundant.py` script - it has a bunch of parameters (which I was
too lazy to make command line arguments), and you'll need to specify your paths
there.  Namely, you'll need to change values of the following variables:

- repo_folders 		- it should be an array of paths to the repos. If the

project has only one repo (unlike LLVM/clang) then the array would have only
one element.

- build_folder 		- build folder. This is where compile_commands.json is

expected to be and this is where the script would run build/tests.

- compile_db_file 	- if compile_commands.json is in a different folder, it

can be specified here.

- processed_files 	- this is a path to a temporary file, it's used to

record which files have been processed. It's useful to resume the script's work
after interrupting it.

- files_list_name 	- (optional) list of files to process in json format.

Can be omitted.

- do_tests		- control variable specifying whether the script will

run build+tests after processing a file or not.

- tests_command 	- command that would run build+tests (basically it's a

command used for verifying our change, we just expect its return code to be 0).

After editing is done, we need to go to our repo and create a temporary branch.
The script will go to the repo and commit changes, so it's better to be on a
separate branch.

  cd /path/to/repo
  git checkout -b temp_branch

Now go back to the scripts repo and start the script:

  cd /path/to/redundant-headers
  python remove_redundant.py

The output should look like this (with colors!):

  [1/3] /a.cpp
  Trying to remove "c.h"...  Required!
  Trying to remove "b.h"...  Redundant!
  Trying to remove "a.h"...  Redundant!
  This one we'll remove:  "b.h"
  This one we'll remove:  "a.h"
  Preprocessed size change: 27 -> 13
  diff --git a/a.cpp b/a.cpp
  index c51cc72..47f5f6c 100644
  --- a/a.cpp
  +++ b/a.cpp
  @@ -1,2 +0,0 @@
  -#include "a.h"
  -#include "b.h"
  Optimized!
  [2/3] /b.cpp
  ...

When the script finishes, the changes would be in the output and committed to
the repo (that's why we created a separate branch).


Repository:
  rL LLVM

https://reviews.llvm.org/D48410

Files:
  llvm/utils/remove_redundant.py

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48410.152210.patch
Type: text/x-patch
Size: 8639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180621/fbde02e1/attachment.bin>


More information about the llvm-commits mailing list