devtools: list symbols by version

Message ID 20230811154944.2947783-1-david.marchand@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series devtools: list symbols by version |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation fail ninja build failure
ci/Intel-compilation fail Compilation issues
ci/github-robot: build fail github build: failed
ci/iol-testing fail build patch failure

Commit Message

David Marchand Aug. 11, 2023, 3:49 p.m. UTC
  Make it easier to list experimental symbols added in a certain version.
While at it, add a check on map symbol files content to avoid breaking
this listing tool.

Example:
$ ./buildtools/map-list-symbol.sh -V 18.11 lib/eal/version.map
lib/eal/version.map EXPERIMENTAL rte_dev_event_callback_process
lib/eal/version.map EXPERIMENTAL rte_dev_hotplug_handle_disable
lib/eal/version.map EXPERIMENTAL rte_dev_hotplug_handle_enable

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 buildtools/map-list-symbol.sh | 39 ++++++++++++++++++++++-------------
 devtools/check-symbol-maps.sh | 21 +++++++++++++++++++
 2 files changed, 46 insertions(+), 14 deletions(-)
  

Comments

Stephen Hemminger Aug. 11, 2023, 5:13 p.m. UTC | #1
On Fri, 11 Aug 2023 17:49:44 +0200
David Marchand <david.marchand@redhat.com> wrote:

> Make it easier to list experimental symbols added in a certain version.
> While at it, add a check on map symbol files content to avoid breaking
> this listing tool.
> 
> Example:
> $ ./buildtools/map-list-symbol.sh -V 18.11 lib/eal/version.map
> lib/eal/version.map EXPERIMENTAL rte_dev_event_callback_process
> lib/eal/version.map EXPERIMENTAL rte_dev_hotplug_handle_disable
> lib/eal/version.map EXPERIMENTAL rte_dev_hotplug_handle_enable
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Script would probably be cleaner in Python with elftools package.
Using awk to parse map output is getting messy.
  
Thomas Monjalon Aug. 14, 2023, 9:48 a.m. UTC | #2
vendredi 11 août 2023, David Marchand:
> Make it easier to list experimental symbols added in a certain version.
> While at it, add a check on map symbol files content to avoid breaking
> this listing tool.

Is there a relation between the new check and the new -V option?
I feel it would be clearer in 2 separate patches.
  
David Marchand Aug. 15, 2023, 10:01 a.m. UTC | #3
On Mon, Aug 14, 2023 at 11:49 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> vendredi 11 août 2023, David Marchand:
> > Make it easier to list experimental symbols added in a certain version.
> > While at it, add a check on map symbol files content to avoid breaking
> > this listing tool.
>
> Is there a relation between the new check and the new -V option?
> I feel it would be clearer in 2 separate patches.

The new option relies on a strict format in the .map files.
I could add the check first in a separate patch if you prefer.
  

Patch

diff --git a/buildtools/map-list-symbol.sh b/buildtools/map-list-symbol.sh
index 3bf9bd66f8..a834399816 100755
--- a/buildtools/map-list-symbol.sh
+++ b/buildtools/map-list-symbol.sh
@@ -6,7 +6,7 @@  section=all
 symbol=all
 quiet=
 
-while getopts 'S:s:q' name; do
+while getopts 'S:s:qV:' name; do
 	case $name in
 	S)
 		[ $section = 'all' ] || {
@@ -25,8 +25,11 @@  while getopts 'S:s:q' name; do
 	q)
 		quiet='y'
 	;;
+	V)
+		version=$OPTARG
+	;;
 	?)
-		echo 'usage: $0 [-S section] [-s symbol] [-q]'
+		echo 'usage: $0 [-S section] [-s symbol] [-V version] [-q]'
 		exit 1
 	;;
 	esac
@@ -38,7 +41,8 @@  for file in $@; do
 	cat "$file" |awk '
 	BEGIN {
 		current_section = "";
-		if ("'$section'" == "all" && "'$symbol'" == "all") {
+		current_version = "";
+		if ("'$section'" == "all" && "'$symbol'" == "all" && "'$version'" == "") {
 			ret = 0;
 		} else {
 			ret = 1;
@@ -49,18 +53,25 @@  for file in $@; do
 			current_section = $1;
 		}
 	}
-	/.*}/ { current_section = ""; }
+	/.*}/ { current_section = ""; current_version = ""; }
+	/^\t# added in / {
+		current_version=$4;
+	}
 	/^[^}].*[^:*];/ {
-		if (current_section != "") {
-			gsub(";","");
-			if ("'$symbol'" == "all" || $1 == "'$symbol'") {
-				ret = 0;
-				if ("'$quiet'" == "") {
-					print "'$file' "current_section" "$1;
-				}
-				if ("'$symbol'" != "all") {
-					exit 0;
-				}
+		if (current_section == "") {
+			next;
+		}
+		if ("'$version'" != "" && "'$version'" != current_version) {
+			next;
+		}
+		gsub(";","");
+		if ("'$symbol'" == "all" || $1 == "'$symbol'") {
+			ret = 0;
+			if ("'$quiet'" == "") {
+				print "'$file' "current_section" "$1;
+			}
+			if ("'$symbol'" != "all") {
+				exit 0;
 			}
 		}
 	}
diff --git a/devtools/check-symbol-maps.sh b/devtools/check-symbol-maps.sh
index 8c116bfa9c..01cd09768d 100755
--- a/devtools/check-symbol-maps.sh
+++ b/devtools/check-symbol-maps.sh
@@ -74,4 +74,25 @@  if [ -n "$empty_maps" ] ; then
     ret=1
 fi
 
+find_bad_format_maps ()
+{
+    for map in $@ ; do
+        cat $map | awk '
+            /^(DPDK_[0-9]*|EXPERIMENTAL|INTERNAL) {$/ { next; } # start of a section
+            /^};$/ { next; } # end of a section
+            /^$/ { next; } # empty line
+            /^\t(global:|local: \*;)$/ { next; } # qualifiers
+            /^\t[a-zA-Z_0-9]*;(| # WINDOWS_NO_EXPORT)$/ { next; } # symbols
+            /^\t# added in [0-9]*\.[0-9]*$/ { next; } # version comments
+            { exit 1; }' || echo $map
+    done
+}
+
+bad_format_maps=$(find_bad_format_maps $@)
+if [ -n "$bad_format_maps" ] ; then
+    echo "Found badly formatted maps:"
+    echo "$bad_format_maps"
+    ret=1
+fi
+
 exit $ret