avatar
mikhailnov has added 67955e1476
Avoid dependencies from libraries outside of standard directories

Example: avoid dependencies from /usr/lib64/tracker-2.0/xxx.so

view file @ 67955e1476
... ... --- a/devel-rpm-generators.spec
... ... +++ b/devel-rpm-generators.spec
... ... @@ -3,7 +3,7 @@ Name: devel-rpm-generators
3 3
Group:		System/Libraries
4 4
License:	GPLv2
5 5
Url:		https://abf.io/import/devel-rpm-generators
6
Version:	0.13
6
Version:	0.14
7 7
Release:	1
8 8
Source0:	develgen.sh
9 9
Source1:	develgen.attr
... ... --- a/develgen.sh
... ... +++ b/develgen.sh
... ... @@ -10,6 +10,11 @@ echo_filter() {
10 10
	fi
11 11
}
12 12
13
if [ -z "$RPM_BUILD_ROOT" ]; then
14
	echoerr 'Error: $RPM_BUILD_ROOT variable is not set.'
15
	exit 1
16
fi
17
13 18
suffix=""
14 19
suffix_orig="$suffix"
15 20
auto=0
... ... @@ -17,6 +22,32 @@ auto=0
22 22
if [ "$2" = 64 ]; then
23 23
	suffix="(64bit)"
24 24
fi
25
# The algorithm of $LIB_PATHS bellow is designed and works for a typical biarch system
26
# where all 64 bit libraries are in /usr/lib64 or /lib64 and 32 bit ones
27
# are in /usr/lib or /lib. Additional adoptation for multiarch may be needed.
28
case "$2" in
29
	64 )
30
		suffix="(64bit)"
31
		LIB_PATHS_list="/lib64 /usr/lib64 ${RPM_BUILD_ROOT}/lib64 ${RPM_BUILD_ROOT}/usr/lib64"
32
	;;
33
	32 )
34
		#suffix=""
35
		LIB_PATHS_list="/lib /usr/lib ${RPM_BUILD_ROOT}/lib ${RPM_BUILD_ROOT}/usr/lib"
36
	;;
37
	* )
38
		# This should be avoided
39
		# We do not verify that bitness of the executable and libraries here do match
40
		# TODO: maybe verify it
41
		LIB_PATHS_list="/lib64 /usr/lib64 ${RPM_BUILD_ROOT}/lib64 ${RPM_BUILD_ROOT}/usr/lib64 /usr/lib /lib ${RPM_BUILD_ROOT}/lib ${RPM_BUILD_ROOT}/usr/lib"
42
	;;
43
esac
44
LIB_PATHS=""
45
for i in ${LIB_PATHS_list} ; do
46
	if [ -d "$i" ]; then
47
		LIB_PATHS="${LIB_PATHS} ${i}"
48
	fi
49
done
50
unset LIB_PATHS_list
25 51
# 3rd arg may override the second arg
26 52
# enabled in glibc as:
27 53
# %define __devel_gen_auto_bitness 1
... ... @@ -99,6 +130,8 @@ case "$1" in
130 130
		done
131 131
	;;
132 132
	-R | --requires )
133
		# Save this to grep it later instead of rerunning find
134
		find_libs_list="$(find -L ${LIB_PATHS} -maxdepth 1 \( -name "*.so" -o -name "*.so.*" \))"
133 135
		while read -r file ; do
134 136
			case "$file" in
135 137
				*.so )
... ... @@ -110,7 +143,21 @@ case "$1" in
143 143
							echoerr 'develgen: Unknown error in patchelf --print-needed'
144 144
							continue
145 145
						fi
146
						echo_filter "devel(${i}${suffix})"
146
						# An example why this check is needed:
147
						# a library may contain RPATH:
148
						# $ patchelf --print-rpath libtracker-control-2.0.so.0
149
						# /usr/lib64/tracker-2.0
150
						# Without this check, a dependency from a library outside of
151
						# standard search paths will be put, but a provide will not exist.
152
						# Another possible approach is using ldd, but ldd can _theoretically_
153
						# execute code, so let's better avoid using it. This would also
154
						# check that bitness of libraries is correct. Actually this should
155
						# be checked not here but in e.g. spec-helper.
156
						# grep bellow will accept both foo.so and foo.so.1, it is intentional.
157
						if echo "$find_libs_list" | grep -q "/${i}.so"
158
							then echo_filter "devel(${i}${suffix})"
159
							else echoerr "$i was not found in ${LIB_PATHS}"
160
						fi
147 161
					done
148 162
				;;
149 163
				* )

Comments