Browse Source

Fix interactive add

Signed-off-by: crueter <crueter@eden-emu.dev>
update-cpmutil
crueter 2 days ago
parent
commit
b288b2d0ad
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 6
      tools/cpm/format.sh
  2. 31
      tools/cpm/package/add.sh
  3. 86
      tools/cpm/package/util/interactive.sh

6
tools/cpm/format.sh

@ -3,7 +3,5 @@
# SPDX-FileCopyrightText: Copyright 2026 crueter # SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
file=cpmfile.json
jq --indent 4 -S <"$file" >"$file".new
mv "$file".new "$file"
jq --indent 4 -S <cpmfile.json >cpmfile.json.new
mv cpmfile.json.new cpmfile.json

31
tools/cpm/package/add.sh

@ -7,31 +7,20 @@ RETURN=0
usage() { usage() {
cat <<EOF cat <<EOF
Usage: cpmutil.sh package add [-s|--sha] [-t|--tag]
[-c|--cpmfile CPMFILE] [package name]
Usage: cpmutil.sh package add [package name]
Add a new package to a cpmfile. Add a new package to a cpmfile.
Options:
-t, --tag Use tag versioning, instead of the default,
commit sha versioning.
-c, --cpmfile <CPMFILE> Use the specified cpmfile instead of the root cpmfile
Note that you are still responsible for integrating this into your CMake. Note that you are still responsible for integrating this into your CMake.
EOF EOF
exit $RETURN
exit "$RETURN"
} }
die() { die() {
echo "-- $*" >&2 echo "-- $*" >&2
exit 1
}
_cpmfile() {
[ -n "$1" ] || die "You must specify a valid cpmfile."
CPMFILE="$1"
RETURN=1 usage
} }
while :; do while :; do
@ -44,21 +33,11 @@ while :; do
opt=$(echo "$opt" | cut -c2-) opt=$(echo "$opt" | cut -c2-)
case "$char" in case "$char" in
t) TAG=1 ;;
c)
_cpmfile "$2"
shift
;;
h) usage ;; h) usage ;;
*) die "Invalid option -$char" ;; *) die "Invalid option -$char" ;;
esac esac
done done
;; ;;
--tag) TAG=1 ;;
--cpmfile)
_cpmfile "$2"
shift
;;
--help) usage ;; --help) usage ;;
"$0") break ;; "$0") break ;;
"") break ;; "") break ;;
@ -68,12 +47,8 @@ while :; do
shift shift
done done
: "${CPMFILE:=$PWD/cpmfile.json}"
[ -n "$PKG" ] || die "You must specify a package name." [ -n "$PKG" ] || die "You must specify a package name."
export PKG export PKG
export CPMFILE
export TAG
"$SCRIPTS"/util/interactive.sh "$SCRIPTS"/util/interactive.sh

86
tools/cpm/package/util/interactive.sh

