From 04a7dda6a6e34b48dcd5fc98e68dd4751b7ac1b7 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Mon, 10 Sep 2012 07:22:18 +0000
Subject: [PATCH] main/abuild: more provides fixes

need special handling when file name is .so (no version number suffix)
and soname has a version number suffix. This is so we dont set provides
version to 0 when it should have been something else.

This fixes issue with libgcj/gcc-java who ships a file libgcj_bc.so with
soname libgcj_bc.so.1 in addition to the libgcj_bc.so.1.0.0 file.

We cannot have 2 provides with same name but with different version.
---
 ...upport-for-uncompressed-tar-archives.patch |  26 ---
 ...build-add-version-number-to-provides.patch |  27 ---
 ...-correct-version-number-for-provides.patch |  69 ------
 ...anelf-soname-to-find-the-provides-so.patch |  32 ---
 ...ild-use-so-as-namespace-for-provides.patch |  26 ---
 ...0002-abuild-add-provides-information.patch |  29 ---
 main/abuild/APKBUILD                          |  19 +-
 main/abuild/abuild-git-20120908.patch         | 203 ++++++++++++++++++
 8 files changed, 207 insertions(+), 224 deletions(-)
 delete mode 100644 main/abuild/0001-abuild-add-support-for-uncompressed-tar-archives.patch
 delete mode 100644 main/abuild/0001-abuild-add-version-number-to-provides.patch
 delete mode 100644 main/abuild/0001-abuild-include-correct-version-number-for-provides.patch
 delete mode 100644 main/abuild/0001-abuild-use-scanelf-soname-to-find-the-provides-so.patch
 delete mode 100644 main/abuild/0001-abuild-use-so-as-namespace-for-provides.patch
 delete mode 100644 main/abuild/0002-abuild-add-provides-information.patch
 create mode 100644 main/abuild/abuild-git-20120908.patch

