Debian Codegraph @

debian/dh_makeclilibs

raw
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_makeclilibs - automatically create clilibs file
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_makeclilibs> [S<I<debhelper options>>] [B<-r>] [B<-V>I<[dependancies]>] [B<-m>I<minversion>] [B<-l>I<nextincompatible>] [B<-X>I<item>]
15
16 =head1 DESCRIPTION
17
18 dh_makeclilibs is a debhelper program that automatically scans for
19 versioned CIL (.NET) assemblies, and generates a clilibs file for the
20 libraries it finds.
21
22 By default, dh_makeclilibs scans the .dll files in the package
23 directories and writes the discovered compatibility data (major/minor,
24 build, token) to "clilibs" files in the appropriate packages.
25
26 However, if a file like debian/package.clilibs is found, this one will
27 be installed and no scanning is performed.
28
29 =head1 OPTIONS
30
31 =over 4
32
33 =item B<-V>, B<-V>I<dependancies>
34
35 =item B<--version-info>, B<--version-info=>I<dependancies>
36
37 By default, the clilibs file generated by this program does not make packages
38 depend on any particular version of the package containing the assembly.
39 It may be necessary for you to add some version dependency
40 information to the clilibs file. If -V is specified with no dependency
41 information, the current version of the package is plugged into a
42 dependency that looks like "packagename (>= packageversion)". If -V is
43 specified with parameters, the parameters can be used to specify the exact
44 dependency information needed (be sure to include the package name).
45
46 Beware of using -V without any parameters; this is a conservative setting
47 that always ensures that other packages' shared library dependencies are at
48 least as tight as they need to be, so that if the maintainer screws up then
49 they won't break. The flip side is that packages might end up with
50 dependencies that are too tight and so find it harder to be upgraded.
51
52 =item B<-m>I<minversion>
53
54 Like -V, but specifies only the version string, the package name comes
55 from the package that is actually processed. This option is more
56 flexible if you try to set a range of valid versions for different
57 assembly packages coming from one source package.
58
59 =item B<-l>I<nextincompatible>
60
61 Specifies the (expected) version of this package when the compatibility
62 to the current assemblies will break.
63
64 =item B<-r>
65
66 An experimental option to automaticaly guess the next incompatible
67 upstream version and insert them (like working with -l and -m options,
68 see above). Do not expect the guessed values to be always correct -
69 normally, the usualy assumed version string has the form
70 generation.major.minor where versions with changes in "minor" are
71 compatible and "major" versions break with compatibility.
72
73 =item B<-X>I<item>, B<--exclude=>I<item>
74
75 Exclude files that contain "item" anywhere in their filename or directory
76 from being treated as shared libraries.
77
78 =item B<--internal-mono>
79
80 Uses the Mono runtime in . (used for bootstrapping Mono packages)
81
82 =back
83
84 =head1 EXAMPLES
85
86 dh_makeclilibs
87
88 Assuming this is a package named libfoobar0.9x-cil, generates a clilibs file that
89 looks something like:
90 libfoobar 1.0.2345.0_23a12f34 libfoobar0.9x-cil
91
92 dh_makeclilibs -V
93
94 Assuming the current version of the package is 0.93-3, generates a clilibs
95 file that looks something like:
96 libfoobar 1.0.2345.0_23a12f34 libfoobar0.9x-cil (>= 0.93-3)
97
98 dh_makeclilibs -V 'libfoobar0.9x-cil (>= 0.92)'
99
100 Generates a clilibs file that looks something like:
101 libfoobar 1.0.2345.0_23a12f34 libfoobar0.9x-cil (>= 0.92)
102
103 Assuming that your package creates libfoobar-cil and liblafasel-cil,
104 which are compatible to 0.92 versions but the upstream is going to break
105 compatibility in the next version, 0.94:
106
107 dh_makeclilibs -m 0.92 -l 0.94
108
109 Generates clilibs file that looks something like:
110
111 libfoobar 1.0.2345.0_23a12f34 libfoobar-cil (>= 0.92), libfoobar-cil (<< 0.94)
112
113 and
114
115 liblafasel 1.0.2345.0_23a12f34 liblafasel-cil (>= 0.92), liblafasel-cil (<< 0.94)
116
117 =cut
118
119 # gar, debhelper 7.1 defines -V for all scripts already :(
120 init(options => {
121 # "V", => \$dh{V_FLAG},
122 "r" => \$dh{R_FLAG},
123 "m=s" => \$dh{M_PARAMS},
124 "l=s" => \$dh{L_PARAMS},
125 "internal-mono" => \$dh{INTERNAL_MONO_FLAG},
126 });
127
128 my $clr;
129 my $cli = '/usr/bin/cli';
130 my $cli_version = `$cli --version 2>&1`;
131 my $cli_parser;
132 my $sn = 'sn';
133
134 if (defined($dh{INTERNAL_MONO_FLAG}) ||
135 (defined($ARGV[0]) && $ARGV[0] eq "internal-mono")) {
136 $clr = "mono";
137 my $mono_path = "LD_LIBRARY_PATH=debian/tmp/usr/lib MONO_PATH=debian/tmp/usr/lib/mono/4.5 MONO_CFG_DIR=debian/tmp/etc";
138 $cli_parser = "$mono_path debian/tmp/usr/bin/mono debian/tmp/usr/lib/mono/4.5/ikdasm.exe";
139 $sn = "$mono_path debian/tmp/usr/bin/mono debian/tmp/usr/lib/mono/4.5/sn.exe";
140 verbose_print("Will use build Mono (debian/tmp/usr/bin/ikdasm) for CIL parsing.");
141 } elsif (-x "/usr/bin/ikdasm") {
142 $clr = "mono";
143 $cli_parser = "/usr/bin/ikdasm";
144 verbose_print("Will use Mono (/usr/bin/ikdasm) for CIL parsing.");
145 } elsif (-x "/usr/bin/ildasm") {
146 $clr = "pnet";
147 $cli_parser = "/usr/share/cli-common/ildasm-monodis";
148 verbose_print("Will use Portable.NET (/usr/bin/ildasm) for CIL parsing.");
149 } else {
150 error("Could not find a CIL disassembler, aborting.");
151 }
152
153 {
154 local $/="";
155 open(FILE, 'debian/control');
156 my $srcblock = <FILE>;
157 close(FILE);
158 if ($srcblock =~ m/Build-Depends(?:\-Indep)?\:(?:.*\n\s+)*.*cli\-common\-dev\s*\(>=\s*([^\)]+)\)/ &&
159 system("dpkg", "--compare-versions", $1, ">=", "0.8~") != 0) {
160 warning("Warning! No Build-Depends(-Indep) on cli-common-dev (>= 0.8~)!");
161 }
162 }
163
164 my $fh;
165 my %shlibdata;
166
167 foreach my $package (@{$dh{DOPACKAGES}}) {
168 next if is_udeb($package);
169
170 my $tmp = tmpdir($package);
171
172 my %seen;
173 my $need_ldconfig = 0;
174
175 doit("rm", "-f", "$tmp/DEBIAN/clilibs");
176 if (-e "debian/$package.clilibs" ) {
177 complex_doit("cat debian/$package.clilibs > $tmp/DEBIAN/clilibs");
178 } else {
179 # So, we look for files or links to existing files with names that
180 # match "*.so*". Matching *.so.* is not good enough because of
181 # broken crap like db3. And we only look at real files not
182 # symlinks, so we don't accidentually add clilibs data to -dev
183 # packages. This may have a few false positives, which is ok,
184 # because only if we can get a library name and a major number from
185 # objdump is anything actually added.
186 my $exclude = '';
187 if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
188 $exclude = "! \\( $dh{EXCLUDE_FIND} \\) ";
189 }
190 open(FIND, "find $tmp -type f \\( -name '*.dll' \\) $exclude |");
191
192 dll:
193 while (<FIND>) {
194 chomp;
195 my ($library, $ver, $libfile);
196 $libfile = $_;
197
198 my $sig;
199 my $command = "$sn -T $libfile 2>&1";
200 verbose_print("running signature reader command: $command");
201 my $output = `$command`;
202 if ($? == 0) {
203 $sig = $output;
204 if ($sig !~ s/.*key token: (\w+).*/$1/is) {
205 warning "$libfile has no signature, ignoring";
206 next dll;
207 }
208 } else {
209 error("signature reader call failed: '$command' rc: $? output:\n$output");
210 return;
211 }
212
213 $command = "$sn -v $libfile 2>&1";
214 verbose_print("running signature verifier command: $command");
215 $output = `$command`;
216 if ($? != 0) {
217 verbose_print("signature verifier call failed: '$command' rc: $? output:\n$output");
218 warning("$libfile has no valid signature, ignoring");
219 next dll;
220 }
221
222 $command = "LANG=C MONO_GAC_PREFIX=\$MONO_GAC_PREFIX:$tmp/usr $cli_parser --assembly $libfile 2>&1";
223 verbose_print("running CLI parser command: $command");
224
225 $output = `$command`;
226 if ($? == 0) {
227 $output =~ m/Name:\s+(\S+)/;
228 $library = $1;
229 $output =~ m/Version:\s+(\S+)/;
230 $ver = $1;
231 } else {
232 error("cli_parser call failed: '$command' rc: $? output:\n$output");
233 return;
234 }
235
236 if (!-d "$tmp/DEBIAN") {
237 doit("install", "-d", "$tmp/DEBIAN");
238 }
239 my $deps = $package;
240
241 # Call isnative becuase it sets $dh{VERSION}
242 # as a side effect.
243 isnative($package);
244 my $version = $dh{VERSION};
245
246 # Old compatibility levels include the
247 # debian revision, while new do not.
248 if (!compat(3)) {
249 # Remove debian version, if any.
250 $version =~ s/-[^-]+$//;
251 }
252
253 if (defined($dh{M_PARAMS}) && $dh{M_PARAMS} ne '') {
254 $version = $dh{M_PARAMS};
255 }
256 if ($dh{V_FLAG_SET}) {
257 if ($dh{V_FLAG} ne '' ) {
258 $deps = $dh{V_FLAG};
259 } else {
260 $deps = "$package (>= $version)";
261 }
262 }
263 if (defined($dh{R_FLAG})) {
264 $version =~ s/-[^-]+$//;
265 my @uvers = split ( /\./, $version );
266 $uvers[1]++;
267 $deps = "$package (>= $version), $package (<< ".join(".", @uvers).")";
268 }
269 if (defined($dh{M_PARAMS})) {
270 $deps = "$package (>= ".$dh{M_PARAMS}.")";
271 }
272 if (defined($dh{L_PARAMS})) {
273 $deps .= ", $package (<< ".$dh{L_PARAMS}.")";
274 }
275 if (defined($library) &&
276 defined($ver) &&
277 defined($deps) &&
278 $library ne '' &&
279 $ver ne '' &&
280 $deps ne '') {
281 # Prevent duplicate lines from entering the file.
282 my $line = "$library $ver" . "__$sig $deps";
283
284 # extra dependencies are to be resolved by dh_clideps,
285 # don't forward the dependency libs to the apps where it
286 # does not belong to
287 # if ( my $extra = extraDeps ($libfile) ) { $line .= ", $extra"; }
288 if (!$seen{$line}) {
289 $seen{$line} = 1;
290 complex_doit("echo '$line' >> $tmp/DEBIAN/clilibs");
291 }
292 }
293 }
294 }
295 close FIND;
296
297 if (-e "$tmp/DEBIAN/clilibs") {
298 reset_perm_and_owner(0644, "$tmp/DEBIAN/clilibs");
299 complex_doit("LC_ALL=C sort $tmp/DEBIAN/clilibs -o $tmp/DEBIAN/clilibs");
300 }
301 }
302
303 =head1 SEE ALSO
304
305 L<debhelper(7)>
306
307 This program is a part of cli-common-dev.
308
309 =head1 KNOWN BUGS
310
311 Will possibly not work correctly with DH_COMPAT levels 1 and 2.
312
313 =head1 AUTHOR
314
315 Mirco Bauer <[email protected]>, Eduard Bloch <[email protected]>,
316 inspired by dh_makeshlibs by Joey Hess <[email protected]>
317
318 =cut