@ -3,8 +3,6 @@
# SPDX-FileCopyrightText: Copyright 2026 crueter # SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
# TODO(crueter): Fix this pls
# This reads a single-line input from the user and also gives them # This reads a single-line input from the user and also gives them
# help if needed. # help if needed.
# $1: The prompt itself, without any trailing spaces or whatever # $1: The prompt itself, without any trailing spaces or whatever
@ -88,6 +86,18 @@ optional "Additional find_package arguments, space-separated" \
FIND_ARGS="$reply" FIND_ARGS="$reply"
optional "Git host (default: github.com)" \
"The hostname of the Git server, if not GitHub (e.g. codeberg.org, git.crueter.xyz)"
GIT_HOST="$reply"
required "Numeric version of the bundled package" \
"The semantic version of the bundled package. This is only used for package identification,
and if you use tag/artifact fetching. Do not input the entire tag here; for example, if you're using
tag v1.3.0, then set this to 1.3.0 and set the tag to v%VERSION%."
VERSION="$reply"
optional "Is this a CI package? [y/N]" \ optional "Is this a CI package? [y/N]" \
"Yes if the package is a prebuilt binary distribution (e.g. crueter-ci), "Yes if the package is a prebuilt binary distribution (e.g. crueter-ci),
no if the package is built from source if it's bundled." no if the package is built from source if it's bundled."
@ -98,27 +108,31 @@ case "$reply" in
esac esac
if [ "$CI" = "false" ]; then if [ "$CI" = "false" ]; then
optional "Git host (default: github.com)" \
"The hostname of the Git server, if not GitHub (e.g. codeberg.org, git.crueter.xyz)"
GIT_HOST="$reply"
while :; do
required "Use tag or commit sha versioning? [tag/sha]" \
"Tag versioning is compatible with auto-updating.
Use sha versioning for projects with improper tagging practices"
if [ "$reply" = "tag" ]; then
TAG=1
break
elif [ "$reply" = "sha" ]; then
SHA=1
break
else
echo "-- Invalid choice $reply"
fi
done
if [ "$TAG" = "1" ]; then if [ "$TAG" = "1" ]; then
required "Numeric version of the bundled package" \
"The semantic version of the bundled package. This is only used for package identification,
and if you use tag/artifact fetching. Do not input the entire tag here; for example, if you're using
tag v1.3.0, then set this to 1.3.0 and set the tag to v%VERSION%."
GIT_VERSION="$reply"
optional "Name of the upstream tag. %VERSION% is replaced by the numeric version (default: %VERSION%)" \
optional "Name of the upstream tag. %VERSION% is replaced by the numeric version ($VERSION) (default: %VERSION%)" \
"Most commonly this will be something like v%VERSION% or release-%VERSION%, or just %VERSION%." "Most commonly this will be something like v%VERSION% or release-%VERSION%, or just %VERSION%."
TAGNAME="$reply" TAGNAME="$reply"
[ -n "$TAGNAME" ] || TAGNAME="%VERSION%" [ -n "$TAGNAME" ] || TAGNAME="%VERSION%"
optional "Name of the release artifact to download, if applicable. optional "Name of the release artifact to download, if applicable.
-- %VERSION% is replaced by the numeric version and %TAG% is replaced by the tag name" \
-- %VERSION% is replaced by the numeric version ($VERSION) and %TAG% is replaced by the tag name" \
"Download the specified artifact from the release with the previously specified tag. "Download the specified artifact from the release with the previously specified tag.
If unspecified, the source code at the specified tag will be used instead." If unspecified, the source code at the specified tag will be used instead."
@ -136,11 +150,6 @@ should be set in CMake with AddJsonPackage's OPTIONS parameter."
OPTIONS="$reply" OPTIONS="$reply"
else else
required "Version of the CI package (e.g. 3.6.0-9eff87adb1)" \
"CI artifacts are stored as <name>-<platform>-<version>.tar.zst. This option controls the version."
VERSION="$reply"
required "Name of the CI artifact" \ required "Name of the CI artifact" \
"CI artifacts are stored as <name>-<platform>-<version>.tar.zst. This option controls the name." "CI artifacts are stored as <name>-<platform>-<version>.tar.zst. This option controls the name."
@ -164,11 +173,15 @@ jq_input='{repo: "'"$REPO"'"}'
[ -z "$PACKAGE" ] || jq_input="$jq_input + {package: \"$PACKAGE\"}" [ -z "$PACKAGE" ] || jq_input="$jq_input + {package: \"$PACKAGE\"}"
[ -z "$MIN_VERSION" ] || jq_input="$jq_input + {min_version: \"$MIN_VERSION\"}" [ -z "$MIN_VERSION" ] || jq_input="$jq_input + {min_version: \"$MIN_VERSION\"}"
[ -z "$FIND_ARGS" ] || jq_input="$jq_input + {find_args: \"$FIND_ARGS\"}" [ -z "$FIND_ARGS" ] || jq_input="$jq_input + {find_args: \"$FIND_ARGS\"}"
jq_input="$jq_input + {version: \"$VERSION\"}"
if [ -n "$GIT_HOST" ] && [ "$GIT_HOST" != "github.com" ]; then
jq_input="$jq_input + {git_host: \"$GIT_HOST\"}"
fi
if [ "$CI" = "true" ]; then if [ "$CI" = "true" ]; then
jq_input="$jq_input + { jq_input="$jq_input + {
ci: true, ci: true,
version: \"$VERSION\",
artifact: \"$ARTIFACT\" artifact: \"$ARTIFACT\"
}" }"
@ -187,32 +200,29 @@ else
jq_input="$jq_input + {options: $options_json}" jq_input="$jq_input + {options: $options_json}"
fi fi
# Git host
if [ -n "$GIT_HOST" ] && [ "$GIT_HOST" != "github.com" ]; then
jq_input="$jq_input + {git_host: \"$GIT_HOST\"}"
fi
# versioning stuff # versioning stuff
if [ -n "$GIT_VERSION" ]; then
jq_input="$jq_input + {git_version: \"$GIT_VERSION\"}"
[ -z "$TAGNAME" ] || jq_input="$jq_input + {tag: \"$TAGNAME\"}"
if [ "$TAG" = 1 ]; then
jq_input="$jq_input + {tag: \"$TAGNAME\"}"
[ -z "$ARTIFACT" ] || jq_input="$jq_input + {artifact: \"$ARTIFACT\"}" [ -z "$ARTIFACT" ] || jq_input="$jq_input + {artifact: \"$ARTIFACT\"}"
else else
jq_input="$jq_input + {sha: \"$SHA\"}" jq_input="$jq_input + {sha: \"$SHA\"}"
fi fi
fi fi
new_json=$(jq -n "$jq_input")
JSON=$(jq -n "$jq_input")
jq --arg key "$PKG" --argjson new "$new_json" \
'.[$key] = $new' "$CPMFILE" --indent 4 >"${CPMFILE}.tmp" &&
mv "${CPMFILE}.tmp" "$CPMFILE"
# shellcheck disable=SC1091
. "$SCRIPTS"/vars.sh
# now correct the hash
if [ "$CI" != true ]; then if [ "$CI" != true ]; then
# shellcheck disable=SC1091
. "$ROOTDIR"/common.sh
QUIET=true UPDATE=true "$SCRIPTS"/util/fix-hash.sh "$PKG"
HASH=$("$SCRIPTS"/util/url-hash.sh "$DOWNLOAD")
JSON=$(echo "$JSON" | jq ".hash = \"$HASH\"")
fi fi
echo "Added package $PKG to $CPMFILE. Include it in your project with AddJsonPackage($PKG)"
jq --arg key "$PKG" --argjson new "$JSON" \
'.[$key] = $new' "cpmfile.json" --indent 4 >"cpmfile.json.tmp" &&
mv "cpmfile.json.tmp" cpmfile.json
"$SCRIPTS"/format.sh
echo "Added package $PKG to cpmfile.json. Include it in your project with AddJsonPackage($PKG)"
Loading…
Cancel
Save