From 63ff27f9101418cf592be69df8c84c8092702aa6 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 4 Jan 2022 21:01:07 +0000 Subject: [PATCH] check_format.sh: handle spdk_ functions that are moved If a function prefixed with spdk_ was moved between files, the check_format.sh naming convention checks would fail. This is because it thinks the function was added, but doesn't see it getting added to the header file, since the header file wasn't touched by the commit. So resolve this by doing the defined/removed checks on a per-library basis, rather than per-file. The checks already handled the case where functions were moved within a file, and that will all work the same now that we check on a per-lib basis. Fixes issue #2307. Signed-off-by: Jim Harris Change-Id: If85a1e9c3cd349b701a10531726e814b60fba26d Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10967 Reviewed-by: Paul Luse Reviewed-by: wanghailiang Reviewed-by: Monica Kenguva Reviewed-by: Dong Yi Reviewed-by: Changpeng Liu Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins --- scripts/check_format.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index aab0cfec1..1dbc25d20 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -293,25 +293,25 @@ function check_naming_conventions() { changed_c_libs=() declared_symbols=() - # Build an array of all the modified C files. - mapfile -t changed_c_libs < <(git diff --name-only HEAD $commit_to_compare -- lib/**/*.c module/**/*.c) + # Build an array of all the modified C libraries. + mapfile -t changed_c_libs < <(git diff --name-only HEAD $commit_to_compare -- lib/**/*.c module/**/*.c | xargs -r dirname | sort | uniq) # Matching groups are 1. qualifiers / return type. 2. function name 3. argument list / comments and stuff after that. # Capture just the names of newly added (or modified) function definitions. mapfile -t declared_symbols < <(git diff -U0 $commit_to_compare HEAD -- include/spdk*/*.h | sed -En 's/(^[+].*)(spdk[a-z,A-Z,0-9,_]*)(\(.*)/\2/p') - for c_file in "${changed_c_libs[@]}"; do + for c_lib in "${changed_c_libs[@]}"; do lib_map_file="mk/spdk_blank.map" defined_symbols=() removed_symbols=() exported_symbols=() - if ls "$(dirname $c_file)"/*.map &> /dev/null; then - lib_map_file="$(ls "$(dirname $c_file)"/*.map)" + if ls "$c_lib"/*.map &> /dev/null; then + lib_map_file="$(ls "$c_lib"/*.map)" fi # Matching groups are 1. leading +sign. 2, function name 3. argument list / anything after that. # Capture just the names of newly added (or modified) functions that start with "spdk_" - mapfile -t defined_symbols < <(git diff -U0 $commit_to_compare HEAD -- $c_file | sed -En 's/(^[+])(spdk[a-z,A-Z,0-9,_]*)(\(.*)/\2/p') + mapfile -t defined_symbols < <(git diff -U0 $commit_to_compare HEAD -- $c_lib | sed -En 's/(^[+])(spdk[a-z,A-Z,0-9,_]*)(\(.*)/\2/p') # Capture the names of removed symbols to catch edge cases where we just move definitions around. - mapfile -t removed_symbols < <(git diff -U0 $commit_to_compare HEAD -- $c_file | sed -En 's/(^[-])(spdk[a-z,A-Z,0-9,_]*)(\(.*)/\2/p') + mapfile -t removed_symbols < <(git diff -U0 $commit_to_compare HEAD -- $c_lib | sed -En 's/(^[-])(spdk[a-z,A-Z,0-9,_]*)(\(.*)/\2/p') for symbol in "${removed_symbols[@]}"; do for i in "${!defined_symbols[@]}"; do if [[ ${defined_symbols[i]} = "$symbol" ]]; then