Update test
[mono-project.git] / scripts / mono-find-requires.in
blobf0ad60bb8a2955b4b87e3433ae08fa0e470b196e
1 #!/bin/bash
3 # mono-find-requires
5 # Authors:
6 # Ben Maurer (bmaurer@ximian.com)
7 # Wade Berrier (wberrier@novell.com)
9 # (C) 2008 Novell (http://www.novell.com)
12 IFS=$'\n'
13 filelist=($(grep -Ev '/usr/doc/|/usr/share/doc/'))
14 monolist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.(exe|dll)\$"))
16 # parse .config files to find which native libraries to depend on
17 # (target attribute must have double quotes for this to work, ie: target="file" )
18 # Add /etc/mono/config ?
19 configlist=($(printf "%s\n" "${filelist[@]}" | egrep "\\.config\$"))
21 # Set the prefix, unless it is overriden (used when building mono rpms)
22 : ${prefix=@prefix@}
24 # Can override .config scanning if specified
25 : ${IGNORE_CONFIG_SCAN=0}
27 libdir=$prefix/@reloc_libdir@
28 bindir=$prefix/bin
30 # Bail out if monodis or libmono is missing
31 if [ ! -x $bindir/monodis ] || [ ! -f $libdir/libmono-2.0.so.1 ] ; then
32 echo "monodis missing or unusable, exiting..." 1>&2
33 exit 1
36 # special case for 64bit archs
37 if test "x@reloc_libdir@" = "xlib64" ; then
38 libext="()(64bit)"
39 else
40 # (note, this works on ppc64 since we only have 32bit mono)
41 libext=""
44 # Exceptions:
45 case `uname -m` in
46 # ia64 doesn't use lib64 for 'libdir' (sles 9 rpm used to provide both... no longer)
47 ia64) libext="()(64bit)" ;;
48 esac
50 # set LD_LIBRARY_PATH to ensure that libmono is found
51 export LD_LIBRARY_PATH=$libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
52 # and set MONO_PATH to ensure that mscorlib.dll can be found
53 export MONO_PATH=$prefix/lib/mono/2.0
55 REQUIRES=$(
56 for i in "${monolist[@]}"; do
57 ($bindir/monodis --assemblyref $i | awk '
58 BEGIN { START=0; LIBNAME=""; VERSION=""; }
59 (START==0) && /^[0-9]+: Version=/ {
60 START=1;
61 sub(/Version=/, "", $2);
62 VERSION=$2
65 (START==1) && /^\tName=/ {
66 sub(/Name=/, "", $1);
67 LIBNAME=$1
68 # Allow rpm deps to be resolved for 1.0 profile version
69 if (VERSION=="1.0.3300.0")
70 OP=">="
71 else
72 OP="="
73 print "mono(" LIBNAME ") " OP " " VERSION
74 START=0
76 ') 2> /dev/null
77 done
80 if [ $IGNORE_CONFIG_SCAN -eq 0 ] ; then
82 rpm_config_REQUIRES=$(
83 # Parse the xml .config files to see what native binaries we call into
84 # TODO: also check monodis --moduleref
85 for i in "${configlist[@]}"; do
86 awk 'match($_, /<dllmap .*target=.*/) {
87 ignore=0
88 req=""
89 split($_, toks, "\"")
90 toks_size=0
91 for(tok in toks) { toks_size++ }
92 for(i=1; i <= toks_size; i++) {
93 if(toks[i] ~ /target=/) {
94 req=toks[i+1]
96 if(toks[i] ~ /os=/) {
97 negate=0
98 found=0
100 attr=toks[i+1]
101 if(attr ~ /^!/) {
102 attr=substr(attr, 2, length(attr)-1)
103 negate=1
106 split(attr, os_targets, ",")
107 os_targets_size=0
108 for(os_target in os_targets) { os_targets_size++ }
109 for(j=1; j <= os_targets_size; j++) {
110 if(os_targets[j] == "linux") {
111 found=1
115 if(negate) {
116 found=!found
118 if (!found) {
119 ignore=1
123 if(!ignore) {
124 print req"'$libext'"
126 } ' $i 2>/dev/null
127 done
130 # Resolve provides to packages, warning on missing to stderr
131 config_REQUIRES=$(
132 first=1 # avoid an empty line if no .config reqs are found
133 for i in ${rpm_config_REQUIRES[@]} ; do
134 out=$(rpm -q --whatprovides --queryformat "%{NAME}\n" $i)
135 if [ $? -eq 0 ] ; then
136 if [ $first -eq 1 ] ; then
137 echo ""
138 first=0
140 echo $out
141 else
142 # echo to stderr
143 echo "mono-find-requires: Warning, could not find package that provides: $i" >&2
145 done
150 # Note about above:
151 # Use to do: system("rpm -q --whatprovides --queryformat \"%{NAME}\n\" ""\""req"'$libext'""\"")
152 # rpmlint prefers to have lib names instead of package names. There was a reason I was using package names but it slips me now...
153 # Ah... now I remember... it's for noarch packs. The noarch packages can be built on either 32 or 64 bit... so we have to depend
154 # on the package name instead.
156 PROVIDES=$(
157 for i in "${monolist[@]}"; do
158 ($bindir/monodis --assembly $i | awk '
159 BEGIN { LIBNAME=""; VERSION=""; }
160 /^Version:/ { VERSION=$2 }
161 /^Name:/ { LIBNAME=$2 }
162 END {
163 if (VERSION && LIBNAME)
164 print "mono(" LIBNAME ") = " VERSION
166 ') 2>/dev/null
167 done
170 # This is a little magic trick to get all REQUIRES that are not
171 # in PROVIDES. While RPM functions correctly when such deps exist,
172 # they make the metadata a bit bloated.
174 # TODO: make this use the mono-find-provides script, to share code
176 # Filter out dups from both lists
177 REQUIRES=$(echo "$REQUIRES $config_REQUIRES" | sort | uniq)
178 PROVIDES=$(echo "$PROVIDES" | sort | uniq)
181 # Get a list of elements that exist in exactly one of PROVIDES or REQUIRES
183 UNIQ=$(echo "$PROVIDES
184 $REQUIRES" | sort | uniq -u)
187 # Of those, only choose the ones that are in REQUIRES
189 echo "$UNIQ
190 $REQUIRES" | sort | uniq -d