[pacman-dev] [PATCH 2/2] Append '-$arch' to 'installed' array in .BUILDINFO

Robin Broda robin at broda.me
Sat Mar 17 21:24:01 UTC 2018


This patch incurs a **severe** performance degradation when generating
the .BUILDINFO file, likely due to frequent usage of `pacman -Qi`
and `grep -E`. I haven't found a faster way to gather this information.

Signed-off-by: Robin Broda <robin at broda.me>
---
 doc/BUILDINFO.5.txt   |  2 +-
 scripts/makepkg.sh.in | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/doc/BUILDINFO.5.txt b/doc/BUILDINFO.5.txt
index 4734301e..2c74f9ff 100644
--- a/doc/BUILDINFO.5.txt
+++ b/doc/BUILDINFO.5.txt
@@ -61,7 +61,7 @@ BUILDINFO file format.
 
 *installed (array)*::
 	The installed packages at build time including the version information of
-	the package. Formatted as "$pkgname-$pkgver-$pkgrel".
+	the package. Formatted as "$pkgname-$pkgver-$pkgrel-$pkgarch".
 
 See Also
 --------
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index ece53dca..10303417 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -694,8 +694,16 @@ write_buildinfo() {
 	write_kv_pair "buildenv" "${BUILDENV[@]}"
 	write_kv_pair "options" "${OPTIONS[@]}"
 
-	local pkglist=($(run_pacman -Q | sed "s# #-#"))
-	write_kv_pair "installed" "${pkglist[@]}"
+	local pkglist=($(run_pacman -Qq))
+	local installed=()
+	for pkg in "${pkglist[@]}"
+	do
+		pkginfo="$(pacman -Qi "${pkg}")"
+		pkgver="$(grep -E '^Version' <<< "${pkginfo}" | tr -d ' ' | cut -d':' -f2-)"
+		pkgarch="$(grep -E '^Architecture' <<< "${pkginfo}" | tr -d ' ' | cut -d':' -f2-)"
+		installed+=("${pkg}-${pkgver}-${pkgarch}")
+	done
+	write_kv_pair "installed" "${installed[@]}"
 }
 
 # build a sorted NUL-separated list of the full contents of the current
-- 
2.16.2


More information about the pacman-dev mailing list