Skip to content

Commit 499823c

Browse files
authored
[Static SDK] Improve version number/tag extraction. (#502)
If there are multiple tags on a revision, `git describe` returns the first tag it finds, but we actually don't want that; we want the tag that represents the highest version number. rdar://161117117
1 parent 75210db commit 499823c

File tree

1 file changed

+26
-1
lines changed
  • swift-ci/sdks/static-linux/scripts

1 file changed

+26
-1
lines changed

swift-ci/sdks/static-linux/scripts/build.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,32 @@ resource_dir="${script_dir}/../resources"
174174
# Find the version numbers of the various dependencies
175175
function describe {
176176
pushd $1 >/dev/null 2>&1
177-
git describe --tags
177+
178+
desc=$(git describe --tags)
179+
extra=
180+
181+
# Although git describe is documented as returning the newest tag,
182+
# if a given revision has multiple tags, it will actually return
183+
# the first one it finds, so we have some more work to do here.
184+
185+
# If we aren't pointing directly at a tag, git describe will append
186+
# -<number-of-commits>-g<truncated-hash> to the nearest tag. Strip
187+
# this, but keep a note of it for later.
188+
if [[ $desc =~ '-[0-9]+-g[0-9a-f]{11}$' ]]; then
189+
stripped=${desc%-*-g*}
190+
extra=${desc#$stripped}
191+
desc=$stripped
192+
fi
193+
194+
# Get the hash for the tag
195+
rev=$(git rev-list -n 1 tags/$desc)
196+
197+
# Now find the newest tag at that hash, using version number ordering
198+
latest_tag=$(git tag --points-at $rev | sort -V | tail -n 1)
199+
200+
# Stick it all back together
201+
echo $latest_tag$extra
202+
178203
popd >/dev/null 2>&1
179204
}
180205
function versionFromTag {

0 commit comments

Comments
 (0)