[pacman-dev] [RFC] makepkg: introduce .SRCINFO files for source packages

Dave Reisner dreisner at archlinux.org
Sat Oct 18 01:59:31 UTC 2014


Similar to .PKGINFO, .SRCINFO provides structured metadata from the
PKGBUILD to be included with source packages.

The format is structured such that it contains a "pkgbase" and one to
many "pkgname" sections.  Each "pkgname" section represents an "output
package", and inherits all of the attributes of the "pkgbase" section,
and then can define their own additive fields.

For example, a simple PKGBUILD:

  pkgbase=ponies
  pkgname=('applejack' 'pinkiepie')
  pkgver=1.2.3
  pkgrel=1
  arch=('x86_64' 'i686')
  depends=('friendship' 'magic')

  build() { ...; }

  package_applejack() {
    provides=('courage')

    ...;
  }

  package_pinkiepie() {
    provides=('laughter')

    ...;
  }

Would yield the following .SRCINFO file:

  pkgbase = ponies
  	pkgdesc = friendship is magic
  	pkgver = 1.2.3
  	pkgrel = 1
  	arch = x86_64
  	arch = i686
  	depends = friendship
  	depends = magic

  pkgname = applejack
  	provides = courage

  pkgname = pinkiepie
  	provides = laughter

The code to generate this new file is taken a project which I've been
incubating[0] under the guise of 'mkaurball', which creates .AURINFO
files for the AUR. AURINFO is the exactly same file as .SRCINFO, but
named as such to make it clear that this is specific to the AUR.

Because we're parsing shell in the packaging functions rather than
executing it, there *are* some limitations, but these only really crop
up in more "exotic" PKGBUILDs. Smoketesting[1] for accuracy in the Arch
repos yields 100% accuracy for [core] and [extra]. [community] clocks in
at ~98% accuracy (.3% difference per PKGBUILD), largely due to silly
haskell packages calling pacman from inside the PKGBUILD to determine
dependencies. [multilib] currently shows about 92% accuracy -- a
statistic which can be largely improved by utilizing the recently merged
arch-specific attribute work. This is also a smaller repo so the numbers
are somewhat inflated. In reality, this is only a .8% variance per
PKGBUILD.

Together, we can make PKGBUILD better.

[0] https://github.com/falconindy/pkgbuild-introspection
[1] https://github.com/falconindy/pkgbuild-introspection/blob/master/test/smoketest
---
Based on Allan's recent email about the feature freeze being pushed back,
I'm offering this up for discussion.

 scripts/makepkg.sh.in | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 8a67d94..0349e05 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -2031,6 +2031,99 @@ 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 pkgbuild_get_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)
+
+	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
+
+	pkgbuild_get_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 {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
@@ -2243,6 +2336,9 @@ create_srcpackage() {
 	msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
 	ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
 
+	msg2 "$(gettext "Generating %s file...")" .SRCINFO
+	write_srcinfo > "$srclinks/$pkgbase"/.SRCINFO
+
 	local file all_sources
 
 	get_all_sources 'all_sources'
-- 
2.1.2


More information about the pacman-dev mailing list