From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-642794-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id BB4B5138247
	for <garchives@archives.gentoo.org>; Sat, 23 Nov 2013 02:05:43 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 3B9CCE09CB;
	Sat, 23 Nov 2013 02:05:40 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id B23FCE09CB
	for <gentoo-commits@lists.gentoo.org>; Sat, 23 Nov 2013 02:05:38 +0000 (UTC)
Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 7E9ED33DAC7
	for <gentoo-commits@lists.gentoo.org>; Sat, 23 Nov 2013 02:05:37 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by hornbill.gentoo.org (Postfix) with ESMTP id F0ED719002B
	for <gentoo-commits@lists.gentoo.org>; Sat, 23 Nov 2013 02:05:34 +0000 (UTC)
From: "Maciej Mrozowski" <reavertm@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Maciej Mrozowski" <reavertm@gentoo.org>
Message-ID: <1385172283.4e81ea0e963c31b13fe8a6386f6ac90f32606bd5.reavertm@gentoo>
Subject: [gentoo-commits] proj/kde:master commit in: Documentation/maintainers/
X-VCS-Repository: proj/kde
X-VCS-Files: Documentation/maintainers/dynlink-scanner
X-VCS-Directories: Documentation/maintainers/
X-VCS-Committer: reavertm
X-VCS-Committer-Name: Maciej Mrozowski
X-VCS-Revision: 4e81ea0e963c31b13fe8a6386f6ac90f32606bd5
X-VCS-Branch: master
Date: Sat, 23 Nov 2013 02:05:34 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: c42d48ec-98a3-4c91-921f-9547cabc9a33
X-Archives-Hash: 7e8b9c54fa05427f8f5977754534324b

commit:     4e81ea0e963c31b13fe8a6386f6ac90f32606bd5
Author:     Maciej Mrozowski <reavertm <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 23 01:54:05 2013 +0000
Commit:     Maciej Mrozowski <reavertm <AT> gentoo <DOT> org>
CommitDate: Sat Nov 23 02:04:43 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/kde.git;a=commit;h=4e81ea0e

[Documentation] Fix dynlink-scanner (make scanelf resolve full library paths, detect broken file utility, add some comments for easier maintenace in a future)

---
 Documentation/maintainers/dynlink-scanner | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/Documentation/maintainers/dynlink-scanner b/Documentation/maintainers/dynlink-scanner
index 07f4fff..017f929 100755
--- a/Documentation/maintainers/dynlink-scanner
+++ b/Documentation/maintainers/dynlink-scanner
@@ -1,9 +1,10 @@
 #!/bin/bash
 
-run_scanelf()
+# Returns colon separated list of linking dependencies
+get_link_deps()
 {
 	KEY=
-	for dep in `scanelf -yBF '%f %n' "$1"`; do
+	for dep in `scanelf --use-ldpath -yBF '%f %n' "$1"`; do
 		if [[ -z $KEY ]]; then
 			KEY="$dep"
 			continue
@@ -12,12 +13,19 @@ run_scanelf()
 	done
 }
 
-if [[ "$1" = --internal ]]; then
+# Print linking deps for given executable or shared object in alphabetical order.
+# Also try to dlopen shared objects in order to detect missing/broken dependencies.
+if [[ "$1" = --linking-deps ]]; then
+	# Sanity check, file-5.12 is broken, bail out early
+	if [[ `file --version | grep --color=never file- | cut -d'-' -f2` == '5.12' ]]; then
+		echo "file-5.12 is broken, bailing out"
+		exit 1
+	fi
 	mime=`file -b --mime-type "$2"`
 	if [[ "$mime" == 'application/x-executable' ]] || [[ "${mime}" == 'application/x-sharedlib' ]]; then
-		LINK=`run_scanelf "$2"`
+		LINK=`get_link_deps "$2"`
 		[[ "$mime" == 'application/x-sharedlib' ]] && /tmp/try_dlopen "$2"
-		[[ -n $LINK ]] && echo -e ${LINK//,/\\n}
+		[[ -n $LINK ]] && echo -e ${LINK//,/\\n} | sort -u
 		exit 0
 	fi
 	exit 1
@@ -25,17 +33,23 @@ fi
 
 [[ -z $* ]] && echo "usage: `basename $0` <package>" && exit 0
 
+# Check whether package is installed
 if ! portageq has_version $ROOT/ $1; then
 	echo "$1 is not installed"
 	exit 1
 fi
 
-LDLIBS=`/sbin/ldconfig -p`
+# Compile dlopen test application, we will use it to check for broken linking dependencies
 gcc "`dirname $0`/try_dlopen.c" -o /tmp/try_dlopen -ldl
 
+# For each installed slot
 for cpv in `portageq match $ROOT/ $1`; do
 	echo "Processing $cpv"
-	qfile -eR $ROOT `portageq contents $ROOT/ $cpv | xargs -r -L 1 "$0" --internal | sort -u` | cut -f1 -d' ' | sort -u
+	# For each file that belongs to package
+	#     run dynlink-scanner --linking-deps <file> to obtain its linking dependencies
+	# Assign all linking deps to packages and print package names
+	qfile -eR $ROOT `portageq contents $ROOT/ $cpv | xargs -r -L 1 "$0" --linking-deps` | cut -f1 -d' ' | sort -u
 done
 
+# Cleanup
 rm -f /tmp/try_dlopen