]> git.pld-linux.org Git - projects/cleanbuild.git/blob - findbr
findbr match updates
[projects/cleanbuild.git] / findbr
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use IPC::Open2;
6 use Cwd;
7
8 my $pwd = getcwd();
9 # how to run poldek
10 my @ignore = qw(vserver-packages python-devel-src);
11 my @poldek = (qw(sudo poldek -n th-x86_64-ready), "--cachedir=$pwd/poldekcache",
12         "--skip-installed", "--conf=$pwd/poldekconf/poldek.conf",
13         "-O", "ignore=" . (join " ", @ignore)
14 );
15
16 # if multiple packages provide some funcionality those will be selected:
17 my %preferred = (
18         "automake" => +1,
19         "autoconf" => +1,
20         "pkgconfig" => +1,
21
22         "python" => +1,
23         "python-modules" => +1,
24         "python-setuptools" => +1,
25
26         "perl-modules" => +1,
27         "perl-Encode" => +2,
28
29         "zlib-devel" => +1,
30         "libstdc++-devel" => +1,
31         "libusb-compat-devel" => +1,
32         "libjpeg-devel" => +1,
33         "libpng-devel" => +1,
34         "libsamplerate-devel" => +1,
35         "pulseaudio-devel" => +1,
36         "xorg-lib-libXrandr-devel" => +1,
37         "sqlite-devel" => +1,
38
39         "ice-devel" => -1,
40 );
41
42 # translate package name to provides name
43 my %translate = (
44         "gcc-c++" => "libstdc++-devel",
45         "rarian-compat" => "scrollkeeper",
46         "Mesa-libGL" => "OpenGL",
47         "Mesa-libGL-devel" => "OpenGL-devel",
48         "Mesa-libGLU-devel" => "OpenGL-GLU-devel",
49 );
50
51 my @skip = qw(hostname git svn svnversion mt gawk);
52 my %skip;
53 @skip{ @skip } = (1) x scalar @skip;
54
55 # for m4 in *.m4; do R=$(rpm -qf $m4); R=${R%-*-*}; \
56 #   awk -vr=$R '/^\s*(AC_DEFUN|AU_ALIAS)/ { gsub(/\].*/,""); gsub(/.*\[/,""); print r " " $0}' $m4; \
57 # done | sort | awk '{print "\t\"" $2 "\" => \"" $1 "\","}'
58 my %ac2br = do "findbr-ac2br";
59
60 my %cmake2br = (
61         "findkde4:44" => "kde4-kdelibs",
62         "findmsgfmt" => "gettext-devel",
63         "findpythoninterp" => "python",
64 );
65
66 BEGIN {
67         $SIG{__WARN__} = sub
68         {
69                 local $_ = shift;
70                 chomp;
71                 print STDERR "\033[31;1m" . $_ . "\033[0m\n"
72         };
73 }
74
75 my $builddir = shift @ARGV;
76 my @lines = <ARGV>;
77
78 my $reason;
79
80 my %out;
81 sub add_br
82 {
83         my $pkg = shift;
84         my $msg = shift || $reason;
85         if ( ref $pkg ) {
86                 foreach my $p ( @$pkg ) {
87                         add_br( $p, $msg );
88                 }
89                 return;
90         }
91
92         $msg =~ s/\n/ # /sg;
93
94         $pkg = $translate{ $pkg } || $pkg;
95
96         return if exists $out{ $pkg };
97         $out{ $pkg } = $msg;
98         print STDERR "\033[33;1madding: $pkg => $msg\033[0m\n";
99 }
100
101 sub poldek_cmd
102 {
103         my $cmd = shift;
104         warn "Poldek: $cmd\n";
105         my $pid = open( READ, "-|", @poldek, "--shcmd=".$cmd );
106
107         my @read = <READ>;
108         close READ;
109
110         return @read if wantarray;
111         return \@read;
112 }
113
114 my $check_ac = 0;
115 my $check_config_log = undef;
116
117 my %checked_files;
118 sub poldek_file
119 {
120         my @files;
121         foreach ( @_ ) {
122                 next if $checked_files{ $_ };
123                 $checked_files{ $_ } = 1;
124                 push @files, $_;
125         }
126         return unless @files;
127
128         my $search = join "; ", map "search -f $_", @files;
129         warn "Reason: $reason\n";
130         my @read = poldek_cmd( $search );
131
132         local $_;
133         my @found;
134         while ( $_ = shift @read ) {
135                 if ( /(\d+) package\(s\) found:$/ ) {
136                         foreach my $i ( 1..$1 ) {
137                                 $_ = shift @read;
138                                 chomp;
139                                 $_ =~ /^(.*)-.*?-.*?$/;
140                                 push @found, $1;
141                         }
142                 }
143         }
144
145         return unless @found;
146
147         my $found = $found[0];
148         if ( @found > 1 ) {
149                 my $i = 0.0;
150                 my %pts = map { ( $_ => ( ($i += 0.001) + ( $preferred{ $_ } || 0 ) ) ) }
151                         reverse @found;
152                 my @pref = sort { $pts{$b} <=> $pts{$a} } @found;
153                 my $pref = join ", ", map "$_ => $pts{$_}", @pref;
154                 warn "Multiple found: $pref\n";
155                 $found = $pref[0];
156         }
157
158         $found = $translate{ $found } if $translate{ $found };
159
160         add_br( $found );
161 }
162
163 my $pkglist;
164 sub get_pkglist
165 {
166         my %pkglist;
167         my $read = poldek_cmd( "ls" );
168         foreach ( @$read ) {
169                 chomp;
170                 next unless /(\S+)-.*?-.*?\.[a-z0-9_]+$/;
171                 my $pkg = $1;
172                 $pkglist{ lc $pkg } = $pkg;
173         }
174         $pkglist = \%pkglist;
175 }
176
177 sub guess_package
178 {
179         my $origname = shift;
180         get_pkglist() unless $pkglist;
181         return unless defined $origname;
182         my $name = lc $origname;
183         my @try = (
184                 "lib$name-devel",
185                 "$name-devel",
186                 "$name",
187                 "lib$name-.*-devel",
188                 "$name-.*-devel",
189                 ".*-lib$name-devel",
190                 ".*-$name-devel",
191                 ".*-lib$name-.*-devel",
192                 ".*-$name-.*-devel",
193         );
194         my @select;
195         for my $k ( keys %$pkglist ) {
196                 if ( $k =~ /$name/ ) {
197                         push @select, $k;
198                 }
199         }
200         @select = sort @select;
201
202         foreach my $try ( @try ) {
203                 foreach my $pkg ( @select ) {
204                         if ( $pkg =~ /^$try$/ ) {
205                                 warn "guessed: $origname => $pkglist->{ $pkg }\n";
206                                 return $pkglist->{ $pkg };
207                         }
208                 }
209         }
210         warn "$origname not guessed\n";
211         return undef;
212 }
213
214 start_check:
215
216 my %checked;
217 my $cmake_get_call = 0;
218 my $cmake_pkg_list = 0;
219 while ( $_ = shift @lines ) {
220         chomp;
221         #next if $checked{ $_ };
222         #$checked{ $_ } = 1;
223
224         $reason = $_;
225         if ( /^\S+: (\S+): (?:Command )?not found$/ or /.*configure\[\d+\]: (\S+): not found$/
226                         or m{which: no (\S+) in \(.*/bin.*\)}
227                         or m{\S+: (\S+): command not found$}
228                         or m{(?:/usr/bin/)?env: (\S+): No such file or directory}
229                         or m{flock: (\S+): No such file or directory}
230                         or m{Can't exec "(\S+)": No such file or directory} ) {
231                 my $exec = $1;
232                 $exec = $1 if $exec =~ m{^"(.*)"$};
233                 next if $skip{ $exec };
234                 warn "Looking for executable $exec\n";
235                 if ( $exec =~ m#^/# ) {
236                         poldek_file( $exec );
237                 }
238                 poldek_file( "/usr/bin/$exec", "/bin/$exec" );
239         }
240
241         if ( /\S+\.[ch](?:pp|xx|c)?:\d+:\d+: error: (\S+): No such file or directory$/ or
242                 /\S+\.[ch](?:pp|xx|c)?:\d+:\d+: fatal error: (\S+): No such file or directory$/ ) {
243                 my $h = $1;
244                 warn "Looking for C(++) header $h\n";
245                 poldek_file( "/usr/include*/$h" );
246         }
247         if ( m{^ImportError: No module named (\S+)$} or
248                 m{^ERROR: Cannot find .+: No module named (\S+)$} or
249                 m{^ERROR: Failed to import the ".+" module: No module named (\S+)$}
250                 ) {
251                 my $mod = $1;
252                 $mod =~ s#\.#/#g;
253                 warn "Looking for python module $mod\n";
254                 poldek_file(
255                                 "/usr/share/python2*/$mod/__init__.py*",
256                                 "/usr/share/python2*/$mod.py*",
257                                 "/usr/lib*/python2*/$mod/__init__.py*",
258                                 "/usr/lib*/python2*/$mod.py*",
259                                 "/usr/lib*/python2*/_$mod.so",
260                                 "/usr/lib*/python2*/$mod.so" );
261         }
262
263         if (
264                 m{^cannot load such file -- (\S+)} or
265                 m{in `require': cannot load such file -- (\S+) \(LoadError\)}
266         ) {
267                 my $mod = $1;
268                 warn "Looking for ruby module $mod\n";
269                 poldek_file(
270                         "/usr/share/ruby/*/$mod.rb",
271                         "/usr/share/ruby/vendor_ruby/*/$mod.rb",
272                         "/usr/lib64/ruby/vendor_ruby/*/$mod.so",
273                 );
274         }
275
276         if ( /configure(?:\.in|\.ac)?:\d+: error: possibly undefined macro: (\S+)/
277                         or m{configure(?:\.in|\.ac)?:\d+: error: m4 macro `(\S+)' is not defined}
278                         or m{warning: macro `(\S+)' not found in library} ) {
279                 my $macro = $1;
280                 warn "Looking for autotools macro $macro\n";
281                 if ( my $br = $ac2br{ $macro } ) {
282                         add_br( $br );
283                         next;
284                 } else {
285                         $check_ac = 1;
286                 }
287         }
288         if ( /^No package '(\S+)' found$/ or
289                         /Package (\S+) was not found in the pkg-config search path/
290                                 or m{None of the required '(\S+?)(?:[<>=].*)?' found}
291                                 or m{--\s+package '(\S+?)(?:[<>=].*)?' not found}
292                                 or m{ERROR: cannot find a valid pkg-config package for \['(\S+?)(?:[<>=].*)?'\]}
293                 ) {
294                 my $pkg = $1;
295                 warn "Looking for package $pkg\n";
296                 poldek_file( "/usr/lib*/pkgconfig/$pkg.pc" );
297         }
298
299         if (/^ocamlfind: Package `(\S+)' not found - required by/
300                 or m{Camlp4: Uncaught exception: DynLoader.Error \("(\S+)", "file not found in path"\)}
301                 ) {
302                 my $pkg = $1;
303                 warn "Looking for ocaml package $pkg\n";
304                 poldek_file( "/usr/lib*/ocaml/*/$pkg.a", "/usr/lib*/ocaml/*/$pkg");
305         }
306
307         if ( m{^cp: cannot stat `(/.*)': No such file or directory$} ) {
308                 my $f = $1;
309                 warn "Looking for file $f\n";
310                 poldek_file( $f );
311         }
312
313         if ( m{^find-lang.sh: Error: international files not found for '}
314                         or m{ gettext tools not found}
315                         ) {
316                 add_br( "gettext-devel" );
317                 next;
318         }
319
320         if ( m{ pkg-config .*not .*found}
321                 or m{^checking for pkg-config\.\.\. no}
322                 or m{^pkg-config unavailable, build terminated}
323         ) {
324                 add_br( "pkgconfig" );
325                 next;
326         }
327
328         if ( m{^Can't locate (.*?\.pm) in \@INC} ) {
329                 my $mod = $1;
330                 warn "Looking for perl module $mod\n";
331                 poldek_file( "/usr/lib*/perl*/$mod", "/usr/share/perl*/$mod" );
332         }
333
334         if (
335                 m{^(?:/usr/bin/ld: )?cannot find -l(.*?)$}
336         ) {
337                 my $lib = $1;
338                 warn "Looking for library $lib\n";
339                 poldek_file( "/usr/lib64/lib$lib.so", "/usr/lib/lib$lib.so",
340                         "/usr/lib*/lib$lib.so" );
341         }
342
343         # full path to ldd files
344         if (
345                 m{^WARNING; can.*t resolve .* dependency: (.*?)$}
346         ) {
347                 my $lib = $1;
348                 warn "Looking for library '$lib'\n";
349                 poldek_file( "/usr/lib64/$lib", "/usr/lib/$lib", "/lib64/$lib", "/lib/$lib");
350         }
351
352         if ( m{^error: Couldn't exec (/\S+): No such file or directory$}
353                         or m{^Can't open perl script "(/\S+)": No such file or directory$}
354                         or m{unable to open (/\S+) \(No such file or directory\)$}
355                         or m{GConf-CRITICAL \*\*: No such file `(/.\S+?)'$}
356                         or m{make.*: \*\*\* No rule to make target `(/\S+)'}
357                         or m{g(?:cc|\+\+): (/\S+): No such file or directory$}
358                         or m{env: (/\S+): No such file or directory$}
359                         ) {
360                 my $file = $1;
361                 warn "Looking for file $file\n";
362                 poldek_file( $file );
363         }
364
365         if ( m{^ValueError: Couldn't find include '(.*\.gir)'} ) {
366                 my $file = $1;
367                 warn "Looking for gir file $file\n";
368                 poldek_file( "/usr/share/gir-1.0/" . $file );
369         }
370
371         if ( m{^error: Package `(\S+)' not found in specified Vala API directories or GObject-Introspection GIR directories}
372         ) {
373                 my $file = $1;
374                 warn "Looking for gir file $file\n";
375                 poldek_file( "/usr/share/vala/vapi/$file.vapi");
376         }
377
378         if ( m{failed.*http://www\.oasis-open\.org/docbook/xml/([\d\.]+/\S+\.dtd)} ) {
379                 my $dtd = $1;
380                 warn "Looking for docbook file $dtd\n";
381                 poldek_file( "/usr/share/sgml/docbook/xml-dtd-$dtd" );
382         }
383         if ( m{http://docbook.sourceforge.net/release/xsl/current/(\S+\.xsl)} ) {
384                 my $db = $1;
385                 next if m{^\s*(/usr/bin/)?xsltproc };
386                 warn "Looking for docbook file $db\n";
387                 poldek_file( "/usr/share/sgml/*/$db" );
388         }
389
390         if ( m{LaTeX Error: File `(\S+)' not found} ) {
391                 my $tex = $1;
392                 warn "Looking for tex file $tex\n";
393                 poldek_file( "/usr/share/tex*/$tex" );
394         }
395         if ( m{mv: cannot move `\S+' to `(/var/lib/texmf.*?)':} ) {
396                 my $tex = $1;
397                 warn "Looking for tex file $tex\n";
398                 poldek_file( $tex );
399         }
400
401         if ( m{configure: error: C\+\+ preprocessor "/lib/cpp" fails sanity check} ) {
402                 add_br( "gcc-c++", "try: %undefine\t__cxx" );
403         }
404         if ( m{configure: error: C\+\+ compiler cannot create executables} ) {
405                 add_br( "libstdc++-devel", "maybe try: %undefine\t__cxx" );
406         }
407         if ( m{configure: error: XML::Parser perl module is required for intltool} ) {
408                 add_br( "perl-XML-Parser" );
409         }
410         if ( m{iconv: conversion from `\S+' is not supported} ) {
411                 add_br( "iconv" );
412         }
413
414         if ( m{ (\S+) does not appear in AM_CONDITIONAL$} ) {
415                 my $macro = $1;
416                 warn "Looking for autotools macro $macro\n";
417                 if ( my $br = $ac2br{ $macro } ) {
418                         add_br( $br );
419                         next;
420                 } else {
421                         $check_ac = 1;
422                 }
423         }
424
425         if ( m{configure\[\d+\]: syntax error: }
426                         or m{\./configure\[\d+\]: \S+_\S+: not found}
427                         or m{./configure\[\d+\]: .*unexpected}
428                         or m{does not appear in AM_CONDITIONAL$}
429                         ) {
430                 warn "Need to check configure source: $reason\n";
431                 $check_ac = 1;
432         }
433         if ( m{^configure: error:} ) {
434                 $check_config_log = 1 unless defined $check_config_log;
435         }
436
437         if ( m{^CMake Error at (?:\S+/)?(\S+?)\.cmake:(\d+) } ) {
438                 my ( $module, $line ) = ( lc $1, $2 );
439                 my $br;
440                 if ( $module eq "findqt4" ) {
441                         my $l = $lines[0];
442                         chomp $l;
443                         if ( $l =~ /qmake/ ) {
444                                 add_br( "qt4-qmake", $l );
445                         } elsif ( $l =~ /rcc/ ) {
446                                 add_br( "qt4-build", $l );
447                         } elsif ( $l =~ /Could NOT find (Qt\S+) header/ ) {
448                                 add_br( "$1-devel", $l );
449                         } else {
450                                 warn "unrecognized Qt requirement: $l\n";
451                         }
452                 } elsif ( $module eq "cmakedeterminecxxcompiler" ) {
453                         add_br( "libstdc++-devel",
454                                 '"try: -DCMAKE_CXX_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER="%{__cc}"' );
455                 } elsif ( $br = $cmake2br{ $module . ":" . $line } ) {
456                         add_br( $br );
457                 } elsif ( $br = $cmake2br{ $module } ) {
458                         add_br( $br );
459                 } elsif ( $br = guess_package( $module =~ /find(.+)/ ) ) {
460                         add_br( $br );
461                 } else {
462                         $cmake_get_call = 1;
463                         warn "Unrecognized cmake error: $reason\n";
464                 }
465         }
466         if ( m{^\s*ERROR: (?:\S+/)?(\S+?\.cmake) not found} ) {
467                 my $cmake = $1;
468                 warn "Looking for cmake file: $cmake\n";
469                 poldek_file( "/usr/*/cmake/*/$cmake" )
470         }
471         if ( $cmake_get_call ) {
472                 if ( m{^\s*/\S+/(\S+)\.cmake:(\d+) } ) {
473                         my ( $module, $line ) = ( lc $1, $2 );
474                         my $br;
475                         if ( $br = $cmake2br{ $module . ":" . $line } ) {
476                                 add_br( $br );
477                                 $cmake_get_call = 0;
478                         } elsif ( $br = $cmake2br{ $module } ) {
479                                 add_br( $br );
480                                 $cmake_get_call = 0;
481                         } elsif ( $br = guess_package( $module =~ /find(.+)/ ) ) {
482                                 add_br( $br );
483                                 $cmake_get_call = 0;
484                         }
485                 }
486         }
487         if ( m{^-- WARNING: you are using the obsolete 'PKGCONFIG' macro} ) {
488                 add_br( "pkgconfig" );
489         }
490         if ( m{QT_(QT\S+)_LIBRARY \(ADVANCED\)} 
491                         or m{X11_(\S+)_LIB \(ADVANCED\)}
492                         or m{Qt (\S+) library not found} ) {
493                 my $find = $1;
494                 my $pkg = guess_package( $find );
495                 if ( $pkg ) {
496                         add_br( $pkg );
497                 } else {
498                         warn "Cannot quess qt package: $find\n";
499                 }
500         }
501
502         if ( m{Unable to find a javac compiler;$} ) {
503                 add_br( "jdk" );
504         }
505         if ( m{Could not find (\S+) Java extension for this JVM$} ) {
506                 my $jar = $1;
507                 warn "Looking for jar file: $jar\n";
508                 poldek_file( "/usr/share/java/$jar.jar", "*/$jar.jar" )
509         }
510
511
512         if ( m{^-- The following OPTIONAL packages could NOT be located on your system} ) {
513                 $cmake_pkg_list = 1;
514         }
515         if ( $cmake_pkg_list ) {
516                 if ( /\s+\* (\S+) / ) {
517                         my $find = $1;
518                         my $pkg = guess_package( $find );
519                         if ( $pkg ) {
520                                 add_br( $pkg );
521                         } else {
522                                 warn "Cannot quess optional package: $find\n";
523                         }
524                 } elsif ( /^\s*$/ ) {
525                         $cmake_pkg_list = 0;
526                 }
527         }
528
529         if ( m{^configure:\d+: checking for (?:"(\S+)"|(\S+))$} ) {
530                 my $exec = $1 || $2;
531                 if ( @lines and $lines[0] =~ m{^configure:\d+: result: no$} ) {
532                         next if $skip{ $exec };
533                         warn "Looking for executable $exec\n";
534                         poldek_file( $exec ) if $exec =~ m#^/#;
535                         poldek_file( "/usr/bin/$exec", "/bin/$exec" );
536                 }
537         }
538 }
539
540
541
542 sub wanted
543 {
544         return unless /^configure(\.(?:ac|in|in\.in))?$/;
545         return unless -r;
546
547         warn "$File::Find::name\n";
548         open F_IN, "<", $_;
549         my $file = $_;
550         while ( <F_IN> ) {
551                 chomp;
552                 if ( m{^\s*([A-Za-z0-9_]+)\s*(\(.*)?$} ) {
553                         my $def = $1;
554                         if ( my $br = $ac2br{ $def } ) {
555                                 add_br( $br, "$file: $_" );
556                         } elsif ( $def !~ /^A[CM]_/ and $def =~ /^_?[A-Z]+_[A-Z_0-9a-z]+$/ ) {
557                                 #warn "Possible macro unrecognized: $def [[[$_]]]\n";
558                         }
559                 }
560         }
561         close F_IN;
562 }
563
564 use File::Find;
565 if ( $check_ac ) {
566         find( \&wanted, $builddir );
567 }
568
569 sub wanted2
570 {
571         return unless /^config\.log$/;
572         return unless -r;
573
574         warn "$File::Find::name\n";
575         open F_IN, "<", $_;
576         push @lines, <F_IN>;
577         close F_IN;
578 }
579
580 if ( $check_config_log ) {
581         $check_config_log = 0;
582         find( \&wanted2, $builddir );
583         goto start_check if @lines;
584 }
585
586 foreach my $pkg ( sort keys %out ) {
587         print "$pkg -- $out{$pkg}\n";
588 }
589 # vim: ts=4 sw=4
This page took 0.138605 seconds and 3 git commands to generate.