diff --git a/main/abuild/0001-abuild-add-support-for-uncompressed-tar-archives.patch b/main/abuild/0001-abuild-add-support-for-uncompressed-tar-archives.patch
deleted file mode 100644
index 6ae675218a22..000000000000
--- a/main/abuild/0001-abuild-add-support-for-uncompressed-tar-archives.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From a5f67dcf25fae7c0200298623cccb61d9275fd28 Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Wed, 23 May 2012 09:42:27 +0000
-Subject: [PATCH] abuild: add support for uncompressed tar archives
-
----
- abuild.in |    3 +++
- 1 file changed, 3 insertions(+)
-
-diff --git a/abuild.in b/abuild.in
-index 2780d2e..32dd153 100755
---- a/abuild.in
-+++ b/abuild.in
-@@ -404,6 +404,9 @@ default_unpack() {
- 	for u in $source; do
- 		local s="$SRCDEST/${u##*/}"	# $(basename $s)
- 		case "$s" in
-+			*.tar)
-+				msg "Unpacking $s..."
-+				tar -C "$srcdir" -xf "$s" || return 1;;
- 			*.tar.gz|*.tgz)
- 				msg "Unpacking $s..."
- 				tar -C "$srcdir" -zxf "$s" || return 1;;
--- 
-1.7.10.2
-
diff --git a/main/abuild/0001-abuild-add-version-number-to-provides.patch b/main/abuild/0001-abuild-add-version-number-to-provides.patch
deleted file mode 100644
index 32a50dbfee48..000000000000
--- a/main/abuild/0001-abuild-add-version-number-to-provides.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From 7ca99d75b3c810546fec0418662586e34be141cd Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Wed, 5 Sep 2012 08:10:13 +0000
-Subject: [PATCH] abuild: add version number to provides
-
-So it is not treated as a special 'virtual'
-We use version number 0 for now.
----
- abuild.in | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/abuild.in b/abuild.in
-index 207cc66..f4d724c 100755
---- a/abuild.in
-+++ b/abuild.in
-@@ -921,7 +921,7 @@ trace_apk_deps() {
- 
- 	echo "# automatically detected:" >> "$dir"/.PKGINFO
- 	if [ -f "$dir"/.provides-so ]; then
--		sed 's/^/provides = /' "$dir"/.provides-so >> "$dir"/.PKGINFO
-+		sed 's/^\(.*\)/provides = \1=0/' "$dir"/.provides-so >> "$dir"/.PKGINFO
- 	fi
- 	[ -z "$autodeps" ] && return 0
- 	for i in $autodeps; do
--- 
-1.7.12
-
diff --git a/main/abuild/0001-abuild-include-correct-version-number-for-provides.patch b/main/abuild/0001-abuild-include-correct-version-number-for-provides.patch
deleted file mode 100644
index 49c3d4db84c2..000000000000
--- a/main/abuild/0001-abuild-include-correct-version-number-for-provides.patch
+++ /dev/null
@@ -1,69 +0,0 @@
-From 14af6a80cfbf657423334614b37a8f6f688dfe1a Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Wed, 5 Sep 2012 12:26:45 +0000
-Subject: [PATCH] abuild: include correct version number for provides
-
-This changes the format of .provides-so file. We now add a column with
-the version number
----
- abuild.in | 16 ++++++++++++----
- 1 file changed, 12 insertions(+), 4 deletions(-)
-
-diff --git a/abuild.in b/abuild.in
-index ecb7c4d..a9ed449 100755
---- a/abuild.in
-+++ b/abuild.in
-@@ -775,14 +775,22 @@ EOF
- 
- prepare_tracedeps() {
- 	local dir=${subpkgdir:-$pkgdir}
-+	local etype= soname= file= sover=
- 	[ "$arch" = "noarch" ] && return 0
- 	options_has "!tracedeps" && return 0
- 	# lets tell all the .so files this package provides in .provides-so
- 	scanelf --recursive --nobanner --soname "$dir" | while read etype soname file; do
- 		# if soname field is missing, soname will be the filepath
- 		# we only want shared libs
-+		sover=0
- 		case $soname in
--		*.so|*.so.[0-9]*) echo ${soname##*/};;
-+		*.so|*.so.[0-9]*)
-+			soname=${soname##*/}
-+			case "$file" in
-+			*.so.[0-9]*) sover=${file##*.so.};;
-+			esac
-+			echo "$soname $sover"
-+			;;
- 		esac
- 	done >"$controldir"/.provides-so
- 	# lets tell all the places we should look for .so files - all rpaths
-@@ -794,7 +802,7 @@ prepare_tracedeps() {
- 		| sed 's:,:\n:g' | sort | uniq \
- 	| while read i; do
- 		# only add files that are not self provided
--		grep "^$i$" "$controldir"/.provides-so >/dev/null \
-+		grep -q -w "^$i" "$controldir"/.provides-so \
- 			|| echo $i >> "$controldir"/.needs-so
- 	done
- }
-@@ -888,7 +896,7 @@ trace_apk_deps() {
- 		found=
- 		# first check if its provide by same apkbuild
- 		for j in "$dir"/../.control.*/.provides-so; do
--			grep -w "$i" "$j" >/dev/null || continue
-+			grep -q -w "^$i" "$j" || continue
- 			found=${j%/.provides-so}
- 			found=${found##*/.control.}
- 			break
-@@ -921,7 +929,7 @@ trace_apk_deps() {
- 
- 	echo "# automatically detected:" >> "$dir"/.PKGINFO
- 	if [ -f "$dir"/.provides-so ]; then
--		sed 's/^\(.*\)/provides = so:\1=0/' "$dir"/.provides-so \
-+		sed 's/^\(.*\) \([0-9].*\)/provides = so:\1=\2/' "$dir"/.provides-so \
- 			>> "$dir"/.PKGINFO
- 	fi
- 	[ -z "$autodeps" ] && return 0
--- 
-1.7.12
-
diff --git a/main/abuild/0001-abuild-use-scanelf-soname-to-find-the-provides-so.patch b/main/abuild/0001-abuild-use-scanelf-soname-to-find-the-provides-so.patch
deleted file mode 100644
index 8fe9ce296c33..000000000000
--- a/main/abuild/0001-abuild-use-scanelf-soname-to-find-the-provides-so.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-From 87953c711587b932fb8e9f95798a0907faaaecf6 Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Tue, 4 Sep 2012 12:30:08 +0000
-Subject: [PATCH 1/2] abuild: use scanelf --soname to find the provides-so
-
----
- abuild.in | 9 +++++++--
- 1 file changed, 7 insertions(+), 2 deletions(-)
-
-diff --git a/abuild.in b/abuild.in
-index 32dd153..3acec46 100755
---- a/abuild.in
-+++ b/abuild.in
-@@ -778,8 +778,13 @@ prepare_tracedeps() {
- 	[ "$arch" = "noarch" ] && return 0
- 	options_has "!tracedeps" && return 0
- 	# lets tell all the .so files this package provides in .provides-so
--	find -name '*.so' -o -name '*.so.[0-9]*' | sed 's:.*/::' \
--		>"$controldir"/.provides-so
-+	scanelf --recursive --nobanner --soname "$dir" | while read etype soname file; do
-+		# if soname field is missing, soname will be the filepath
-+		# we only want shared libs
-+		case $soname in
-+		*.so|*.so.[0-9]*) echo ${soname##*/};;
-+		esac
-+	done >"$controldir"/.provides-so
- 	# lets tell all the places we should look for .so files - all rpaths
- 	scanelf -q -Rr "$dir" | sed -e 's/[[:space:]].*//' -e 's/:/\n/' \
- 		| sort | uniq \
--- 
-1.7.12
-
diff --git a/main/abuild/0001-abuild-use-so-as-namespace-for-provides.patch b/main/abuild/0001-abuild-use-so-as-namespace-for-provides.patch
deleted file mode 100644
index 5b6b1de954b5..000000000000
--- a/main/abuild/0001-abuild-use-so-as-namespace-for-provides.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From a5cc84e229a40d725c1d53d1b0924a9ef9a615e0 Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Wed, 5 Sep 2012 11:09:57 +0000
-Subject: [PATCH] abuild: use 'so:' as 'namespace' for provides
-
----
- abuild.in | 3 ++-
- 1 file changed, 2 insertions(+), 1 deletion(-)
-
-diff --git a/abuild.in b/abuild.in
-index f4d724c..ecb7c4d 100755
---- a/abuild.in
-+++ b/abuild.in
-@@ -921,7 +921,8 @@ trace_apk_deps() {
- 
- 	echo "# automatically detected:" >> "$dir"/.PKGINFO
- 	if [ -f "$dir"/.provides-so ]; then
--		sed 's/^\(.*\)/provides = \1=0/' "$dir"/.provides-so >> "$dir"/.PKGINFO
-+		sed 's/^\(.*\)/provides = so:\1=0/' "$dir"/.provides-so \
-+			>> "$dir"/.PKGINFO
- 	fi
- 	[ -z "$autodeps" ] && return 0
- 	for i in $autodeps; do
--- 
-1.7.12
-
diff --git a/main/abuild/0002-abuild-add-provides-information.patch b/main/abuild/0002-abuild-add-provides-information.patch
deleted file mode 100644
index a4ea86964116..000000000000
--- a/main/abuild/0002-abuild-add-provides-information.patch
+++ /dev/null
@@ -1,29 +0,0 @@
-From 76e93e602f74e0fcf8cfc708fd93b4f71b74781e Mon Sep 17 00:00:00 2001
-From: Natanael Copa <ncopa@alpinelinux.org>
-Date: Tue, 4 Sep 2012 13:37:26 +0000
-Subject: [PATCH 2/2] abuild: add provides information
-
----
- abuild.in | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
-
-diff --git a/abuild.in b/abuild.in
-index 3acec46..207cc66 100755
---- a/abuild.in
-+++ b/abuild.in
-@@ -919,8 +919,11 @@ trace_apk_deps() {
- 		fi
- 	done
- 
--	[ -z "$autodeps" ] && return 0
- 	echo "# automatically detected:" >> "$dir"/.PKGINFO
-+	if [ -f "$dir"/.provides-so ]; then
-+		sed 's/^/provides = /' "$dir"/.provides-so >> "$dir"/.PKGINFO
-+	fi
-+	[ -z "$autodeps" ] && return 0
- 	for i in $autodeps; do
- 		echo "depend = $i" >> "$dir"/.PKGINFO
- 	done
--- 
-1.7.12
-
diff --git a/main/abuild/APKBUILD b/main/abuild/APKBUILD
index bb16bc9aedcb..0aaaf26d71cb 100644
--- a/main/abuild/APKBUILD
+++ b/main/abuild/APKBUILD
@@ -2,16 +2,8 @@
 pkgdesc="Script to build Alpine Packages"
 pkgname=abuild
 pkgver=2.12.1
-pkgrel=4
+pkgrel=5
 url=http://git.alpinelinux.org/cgit/abuild/
-source="http://git.alpinelinux.org/cgit/abuild/snapshot/abuild-$pkgver.tar.bz2
-	0001-abuild-add-support-for-uncompressed-tar-archives.patch
-	0001-abuild-use-scanelf-soname-to-find-the-provides-so.patch
-	0002-abuild-add-provides-information.patch
-	0001-abuild-add-version-number-to-provides.patch
-	0001-abuild-use-so-as-namespace-for-provides.patch
-	0001-abuild-include-correct-version-number-for-provides.patch
-	"
 depends="fakeroot file sudo pax-utils openssl apk-tools>=2.0.7-r1 uclibc-utils
 	abuildhelper curl"
 makedepends="openssl-dev pkgconfig"
@@ -20,6 +12,8 @@ subpackages="apkbuild-cpan:cpan"
 pkggroups="abuild"
 arch="all"
 license=GPL-2
+source="http://git.alpinelinux.org/cgit/abuild/snapshot/abuild-$pkgver.tar.bz2
+	abuild-git-20120908.patch"
 
 prepare() {
 	cd "$srcdir/$pkgname-$pkgver"
@@ -54,9 +48,4 @@ cpan() {
 }
 
 md5sums="92348750a3354c3ec7b811716543b8e5  abuild-2.12.1.tar.bz2
-b04eb6325bf8014ea9fc974344f71a82  0001-abuild-add-support-for-uncompressed-tar-archives.patch
-8ba51a92d24d9e54bfdd1133bc2f0f8d  0001-abuild-use-scanelf-soname-to-find-the-provides-so.patch
-454e0c6a8a3ee97ec4b00874203f700c  0002-abuild-add-provides-information.patch
-e8e910f86ed1892bd46facb88164a27b  0001-abuild-add-version-number-to-provides.patch
-1b3e30efede1bccff3f2686a4355a71d  0001-abuild-use-so-as-namespace-for-provides.patch
-ddeb905afd9a486902f70eea824fcd05  0001-abuild-include-correct-version-number-for-provides.patch"
+877d6a683752d9cca041b2b545901fd8  abuild-git-20120908.patch"
diff --git a/main/abuild/abuild-git-20120908.patch b/main/abuild/abuild-git-20120908.patch
new file mode 100644
index 000000000000..847f767495dd
--- /dev/null
+++ b/main/abuild/abuild-git-20120908.patch
@@ -0,0 +1,203 @@
+diff --git a/abuild.in b/abuild.in
+index 2780d2e..60cb91c 100755
+--- a/abuild.in
++++ b/abuild.in
+@@ -404,6 +404,9 @@ default_unpack() {
+ 	for u in $source; do
+ 		local s="$SRCDEST/${u##*/}"	# $(basename $s)
+ 		case "$s" in
++			*.tar)
++				msg "Unpacking $s..."
++				tar -C "$srcdir" -xf "$s" || return 1;;
+ 			*.tar.gz|*.tgz)
+ 				msg "Unpacking $s..."
+ 				tar -C "$srcdir" -zxf "$s" || return 1;;
+@@ -772,23 +775,20 @@ EOF
+ 
+ prepare_tracedeps() {
+ 	local dir=${subpkgdir:-$pkgdir}
++	local etype= soname= file= sover=
+ 	[ "$arch" = "noarch" ] && return 0
+ 	options_has "!tracedeps" && return 0
+-	# lets tell all the .so files this package provides in .provides-so
+-	find -name '*.so' -o -name '*.so.[0-9]*' | sed 's:.*/::' \
+-		>"$controldir"/.provides-so
+ 	# lets tell all the places we should look for .so files - all rpaths
+-	scanelf -q -Rr "$dir" | sed -e 's/[[:space:]].*//' -e 's/:/\n/' \
+-		| sort | uniq \
++	scanelf --quiet --recursive --rpath "$dir" \
++		| sed -e 's/[[:space:]].*//' -e 's/:/\n/' | sort -u \
+ 		>"$controldir"/.rpaths
+-	# now find the so dependencies
+-	scanelf -Rn "$dir" | tr ' ' ':' | awk -F ":" '$1 == "ET_DYN" || $1 == "ET_EXEC" {print $2}'  \
+-		| sed 's:,:\n:g' | sort | uniq \
+-	| while read i; do
+-		# only add files that are not self provided
+-		grep "^$i$" "$controldir"/.provides-so >/dev/null \
+-			|| echo $i >> "$controldir"/.needs-so
+-	done
++	if grep -q -x '/usr/lib' "$controldir"/.rpaths; then
++		warning "Redundat /usr/lib in rpath found"
++	fi
++	if grep '^/home/' "$controldir"/.rpaths; then
++		error "Has /home/... in rpath"
++		return 1
++	fi
+ }
+ 
+ # check if dir has arch specific binaries
+@@ -862,7 +862,7 @@ trace_apk_deps() {
+ 	local name="$1"
+ 	local dir="$2"
+ 	local i= j= found= autodeps= deppkgs= missing= so_paths= self_provided=
+-	msg "Tracing dependencies for $name..."
++	msg "Tracing dependencies..."
+ 	# add pkgconfig if usr/lib/pkgconfig is found
+ 	if [ -d "$pkgbasedir"/$name/usr/lib/pkgconfig ] \
+ 			&& ! grep -q '^depend = pkgconfig' "$dir"/.PKGINFO; then
+@@ -880,7 +880,7 @@ trace_apk_deps() {
+ 		found=
+ 		# first check if its provide by same apkbuild
+ 		for j in "$dir"/../.control.*/.provides-so; do
+-			grep -w "$i" "$j" >/dev/null || continue
++			grep -q -w "^$i" "$j" || continue
+ 			found=${j%/.provides-so}
+ 			found=${found##*/.control.}
+ 			break
+@@ -911,26 +911,106 @@ trace_apk_deps() {
+ 		fi
+ 	done
+ 
+-	[ -z "$autodeps" ] && return 0
+ 	echo "# automatically detected:" >> "$dir"/.PKGINFO
++	if [ -f "$dir"/.provides-so ]; then
++		sed 's/^\(.*\) \([0-9].*\)/provides = so:\1=\2/' "$dir"/.provides-so \
++			>> "$dir"/.PKGINFO
++	fi
++	[ -z "$autodeps" ] && return 0
+ 	for i in $autodeps; do
+ 		echo "depend = $i" >> "$dir"/.PKGINFO
+ 	done
+ }
+ 
++find_scanelf_paths() {
++	local controldir="$1" datadir="$2"
++	local paths="$datadir/lib:$datadir/usr/lib" i= rpath=
++	if [ -n "$ldpath" ]; then
++		paths="$paths:$(echo "$ldpath" | sed "s|\(^\|:\)|\1$datadir|g")"
++	fi
++	# search in all rpaths
++	for rpath in "$pkgbasedir"/.control.*/.rpath; do
++		[ -f "$rpath" ] || continue
++		while read i; do
++			if [ -d "$datadir/$i" ]; then
++				paths="$paths:$datadir/$i"
++			fi
++		done < "$rpath"
++	done
++	echo "$paths"
++}
++
++scan_shared_objects() {
++	local name="$1" controldir="$2" datadir="$3"
++
++	# allow spaces in paths
++	IFS=:
++	set -- $(find_scanelf_paths "$controldir" "$datadir")
++	unset IFS
++
++	msg "Scanning shared objects"
++	# lets tell all the .so files this package provides in .provides-so
++	scanelf --nobanner --soname "$@" | while read etype soname file; do
++		# if soname field is missing, soname will be the filepath
++		sover=0
++		if [ -z "$file" ]; then
++			file="$soname"
++			soname=${soname##*/}
++		fi
++
++		# we only want shared libs
++		case $soname in
++		*.so|*.so.[0-9]*);;
++		*) continue;;
++		esac
++
++		case "$file" in
++		*.so.[0-9]*) sover=${file##*.so.};;
++		*.so)
++			# filter out sonames with version when file does not
++			# have version
++			case "$soname" in
++			*.so.[0-9]*) continue;;
++			esac
++			;;
++		esac
++		echo "$soname $sover"
++	done > "$controldir"/.provides-so
++
++	# now find the so dependencies
++	scanelf --nobanner --recursive --needed "$datadir"  | tr ' ' ':' \
++		| awk -F ":" '$1 == "ET_DYN" || $1 == "ET_EXEC" {print $2}'  \
++		| sed 's:,:\n:g' | sort -u \
++	| while read i; do
++		# only add files that are not self provided
++		grep -q -w "^$i" "$controldir"/.provides-so \
++			|| echo $i
++	done > "$controldir"/.needs-so
++}
++
+ create_apks() {
+-	local file
++	local file= dir= name= ver= apk= datadir=
+ 	getpkgver || return 1
+ 	mkdir -p "$PKGDEST"
++	if [ "$arch" != "noarch" ] && ! options_has "!tracedeps"; then
++		for file in "$pkgbasedir"/.control.*/.PKGINFO; do
++			dir="${file%/.PKGINFO}"
++			name="$(pkginfo_val pkgname $file)"
++			datadir="$pkgbasedir"/$name
++			subpkgname=$name
++			scan_shared_objects "$name" "$dir" "$datadir"
++		done
++	fi
+ 	for file in "$pkgbasedir"/.control.*/.PKGINFO; do
+-		local dir="${file%/.PKGINFO}"
+-		local name=$(pkginfo_val pkgname $file)
+-		local ver=$(pkginfo_val pkgver $file)
+-		local apk=$name-$ver.apk
+-		local datadir="$pkgbasedir"/$name
++		dir="${file%/.PKGINFO}"
++		name=$(pkginfo_val pkgname $file)
++		ver=$(pkginfo_val pkgver $file)
++		apk=$name-$ver.apk
++		datadir="$pkgbasedir"/$name
++		subpkgname=$name
+ 
+ 		trace_apk_deps "$name" "$dir" || return 1
+-		msg "Creating $apk..."
++		msg "Compressing data..."
+ 		(
+ 		cd "$datadir"
+ 		# data.tar.gz
+@@ -941,6 +1021,7 @@ create_apks() {
+ 		fi
+ 		tar -c "$@" | abuild-tar --hash | gzip -9 >"$dir"/data.tar.gz
+ 
++		msg "Create checksum..."
+ 		# append the hash for data.tar.gz
+ 		local sha256=$(sha256sum "$dir"/data.tar.gz | cut -f1 -d' ')
+ 		echo "datahash = $sha256" >> "$dir"/.PKGINFO
+@@ -951,10 +1032,12 @@ create_apks() {
+ 			| gzip -9 > control.tar.gz
+ 		abuild-sign -q control.tar.gz || exit 1
+ 
++		msg "Create $apk"
+ 		# create the final apk
+ 		cat control.tar.gz data.tar.gz > "$PKGDEST"/$apk
+-	)
++		)
+ 	done
++	subpkgname=
+ }
+ 
+ clean_abuildrepo() {
-- 
GitLab