update_submodules: Fix submodule path handling

There are two regressions introduced by CB:87823.

1. If the specified repo path has a tailing slash, `submodule` becames a
   empty variable due to `${submodule##*/}`, e.g.,

   `./util/scripts/update_submodules -R 3rdparty/arm-trusted-firmware/`

2. CB:87823 uses `git submodule status | cut -d ' ' -f 3` to retrieve
   all submodule paths. The script gets the wrong path if the format is
   wrong, e.g.,

-26c572974bcf7255930b0e9a51da3144ed0104b5 3rdparty/amd_blobs
 57ac3f74b34a3303f03deee264a1f2247c68008d 3rdparty/arm-trusted-firmware (v2.12.0-908-g57ac3f74b)
+5b7492979fc139efdfdc7f97ae53a2349798f160 3rdparty/cmocka (cmocka-1.1.5-263-g5b74929)

   The script gets the empty path for 3rdparty/amd_blobs and get
   cmocka-1.1.5-263-g5b74929 for 3rdparty/cmocka.

This patch fixes 1 by removing the tailing slash for the input directory
and fixes 2 by the below command.
   `git submodule foreach 'echo ${sm_path}'|grep -v Entering`

Note that `smp_path` is an environment variable[1] set by
`git submodule` when travelling the submodule directory.

[1]: https://git-scm.com/docs/git-submodule

Change-Id: I0016f3a867e2b4594788d71a790ff9a938121da5
Signed-off-by: Yidi Lin <yidilin@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87972
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
This commit is contained in:
Yidi Lin 2025-06-06 08:40:25 +08:00 committed by Matt DeVillier
commit c4eb645a0b

View file

@ -65,7 +65,7 @@ get_args() {
exit 0
;;
-R | --repo)
submodule_dirs="${1}"
submodule_dirs="${1%/}"
shift
if [[ ! -d "${submodule_dirs[0]}" ]]; then
echo "Error: ${submodule_dirs[0]} is not valid."
@ -92,7 +92,7 @@ main() {
get_args "$@"
if (( ${#submodule_dirs[@]} == 0 )); then
readarray -t submodule_dirs < <(git submodule status | cut -d ' ' -f 3)
readarray -t submodule_dirs < <(git submodule foreach 'echo ${sm_path}'|grep -v Entering)
fi
for submodule in "${submodule_dirs[@]}"; do