From 4696a159ef28a3d32c47a2aa4d01963c47b85cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Thu, 28 Sep 2017 13:22:57 +0200 Subject: [PATCH] header_usage.sh: Keep leading directory for grep. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes the script a bit more accurate in identifying place-holder header files. Bug: None Change-Id: Iba13562aed0d40bffef9c25d7345f3bb8af16c29 No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/4381 Reviewed-by: Patrik Höglund Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#20357} --- rtc_tools/header_usage.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rtc_tools/header_usage.sh b/rtc_tools/header_usage.sh index 58d85024dd..899b2fcf97 100755 --- a/rtc_tools/header_usage.sh +++ b/rtc_tools/header_usage.sh @@ -16,8 +16,20 @@ # # Headers close to the top of the list are candidates for removal. +# If the name includes at most one directory, keep name unchanged, +# otherwise strip directories. Needed to work with relative #includes +# which are used in some parts of the tree, while still avoiding, +# e.g., api/foo.h to match includes of pc/foo.h. +simplify_name () { + if expr "$1" : '.*/.*/' > /dev/null ; then + basename "$1" + else + echo "$1" + fi +} + git ls-files '*.h' '*.hpp' | while read header ; do - name="$(basename "${header}")" + name="$(simplify_name "${header}")" count="$(git grep -l -F "${name}" \ | grep -v -e '\.gn' -e '\.gyp' \ | wc -l)"