[pacman-dev] [PATCH] libmakepkg: extract functions for writing .SRCINFO files
Ashley Whetter
ashley at awhetter.co.uk
Wed Feb 10 21:07:39 UTC 2016
Signed-off-by: Ashley Whetter <ashley at awhetter.co.uk>
---
scripts/Makefile.am | 1 +
scripts/libmakepkg/srcinfo.sh.in | 120 +++++++++++++++++++++++++++++++++++++++
scripts/makepkg.sh.in | 94 ------------------------------
3 files changed, 121 insertions(+), 94 deletions(-)
create mode 100644 scripts/libmakepkg/srcinfo.sh.in
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index d660c0b..2dfd238 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -74,6 +74,7 @@ LIBMAKEPKG_IN = \
libmakepkg/lint_pkgbuild/source.sh \
libmakepkg/lint_pkgbuild/util.sh \
libmakepkg/lint_pkgbuild/variable.sh \
+ libmakepkg/srcinfo.sh \
libmakepkg/source.sh \
libmakepkg/source/bzr.sh \
libmakepkg/source/file.sh \
diff --git a/scripts/libmakepkg/srcinfo.sh.in b/scripts/libmakepkg/srcinfo.sh.in
new file mode 100644
index 0000000..96dc59b
--- /dev/null
+++ b/scripts/libmakepkg/srcinfo.sh.in
@@ -0,0 +1,120 @@
+#!/bin/bash
+#
+# srcinfo.sh - functions for writing .SRCINFO files
+#
+# Copyright (c) 2016 Pacman Development Team <pacman-dev at archlinux.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[[ -n "$LIBMAKEPKG_SRCINFO_SH" ]] && return
+LIBMAKEPKG_SRCINFO_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/pkgbuild.sh"
+
+srcinfo_open_section() {
+ printf '%s = %s\n' "$1" "$2"
+}
+
+srcinfo_close_section() {
+ echo
+}
+
+srcinfo_write_attr() {
+ # $1: attr name
+ # $2: attr values
+
+ local attrname=$1 attrvalues=("${@:2}")
+
+ # normalize whitespace, strip leading and trailing
+ attrvalues=("${attrvalues[@]//+([[:space:]])/ }")
+ attrvalues=("${attrvalues[@]#[[:space:]]}")
+ attrvalues=("${attrvalues[@]%[[:space:]]}")
+
+ printf "\t$attrname = %s\n" "${attrvalues[@]}"
+}
+
+pkgbuild_extract_to_srcinfo() {
+ # $1: pkgname
+ # $2: attr name
+ # $3: multivalued
+
+ local pkgname=$1 attrname=$2 isarray=$3 outvalue=
+
+ if get_pkgbuild_attribute "$pkgname" "$attrname" "$isarray" 'outvalue'; then
+ srcinfo_write_attr "$attrname" "${outvalue[@]}"
+ fi
+}
+
+srcinfo_write_section_details() {
+ local attr package_arch a
+ local multivalued_arch_attrs=(source provides conflicts depends replaces
+ optdepends makedepends checkdepends
+ {md5,sha{1,224,256,384,512}}sums)
+
+ for attr in "${singlevalued[@]}"; do
+ pkgbuild_extract_to_srcinfo "$1" "$attr" 0
+ done
+
+ for attr in "${multivalued[@]}"; do
+ pkgbuild_extract_to_srcinfo "$1" "$attr" 1
+ done
+
+ get_pkgbuild_attribute "$1" 'arch' 1 'package_arch'
+ for a in "${package_arch[@]}"; do
+ # 'any' is special. there's no support for, e.g. depends_any.
+ [[ $a = any ]] && continue
+
+ for attr in "${multivalued_arch_attrs[@]}"; do
+ pkgbuild_extract_to_srcinfo "$1" "${attr}_$a" 1
+ done
+ done
+}
+
+srcinfo_write_global() {
+ local singlevalued=(pkgdesc pkgver pkgrel epoch url install changelog)
+ local multivalued=(arch groups license checkdepends makedepends
+ depends optdepends provides conflicts replaces
+ noextract options backup
+ source validpgpkeys {md5,sha{1,224,256,384,512}}sums)
+
+ srcinfo_open_section 'pkgbase' "${pkgbase:-$pkgname}"
+ srcinfo_write_section_details ''
+ srcinfo_close_section
+}
+
+srcinfo_write_package() {
+ local singlevalued=(pkgdesc url install changelog)
+ local multivalued=(arch groups license checkdepends depends optdepends
+ provides conflicts replaces options backup)
+
+ srcinfo_open_section 'pkgname' "$1"
+ srcinfo_write_section_details "$1"
+ srcinfo_close_section
+}
+
+write_srcinfo() {
+ local pkg
+
+ printf "# Generated by makepkg %s\n" "$makepkg_version"
+ printf "# %s\n" "$(LC_ALL=C date -u)"
+
+ srcinfo_write_global
+
+ for pkg in "${pkgname[@]}"; do
+ srcinfo_write_package "$pkg"
+ done
+}
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 80b95f4..4411ac2 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -999,100 +999,6 @@ find_libprovides() {
printf '%s\n' "${libprovides[@]}"
}
-srcinfo_open_section() {
- printf '%s = %s\n' "$1" "$2"
-}
-
-srcinfo_close_section() {
- echo
-}
-
-srcinfo_write_attr() {
- # $1: attr name
- # $2: attr values
-
- local attrname=$1 attrvalues=("${@:2}")
-
- # normalize whitespace, strip leading and trailing
- attrvalues=("${attrvalues[@]//+([[:space:]])/ }")
- attrvalues=("${attrvalues[@]#[[:space:]]}")
- attrvalues=("${attrvalues[@]%[[:space:]]}")
-
- printf "\t$attrname = %s\n" "${attrvalues[@]}"
-}
-
-pkgbuild_extract_to_srcinfo() {
- # $1: pkgname
- # $2: attr name
- # $3: multivalued
-
- local pkgname=$1 attrname=$2 isarray=$3 outvalue=
-
- if get_pkgbuild_attribute "$pkgname" "$attrname" "$isarray" 'outvalue'; then
- srcinfo_write_attr "$attrname" "${outvalue[@]}"
- fi
-}
-
-srcinfo_write_section_details() {
- local attr package_arch a
- local multivalued_arch_attrs=(source provides conflicts depends replaces
- optdepends makedepends checkdepends
- {md5,sha{1,224,256,384,512}}sums)
-
- for attr in "${singlevalued[@]}"; do
- pkgbuild_extract_to_srcinfo "$1" "$attr" 0
- done
-
- for attr in "${multivalued[@]}"; do
- pkgbuild_extract_to_srcinfo "$1" "$attr" 1
- done
-
- get_pkgbuild_attribute "$1" 'arch' 1 'package_arch'
- for a in "${package_arch[@]}"; do
- # 'any' is special. there's no support for, e.g. depends_any.
- [[ $a = any ]] && continue
-
- for attr in "${multivalued_arch_attrs[@]}"; do
- pkgbuild_extract_to_srcinfo "$1" "${attr}_$a" 1
- done
- done
-}
-
-srcinfo_write_global() {
- local singlevalued=(pkgdesc pkgver pkgrel epoch url install changelog)
- local multivalued=(arch groups license checkdepends makedepends
- depends optdepends provides conflicts replaces
- noextract options backup
- source validpgpkeys {md5,sha{1,224,256,384,512}}sums)
-
- srcinfo_open_section 'pkgbase' "${pkgbase:-$pkgname}"
- srcinfo_write_section_details ''
- srcinfo_close_section
-}
-
-srcinfo_write_package() {
- local singlevalued=(pkgdesc url install changelog)
- local multivalued=(arch groups license checkdepends depends optdepends
- provides conflicts replaces options backup)
-
- srcinfo_open_section 'pkgname' "$1"
- srcinfo_write_section_details "$1"
- srcinfo_close_section
-}
-
-write_srcinfo() {
- local pkg
-
- printf "# Generated by makepkg %s\n" "$makepkg_version"
- printf "# %s\n" "$(LC_ALL=C date -u)"
-
- srcinfo_write_global
-
- for pkg in "${pkgname[@]}"; do
- srcinfo_write_package "$pkg"
- done
-}
-
write_pkginfo() {
local builddate=$(date -u "+%s")
if [[ -n $PACKAGER ]]; then
--
2.7.0
More information about the pacman-dev
mailing list