eden/tools/cpm/migrate.sh
crueter 94e655b4e4
[cmake] Update CPMUtil
Notable changes

- Single cpmfile
- version/min_version/git_version have been fixed and replaced with
  version and min_version
- Docs rewrite
- Legacy options are gone
- Fixed update/version commands

Interactive adder is nonfunctional right now, will rewrite later

Signed-off-by: crueter <crueter@eden-emu.dev>
2026-06-23 22:33:02 -04:00

46 lines
1 KiB
Bash
Executable file

#!/bin/sh -e
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
SUBMODULES="$(git submodule status --recursive | cut -c2-)"
: "${SUBMODULES:?No submodules defined!}"
tmp=$(mktemp)
printf '{}' >"$tmp"
IFS="
"
for i in $SUBMODULES; do
sha=$(echo "$i" | cut -d" " -f1 | cut -c1-10)
ver=$(echo "$i" | cut -d" " -f3 | tr -d '()')
path=$(echo "$i" | cut -d" " -f2)
name=$(echo "$path" | awk -F/ '{print $NF}')
remote=$(git -C "$path" remote get-url origin)
host=$(echo "$remote" | cut -d"/" -f3)
[ "$host" != github.com ] || host=
repo=$(echo "$remote" | cut -d"/" -f4-5 | cut -d'.' -f1)
entry=$(jq -n --arg name "$name" \
--arg sha "$sha" \
--arg ver "$ver" \
--arg repo "$repo" \
--arg host "$host" \
'{
($name): {
sha: $sha,
version: $ver,
repo: $repo
} + (if $host != "" then {git_host: $host} else {} end)
}')
jq --argjson new "$entry" '. + $new' "$tmp" >"${tmp}.new"
mv "$tmp.new" "$tmp"
done
jq '.' "$tmp" >cpmfile.json
rm -f "$tmp"