User Tools

Site Tools


u-boot_unused_configs

This is an old revision of the document!


Overview

Script that scans a Kbuild-based code base to identify CONFIG_ options that appear to be unused/untested in the code base.

Please do not make fun of the coding style of the script; I wrote it many, many years ago, and it would probably be far better written in Python.

The script

The script takes, as an optional argument, the specific directory you want to examine, and you're encouraged to be specific as the full output will be immense.

#!/bin/sh

# Uncomment whatever debugging you want to see.

SCAN_DIR=${1-*}

#  Collect config variables from Kconfig* files of interest.

SELECTED_KCONFIG_FILES=$(find ${SCAN_DIR} -name "Kconfig*")

if [ "${SELECTED_KCONFIG_FILES}" = "" ] ; then
        echo "No kconfig files, exiting."
        exit 1
fi

ALL_KCONFIG_FILES=$(find * -name "Kconfig*")

# echo SELECTED_KCONFIG_FILES = "${SELECTED_KCONFIG_FILES}"
# echo ALL_KCONFIG_FILES = "${ALL_KCONFIG_FILES}"

KCONFIG_VARS1=$(grep ^config ${SELECTED_KCONFIG_FILES} | awk '{print $2}' | sort -u)
KCONFIG_VARS2=$(grep ^menuconfig ${SELECTED_KCONFIG_FILES} | awk '{print $2}' | sort -u)

# echo KCONFIG_VARS1 = "${KCONFIG_VARS1}"
# echo KCONFIG_VARS2 = "${KCONFIG_VARS2}"

for kv in ${KCONFIG_VARS1} ${KCONFIG_VARS2} ; do
        # echo "Checking ${kv} ..."
        grep -q "depends on.*${kv}" ${ALL_KCONFIG_FILES} ||
        grep -q "if.*${kv}" ${ALL_KCONFIG_FILES} ||
        grep -q "default.*${kv}" ${ALL_KCONFIG_FILES} ||
        grep -r -w -q --exclude="*defconfig" "CONFIG_${kv}" * ||  {
                echo ">>>>> ${kv}"
                grep -rwn ${kv} * | grep -v defconfig
        }

done
u-boot_unused_configs.1555153528.txt.gz · Last modified: 2019/04/13 11:05 by rpjday