All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Jacques Hiblot <jjhiblot@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] policy regarding unused code
Date: Wed, 12 Dec 2018 16:17:09 +0100	[thread overview]
Message-ID: <47fc6f39-10ae-5f9f-8a3a-6bcdc24f8a9f@ti.com> (raw)
In-Reply-To: <alpine.LFD.2.21.1812111411540.4139@localhost.localdomain>


>> I suspect this splits into three categories:
>> - Dead symbols and code to drop.
>> - Typos/thinkos
>> - Mistake in your grep?  I see CONFIG_VIRTIO_SANDBOX is used today for
>>    example.
>    what did you run to get that list of CONFIG_* symbols? years ago, i

This is small python script that I wrote (see code below).

What it does (roughly):

- scan all Makefile and*.mk file to create a set of variables starting 
with CONFIG_

- create the set of all used CONFIG_* variables by scanning 
moveconfig.db. This can be created with tools/moveconfig.py -b. (you 
need patch 'tools: moveconfig: Add an option to build a fuller database 
of options').

- subtract set#2 from set#1

JJ

From: Jean-Jacques Hiblot <jjhiblot@ti.com>
Date: Wed, 12 Dec 2018 16:15:21 +0100
Subject: [PATCH] simple tool to find unused options

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
  tools/find_unused_config_options.py | 78 
+++++++++++++++++++++++++++++++++++++
  1 file changed, 78 insertions(+)
  create mode 100755 tools/find_unused_config_options.py

diff --git a/tools/find_unused_config_options.py 
b/tools/find_unused_config_options.py
new file mode 100755
index 0000000..85c859a
--- /dev/null
+++ b/tools/find_unused_config_options.py
@@ -0,0 +1,78 @@
+#! /usr/bin/env python
+
+import re
+import os
+
+def get_var_from_moveconfig_db():
+       options = set()
+       search = re.compile("\s*CONFIG_([^=]*)=.*")
+       with open("moveconfig.db", "r") as f:
+               for l in f.readlines():
+                       m = search.match(l)
+                       if m:
+                               options.add(m.group(1))
+       return options
+
+def get_makefiles(start):
+       Makefiles = []
+       for (dirpath, dirnames, filenames) in os.walk(start):
+                Makefiles.extend([ os.path.join(dirpath,f) for f in 
filenames if f == "Makefile" or f.endswith(".mk")])
+       return Makefiles
+
+def get_C_files(start):
+       c_files = []
+       for (dirpath, dirnames, filenames) in os.walk(start):
+                Makefiles.extend([ os.path.join(dirpath,f) for f in 
filenames if f.endswith(".c") or f.endswith(".h")])
+       return c_files
+
+def get_CONFIG_var_from_Makefile(makefile):
+       simple_options = set()
+       spl_tpl_options = set()
+
+       search = re.compile("\$\(CONFIG_(.*)\)")
+       with open(makefile, "r") as f:
+               for l in f.readlines():
+                       m = search.search(l)
+                       if m:
+                               option = m.group(1)
+                               s = set()
+                               if option.startswith("$(SPL_)"):
+ s.add(option.replace("$(SPL_)",""))
+ s.add(option.replace("$(SPL_)","SPL_"))
+                               elif option.startswith("$(SPL_TPL_)"):
+ s.add(option.replace("$(SPL_TPL_)",""))
+ s.add(option.replace("$(SPL_TPL_)","SPL_"))
+ s.add(option.replace("$(SPL_TPL_)","TPL_"))
+                               else:
+ simple_options.add(option.split(')')[0].split(':')[0])
+                               for opt in s:
+ spl_tpl_options.add(opt.split(')')[0].split(':')[0])
+
+       return simple_options, spl_tpl_options
+
+
+makefiles = get_makefiles('./')
+simple_options = set()
+spl_tpl_options = set()
+for f in makefiles:
+       a, b = get_CONFIG_var_from_Makefile(f)
+       simple_options |= a
+       spl_tpl_options |= b
+
+var_in_makefiles = simple_options
+# add the SPL_TPL variables (but filter out those that are never 
referenced in the code)
+for option in spl_tpl_options:
+       ### filter out variable that are not reference at all
+       if os.system("git grep 'CONFIG_{}' > /dev/null".format(option)) 
== 0:
+               var_in_makefiles.add(option)
+
+var_in_cfg = get_var_from_moveconfig_db()
+
+whitelist = set(["SPL_BUILD","TPL_BUILD", "SHELL"])
+suspects = var_in_makefiles - var_in_cfg - whitelist
+
+print(" -----------------------")
+print ("used in makefile but NOT referenced in defconfigs")
+for option in suspects:
+       print('CONFIG_'+option)
+
-- 
2.7.4

>

  reply	other threads:[~2018-12-12 15:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-11 15:25 [U-Boot] policy regarding unused code Jean-Jacques Hiblot
2018-12-11 15:46 ` Jean-Jacques Hiblot
2018-12-11 16:35   ` Tom Rini
2018-12-11 17:01     ` Jean-Jacques Hiblot
2018-12-11 18:17       ` Tom Rini
2018-12-12 11:59         ` Jean-Jacques Hiblot
     [not found]           ` <752D002CFF5D0F4FA35C0100F1D73F3FA3A5E60E@ATCPCS16.andestech.com>
2018-12-13  2:03             ` Rick Chen
2018-12-11 19:24     ` Robert P. J. Day
2018-12-12 15:17       ` Jean-Jacques Hiblot [this message]
2018-12-11 22:44   ` Lukasz Majewski
2018-12-14 15:54   ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47fc6f39-10ae-5f9f-8a3a-6bcdc24f8a9f@ti.com \
    --to=jjhiblot@ti.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.