mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-06-26 12:59:28 -04:00
Fix interactive add
Signed-off-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
parent
19860da768
commit
b288b2d0ad
3 changed files with 52 additions and 69 deletions
|
|
@ -3,7 +3,5 @@
|
|||
# SPDX-FileCopyrightText: Copyright 2026 crueter
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -7,31 +7,20 @@ RETURN=0
|
|||
|
||||
usage() {
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
EOF
|
||||
|
||||
exit $RETURN
|
||||
exit "$RETURN"
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "-- $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
_cpmfile() {
|
||||
[ -n "$1" ] || die "You must specify a valid cpmfile."
|
||||
CPMFILE="$1"
|
||||
RETURN=1 usage
|
||||
}
|
||||
|
||||
while :; do
|
||||
|
|
@ -44,21 +33,11 @@ while :; do
|
|||
opt=$(echo "$opt" | cut -c2-)
|
||||
|
||||
case "$char" in
|
||||
t) TAG=1 ;;
|
||||
c)
|
||||
_cpmfile "$2"
|
||||
shift
|
||||
;;
|
||||
h) usage ;;
|
||||
*) die "Invalid option -$char" ;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
--tag) TAG=1 ;;
|
||||
--cpmfile)
|
||||
_cpmfile "$2"
|
||||
shift
|
||||
;;
|
||||
--help) usage ;;
|
||||
"$0") break ;;
|
||||
"") break ;;
|
||||
|
|
@ -68,12 +47,8 @@ while :; do
|
|||
shift
|
||||
done
|
||||
|
||||
: "${CPMFILE:=$PWD/cpmfile.json}"
|
||||
|
||||
[ -n "$PKG" ] || die "You must specify a package name."
|
||||
|
||||
export PKG
|
||||
export CPMFILE
|
||||
export TAG
|
||||
|
||||
"$SCRIPTS"/util/interactive.sh
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
# SPDX-FileCopyrightText: Copyright 2026 crueter
|
||||
# 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
|
||||
# help if needed.
|
||||
# $1: The prompt itself, without any trailing spaces or whatever
|
||||
|
|
@ -88,6 +86,18 @@ optional "Additional find_package arguments, space-separated" \
|
|||
|
||||
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]" \
|
||||
"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."
|
||||
|
|
@ -98,27 +108,31 @@ case "$reply" in
|
|||
esac
|
||||
|
||||
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)"
|
||||
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"
|
||||
|
||||
GIT_HOST="$reply"
|
||||
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
|
||||
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%."
|
||||
|
||||
TAGNAME="$reply"
|
||||
[ -n "$TAGNAME" ] || TAGNAME="%VERSION%"
|
||||
|
||||
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.
|
||||
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"
|
||||
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" \
|
||||
"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 "$MIN_VERSION" ] || jq_input="$jq_input + {min_version: \"$MIN_VERSION\"}"
|
||||
[ -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
|
||||
jq_input="$jq_input + {
|
||||
ci: true,
|
||||
version: \"$VERSION\",
|
||||
artifact: \"$ARTIFACT\"
|
||||
}"
|
||||
|
||||
|
|
@ -187,32 +200,29 @@ else
|
|||
jq_input="$jq_input + {options: $options_json}"
|
||||
fi
|
||||
|
||||
# Git host
|
||||
if [ -n "$GIT_HOST" ] && [ "$GIT_HOST" != "github.com" ]; then
|
||||
jq_input="$jq_input + {git_host: \"$GIT_HOST\"}"
|
||||
fi
|
||||
|
||||
# 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\"}"
|
||||
else
|
||||
jq_input="$jq_input + {sha: \"$SHA\"}"
|
||||
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
|
||||
# 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
|
||||
|
||||
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…
Add table
Reference in a new issue