From 60bf1e14ed543bf5e06759d86f880c1b87d3fc81 Mon Sep 17 00:00:00 2001 From: Terence Hui Date: Thu, 8 Oct 2026 16:15:18 +0000 Subject: [PATCH] [meta] attrversion.sh: only emit versions for attributes in the checked-out headers attrversion.sh collects SAI_METADATA_ATTR_VERSION_* from every vX.Y.Z tag from v1.10.0 up. A clone usually carries all upstream tags, including releases published after the checked-out commit or on newer release branches, so attributes that do not exist in the checked-out headers were emitted too, and the output changed whenever a new release was tagged. For example, v1.17.5 checked out in a clone that has v1.19.1 produced 5821 defines for 2650 attributes in its headers. Downstream users that build metadata from a pinned SAI (e.g. the sonic-sairedis Python binding) saw unchanged sources start failing to build once v1.19.1 was tagged. Keep scanning the same tags, but only emit a define for attributes found in the checked-out headers. Unlike restricting to tags merged into HEAD, this keeps backported attributes at the point release that first shipped them. Every remaining attribute keeps the version of the first tag that contains it, so the generated metadata is unchanged apart from SAI_METADATA_HAVE_ATTR_VERSION; defines for attributes removed from the headers (e.g. the DASH meter bucket attributes) are dropped. Fixes #2361 Signed-off-by: Terence Hui --- meta/attrversion.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/meta/attrversion.sh b/meta/attrversion.sh index 33f6296c6..3fe0fbec5 100755 --- a/meta/attrversion.sh +++ b/meta/attrversion.sh @@ -42,7 +42,14 @@ set -e TAGS=$(git tag --sort=v:refname | grep -P "^v\d+\.\d+.\d+$" | sed -n -e '/'$BASE'/,$p'; echo HEAD) +# A clone usually carries every upstream tag, including releases published +# after (or on branches newer than) the checked-out commit. Only emit versions +# for attributes present in the checked-out headers, so that the output does not +# depend on which tags exist in the clone. + (for tag in $TAGS; do git grep -P "^\s+SAI_\w+_ATTR_" $tag ../inc ../experimental ../custom | cat; done; grep -sP "^\s+SAI_\w+_ATTR_" ../inc/sai*h ../experimental/sai*h ../custom/sai*h | perl -npe '$_.="HEAD:"' ) | \ - perl -ne '/^(\S+):..\/(\S+)\/\S+.h:\s+(SAI_\w+_ATTR_\w+)/; - print "#define SAI_METADATA_ATTR_VERSION_$3 \"$1\" /* $2 */\n" if not defined $h{$3};$h{$3}=1' > $OUTPUT + perl -ne '/^(\S+):..\/(\S+)\/\S+.h:\s+(SAI_\w+_ATTR_\w+)/ or next; + push @attrs, [$1, $2, $3]; $head{$3} = 1 if $1 eq "HEAD"; + END { for (@attrs) { my ($ver, $dir, $attr) = @$_; + print "#define SAI_METADATA_ATTR_VERSION_$attr \"$ver\" /* $dir */\n" if $head{$attr} and not $h{$attr}++ } }' > $OUTPUT