aboutsummaryrefslogtreecommitdiff
path: root/tools/cpm/package.sh
diff options
context:
space:
mode:
authorcrueter <crueter@eden-emu.dev>2025-10-05 03:04:53 +0200
committercrueter <crueter@eden-emu.dev>2025-10-05 03:04:53 +0200
commit9f385bf627e40e2b7d5b06cd83cab0a4e9f98f99 (patch)
treea9146b701ca51c941197fe60f90b691ecf60506c /tools/cpm/package.sh
parent1a13e79c3d8619ff302d9c77eacf1a35c2210b66 (diff)
[tools, cmake] refactor: update/hash check scripts, use tags for some more deps, proper CPMUtil separation (#2666)
Uses tags for a bunch of deps that can use them Also adds a bunmch of scripts to tools/cpm, notably for checking hashes and checking for updates. TODO for the future: - CI target to check hashes - Weekly CI to check for updates Need to get that other CI runner up additional stuff - Ports gentoo fixes - makes solaris work (TODO: sdl2) - way better docs - properly separates CPMUtil as a standalone project Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2666 Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Diffstat (limited to 'tools/cpm/package.sh')
-rwxr-xr-xtools/cpm/package.sh203
1 files changed, 203 insertions, 0 deletions
diff --git a/tools/cpm/package.sh b/tools/cpm/package.sh
new file mode 100755
index 0000000000..d82b2fcbe9
--- /dev/null
+++ b/tools/cpm/package.sh
@@ -0,0 +1,203 @@
+#!/bin/sh -e
+
+# SPDX-FileCopyrightText: 2025 crueter
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# env vars:
+# - UPDATE: fix hashes if needed
+
+# shellcheck disable=SC1091
+. tools/cpm/common.sh
+
+[ -z "$PACKAGE" ] && echo "Package was not specified" && exit 0
+
+# shellcheck disable=SC2153
+JSON=$(echo "$PACKAGES" | jq -r ".\"$PACKAGE\" | select( . != null )")
+
+[ -z "$JSON" ] && echo "!! No cpmfile definition for $PACKAGE" && exit 1
+
+# unset stuff
+export PACKAGE_NAME="null"
+export REPO="null"
+export CI="null"
+export GIT_HOST="null"
+export EXT="null"
+export NAME="null"
+export DISABLED="null"
+export TAG="null"
+export ARTIFACT="null"
+export SHA="null"
+export VERSION="null"
+export GIT_VERSION="null"
+export DOWNLOAD="null"
+export URL="null"
+export KEY="null"
+export HASH="null"
+export ORIGINAL_TAG="null"
+export HAS_REPLACE="null"
+export VERSION_REPLACE="null"
+export HASH_URL="null"
+export HASH_SUFFIX="null"
+export HASH_ALGO="null"
+
+########
+# Meta #
+########
+
+REPO=$(value "repo")
+CI=$(value "ci")
+
+PACKAGE_NAME=$(value "package")
+[ "$PACKAGE_NAME" = null ] && PACKAGE_NAME="$PACKAGE"
+
+GIT_HOST=$(value "git_host")
+[ "$GIT_HOST" = null ] && GIT_HOST=github.com
+
+export PACKAGE_NAME
+export REPO
+export CI
+export GIT_HOST
+
+######################
+# CI Package Parsing #
+######################
+
+VERSION=$(value "version")
+
+if [ "$CI" = "true" ]; then
+ EXT=$(value "extension")
+ [ "$EXT" = null ] && EXT="tar.zst"
+
+ NAME=$(value "name")
+ DISABLED=$(echo "$JSON" | jq -j '.disabled_platforms')
+
+ [ "$NAME" = null ] && NAME="$PACKAGE_NAME"
+
+ export EXT
+ export NAME
+ export DISABLED
+ export VERSION
+
+ return 0
+fi
+
+##############
+# Versioning #
+##############
+
+TAG=$(value "tag")
+ARTIFACT=$(value "artifact")
+SHA=$(value "sha")
+GIT_VERSION=$(value "git_version")
+
+[ "$GIT_VERSION" = null ] && GIT_VERSION="$VERSION"
+
+if [ "$GIT_VERSION" != null ]; then
+ VERSION_REPLACE="$GIT_VERSION"
+else
+ VERSION_REPLACE="$VERSION"
+fi
+
+echo "$TAG" | grep -e "%VERSION%" > /dev/null && HAS_REPLACE=true || HAS_REPLACE=false
+ORIGINAL_TAG="$TAG"
+
+TAG=$(echo "$TAG" | sed "s/%VERSION%/$VERSION_REPLACE/g")
+ARTIFACT=$(echo "$ARTIFACT" | sed "s/%VERSION%/$VERSION_REPLACE/g")
+ARTIFACT=$(echo "$ARTIFACT" | sed "s/%TAG%/$TAG/g")
+
+export TAG
+export ARTIFACT
+export SHA
+export VERSION
+export GIT_VERSION
+export ORIGINAL_TAG
+export HAS_REPLACE
+export VERSION_REPLACE
+
+###############
+# URL Parsing #
+###############
+
+URL=$(value "url")
+
+if [ "$URL" != "null" ]; then
+ DOWNLOAD="$URL"
+elif [ "$REPO" != "null" ]; then
+ GIT_URL="https://$GIT_HOST/$REPO"
+
+ BRANCH=$(value "branch")
+
+ if [ "$TAG" != "null" ]; then
+ if [ "$ARTIFACT" != "null" ]; then
+ DOWNLOAD="${GIT_URL}/releases/download/${TAG}/${ARTIFACT}"
+ else
+ DOWNLOAD="${GIT_URL}/archive/refs/tags/${TAG}.tar.gz"
+ fi
+ elif [ "$SHA" != "null" ]; then
+ DOWNLOAD="${GIT_URL}/archive/${SHA}.zip"
+ else
+ if [ "$BRANCH" = null ]; then
+ BRANCH=master
+ fi
+
+ DOWNLOAD="${GIT_URL}/archive/refs/heads/${BRANCH}.zip"
+ fi
+else
+ echo "!! No repo or URL defined for $PACKAGE"
+ exit 1
+fi
+
+export DOWNLOAD
+export URL
+
+###############
+# Key Parsing #
+###############
+
+KEY=$(value "key")
+
+if [ "$KEY" = null ]; then
+ if [ "$SHA" != null ]; then
+ KEY=$(echo "$SHA" | cut -c1-4)
+ elif [ "$GIT_VERSION" != null ]; then
+ KEY="$GIT_VERSION"
+ elif [ "$TAG" != null ]; then
+ KEY="$TAG"
+ elif [ "$VERSION" != null ]; then
+ KEY="$VERSION"
+ else
+ echo "!! No valid key could be determined for $PACKAGE. Must define one of: key, sha, tag, version, git_version"
+ exit 1
+ fi
+fi
+
+export KEY
+
+################
+# Hash Parsing #
+################
+
+HASH_ALGO=$(value "hash_algo")
+[ "$HASH_ALGO" = null ] && HASH_ALGO=sha512
+
+HASH=$(value "hash")
+
+if [ "$HASH" = null ]; then
+ HASH_SUFFIX="${HASH_ALGO}sum"
+ HASH_URL=$(value "hash_url")
+
+ if [ "$HASH_URL" = null ]; then
+ HASH_URL="${DOWNLOAD}.${HASH_SUFFIX}"
+ fi
+
+ HASH=$(curl "$HASH_URL" -Ss -L -o -)
+else
+ HASH_URL=null
+ HASH_SUFFIX=null
+fi
+
+export HASH_URL
+export HASH_SUFFIX
+export HASH
+export HASH_ALGO
+export JSON \ No newline at end of file