git: 39a98a35c17a - main - Tools/scripts: Improve update-rust-port.sh

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Wed, 12 Jul 2023 19:17:31 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=39a98a35c17a9b3721f215b4dd1acee3a41363a6

commit 39a98a35c17a9b3721f215b4dd1acee3a41363a6
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2023-07-12 19:14:57 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-07-12 19:17:29 +0000

    Tools/scripts: Improve update-rust-port.sh
    
    * use strict shell mode
    * check dependencies
    * update PORTREVISION
    
    Suggested by:   mikael@ (use of portedit)
---
 Tools/scripts/update-rust-port.sh | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/Tools/scripts/update-rust-port.sh b/Tools/scripts/update-rust-port.sh
index 7e479f87822a..80edc8347f71 100755
--- a/Tools/scripts/update-rust-port.sh
+++ b/Tools/scripts/update-rust-port.sh
@@ -2,12 +2,25 @@
 #
 # MAINTAINER: yuri@FreeBSD.org
 
+# CAVEAT: ports with Makefile.crates are not yet supported
+
 ## args
 
 VERSION="$1"
 
+## set strict mode
+
+STRICT="set -euo pipefail"
+$STRICT
+
 ## checks
 
+for dep in portedit rustc; do
+	if ! which -s $dep; then
+		echo "error: $dep dependency is missing, $0 requires lang/rust and ports-mgmt/portfmt to be installed" >&2
+		exit 1
+	fi
+done
 if [ -z "$VERSION" ]; then
 	echo "Usage: $0 <new-version>"
 	exit 1
@@ -22,8 +35,13 @@ fi
 # copy Makefile
 cp Makefile Makefile.new
 
-# substitute version
-sed -i '' -E "s/(VERSION=[\t ]*)[0-9.]+/\1${VERSION}/" Makefile.new
+# substitute version tag PORTVERSION or DISTVERSION
+sed -i '' -E "s/^(PORT|DIST)(VERSION=[\t ]*)[0-9.-]+/\1\2${VERSION}/" Makefile.new
+
+# reset PORTREVISION if present
+if grep -q "PORTREVISION=" Makefile; then
+	echo PORTREVISION=0 | portedit merge -i Makefile.new
+fi
 
 # replace CARGO_CRATES with a placeholder
 /usr/bin/awk '