kiss: add pkg_find_version()

This commit is contained in:
Dylan Araps 2021-07-03 14:48:39 +00:00
parent d107c43098
commit 32cdd4efc1
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C
1 changed files with 18 additions and 28 deletions

46
kiss
View File

@ -138,13 +138,10 @@ sh256() {
pkg_lint() { pkg_lint() {
log "$1" "Checking repository files" log "$1" "Checking repository files"
pkg_find "$1" pkg_find_version "$1"
cd "$repo_dir" cd "$repo_dir"
read -r _ release 2>/dev/null < version || [ "$repo_rel" ] ||
die "Version file not found"
[ "$release" ] ||
die "$1" "Release field not found in version file" die "$1" "Release field not found in version file"
[ -x build ] || [ -x build ] ||
@ -154,6 +151,13 @@ pkg_lint() {
war "$1" "Sources file not found" war "$1" "Sources file not found"
} }
pkg_find_version() {
pkg_find "$1"
read -r repo_ver repo_rel < "$repo_dir/version" ||
die "$1" "Failed to read version file ($repo_dir/version)"
}
pkg_find() { pkg_find() {
# Figure out which repository a package belongs to by searching for # Figure out which repository a package belongs to by searching for
# directories matching the package name in $KISS_PATH/*. # directories matching the package name in $KISS_PATH/*.
@ -203,13 +207,10 @@ pkg_list() {
pkg_cache() { pkg_cache() {
# Find the tarball of a package using a glob. Use the first found match # Find the tarball of a package using a glob. Use the first found match
# of '<pkg_name>[#@]<pkg_version><pkg_release>.tar.*'. # of '<pkg_name>[#@]<pkg_version><pkg_release>.tar.*'.
pkg_find "$1" pkg_find_version "$1"
read -r version release 2>/dev/null < "$repo_dir/version" ||
die "$1" "Failed to read version"
set +f set +f
set -f -- "$bin_dir/$1"[#@]"$version-$release.tar."* set -f -- "$bin_dir/$1"[#@]"$repo_ver-$repo_rel.tar."*
[ -f "$2" ] && shift [ -f "$2" ] && shift
@ -599,11 +600,7 @@ pkg_tar() (
# contains the package's database entry. # contains the package's database entry.
log "$1" "Creating tarball" log "$1" "Creating tarball"
pkg_find "$1" pkg_find_version "$1"
# Read the version information to name the package.
read -r version release < "$repo_dir/version" ||
die "$1" "Failed to read version"
# Use 'cd' to avoid needing tar's '-C' flag which may not be portable # Use 'cd' to avoid needing tar's '-C' flag which may not be portable
# across implementations. # across implementations.
@ -617,7 +614,7 @@ pkg_tar() (
lz) lzip -z ;; lz) lzip -z ;;
xz) xz -zT0 ;; xz) xz -zT0 ;;
zst) zstd -z ;; zst) zstd -z ;;
esac > "$bin_dir/$1@$version-$release.tar.${KISS_COMPRESS:=gz}" esac > "$bin_dir/$1@$repo_ver-$repo_rel.tar.${KISS_COMPRESS:=gz}"
log "$1" "Successfully created tarball" log "$1" "Successfully created tarball"
run_hook post-package "$1" run_hook post-package "$1"
@ -694,24 +691,20 @@ pkg_build() {
run_hook pre-extract "$pkg" "$pkg_dir/$pkg" run_hook pre-extract "$pkg" "$pkg_dir/$pkg"
pkg_extract "$pkg" pkg_extract "$pkg"
pkg_find "$pkg" pkg_find_version "$pkg"
# Install built packages to a directory under the package name to # Install built packages to a directory under the package name to
# avoid collisions with other packages. # avoid collisions with other packages.
mkdir -p "$pkg_dir/$pkg/$pkg_db" "$mak_dir/$pkg" mkdir -p "$pkg_dir/$pkg/$pkg_db" "$mak_dir/$pkg"
cd "$mak_dir/$pkg" cd "$mak_dir/$pkg"
# Log the version so we can pass it to the package build file.
read -r build_version _ < "$repo_dir/version" ||
die "$pkg" "Failed to read version"
log "$pkg" "Starting build" log "$pkg" "Starting build"
run_hook pre-build "$pkg" "$pkg_dir/$pkg" run_hook pre-build "$pkg" "$pkg_dir/$pkg"
# Call the build script, log the output to the terminal and to a file. # Call the build script, log the output to the terminal and to a file.
# There's no PIPEFAIL in POSIX shelll so we must resort to tricks like # There's no PIPEFAIL in POSIX shelll so we must resort to tricks like
# killing the script ourselves. # killing the script ourselves.
{ "$repo_dir/build" "$pkg_dir/$pkg" "$build_version" 2>&1 || { { "$repo_dir/build" "$pkg_dir/$pkg" "$repo_ver" 2>&1 || {
log "$pkg" "Build failed" log "$pkg" "Build failed"
log "$pkg" "Log stored to $log_dir/$pkg-$time-$pid" log "$pkg" "Log stored to $log_dir/$pkg-$time-$pid"
run_hook build-fail "$pkg" "$pkg_dir/$pkg" run_hook build-fail "$pkg" "$pkg_dir/$pkg"
@ -1413,14 +1406,11 @@ pkg_updates() {
read -r db_ver db_rel < "$pkg/version" || read -r db_ver db_rel < "$pkg/version" ||
die "${pkg##*/}" "Failed to read installed version" die "${pkg##*/}" "Failed to read installed version"
pkg_find "${pkg##*/}" pkg_find_version "${pkg##*/}"
read -r re_ver re_rel < "$repo_dir/version" ||
die "${pkg##*/}" "Failed to read repository version"
# Compare installed packages to repository packages. # Compare installed packages to repository packages.
[ "$db_ver-$db_rel" = "$re_ver-$re_rel" ] || { [ "$db_ver-$db_rel" = "$repo_ver-$repo_rel" ] || {
printf '%s\n' "${pkg##*/} $db_ver-$db_rel ==> $re_ver-$re_rel" printf '%s\n' "${pkg##*/} $db_ver-$db_rel ==> $repo_ver-$repo_rel"
set -- "$@" "${pkg##*/}" set -- "$@" "${pkg##*/}"
} }
done done