]> git.pld-linux.org Git - projects/cleanbuild.git/blame - findbr
- a simple input/output wrapper to be used instead of tee with lots of magic
[projects/cleanbuild.git] / findbr
CommitLineData
c494424e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use IPC::Open2;
c728428f 6use Cwd;
c494424e 7
c728428f 8my $pwd = getcwd();
c494424e 9# how to run poldek
10my @ignore = qw(vserver-packages python-devel-src);
c728428f 11my @poldek = (qw(sudo poldek -n th-x86_64-ready), "--cachedir=$pwd/poldekcache",
12 "--skip-installed", "--conf=$pwd/poldekconf/poldek.conf",
c494424e 13 "-O", "ignore=" . (join " ", @ignore)
14);
15
16# if multiple packages provide some funcionality those will be selected:
17my %preferred = (
18 "automake" => +1,
19 "autoconf" => +1,
20 "pkgconfig" => +1,
21
22 "python" => +1,
23 "python-modules" => +1,
9ac658a4 24 "python-setuptools" => +1,
c494424e 25
26 "perl-modules" => +1,
27 "perl-Encode" => +2,
28
29 "zlib-devel" => +1,
30 "libstdc++-devel" => +1,
a75e2ecf 31 "libusb-compat-devel" => +1,
022b6e5b 32 "libjpeg-devel" => +1,
c728428f 33 "libpng-devel" => +1,
022b6e5b 34 "libsamplerate-devel" => +1,
35 "pulseaudio-devel" => +1,
36 "xorg-lib-libXrandr-devel" => +1,
c728428f 37 "sqlite-devel" => +1,
a896e84e 38
39 "ice-devel" => -1,
c494424e 40);
41
44dfaf2a 42# translate package name to provides name
c494424e 43my %translate = (
a896e84e 44 "gcc-c++" => "libstdc++-devel",
c494424e 45 "rarian-compat" => "scrollkeeper",
022b6e5b 46 "Mesa-libGL" => "OpenGL",
47 "Mesa-libGL-devel" => "OpenGL-devel",
c494424e 48 "Mesa-libGLU-devel" => "OpenGL-GLU-devel",
49);
50
a896e84e 51my @skip = qw(hostname git svn svnversion mt gawk);
a6c4aafb 52my %skip;
53@skip{ @skip } = (1) x scalar @skip;
54
c494424e 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 "\","}'
58my %ac2br = do "findbr-ac2br";
59
60my %cmake2br = (
61 "findkde4:44" => "kde4-kdelibs",
62 "findmsgfmt" => "gettext-devel",
63 "findpythoninterp" => "python",
64);
65
66BEGIN {
67 $SIG{__WARN__} = sub
68 {
69 local $_ = shift;
70 chomp;
71 print STDERR "\033[31;1m" . $_ . "\033[0m\n"
72 };
73}
74
75my $builddir = shift @ARGV;
76my @lines = <ARGV>;
77
78my $reason;
79
80my %out;
81sub 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
101sub 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
114my $check_ac = 0;
c728428f 115my $check_config_log = undef;
c494424e 116
117my %checked_files;
118sub 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
163my $pkglist;
164sub 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
177sub 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
022b6e5b 214start_check:
215
c494424e 216my %checked;
217my $cmake_get_call = 0;
218my $cmake_pkg_list = 0;
219while ( $_ = 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$}
024ede0e 228 or m{(?:/usr/bin/)?env: (\S+): No such file or directory}
c494424e 229 or m{Can't exec "(\S+)": No such file or directory} ) {
230 my $exec = $1;
c728428f 231 $exec = $1 if $exec =~ m{^"(.*)"$};
a6c4aafb 232 next if $skip{ $exec };
c494424e 233 warn "Looking for executable $exec\n";
234 if ( $exec =~ m#^/# ) {
235 poldek_file( $exec );
236 }
237 poldek_file( "/usr/bin/$exec", "/bin/$exec" );
238 }
239
240
bfe0e7d5 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$/ ) {
c494424e 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+)$} ) {
248 my $mod = $1;
249 $mod =~ s#\.#/#g;
250 warn "Looking for python module $mod\n";
251 poldek_file( "/usr/share/python2*/$mod/__init__.py*",
252 "/usr/share/python2*/$mod.py*",
253 "/usr/lib*/python2*/$mod.py*",
9ac658a4 254 "/usr/lib*/python2*/_$mod.so",
255 "/usr/lib*/python2*/$mod.so" );
c494424e 256 }
257 if ( /configure(?:\.in|\.ac)?:\d+: error: possibly undefined macro: (\S+)/
e6da4d63 258 or m{configure(?:\.in|\.ac)?:\d+: error: m4 macro `(\S+)' is not defined}
259 or m{warning: macro `(\S+)' not found in library} ) {
c494424e 260 my $macro = $1;
261 warn "Looking for autotools macro $macro\n";
262 if ( my $br = $ac2br{ $macro } ) {
263 add_br( $br );
264 next;
c728428f 265 } else {
266 $check_ac = 1;
c494424e 267 }
268 }
269 if ( /^No package '(\S+)' found$/ or
270 /Package (\S+) was not found in the pkg-config search path/
271 or m{None of the required '(\S+?)(?:[<>=].*)?' found}
272 or m{--\s+package '(\S+?)(?:[<>=].*)?' not found}
273 ) {
274 my $pkg = $1;
275 warn "Looking for package $pkg\n";
276 poldek_file( "/usr/lib*/pkgconfig/$pkg.pc" );
277 }
278 if ( m{^cp: cannot stat `(/.*)': No such file or directory$} ) {
279 my $f = $1;
280 warn "Looking for file $f\n";
281 poldek_file( $f );
282 }
283 if ( m{^find-lang.sh: Error: international files not found for '}
284 or m{ gettext tools not found}
285 ) {
286 add_br( "gettext-devel" );
287 #exit;
288 next;
289 }
290 if ( m{ pkg-config .*not .*found}
291 or m{^checking for pkg-config\.\.\. no} ) {
292 add_br( "pkgconfig" );
293 #exit;
294 next;
295 }
296 if ( m{^Can't locate (.*?\.pm) in \@INC} ) {
297 my $mod = $1;
298 warn "Looking for perl module $mod\n";
299 poldek_file( "/usr/lib*/perl*/$mod", "/usr/share/perl*/$mod" );
300 }
c728428f 301 if ( m{^(?:/usr/bin/ld: )?cannot find -l(.*?)$} ) {
c494424e 302 my $lib = $1;
303 warn "Looking for library $lib\n";
c728428f 304 poldek_file( "/usr/lib64/lib$lib.so", "/usr/lib/lib$lib.so",
305 "/usr/lib*/lib$lib.so" );
c494424e 306 }
307 if ( m{^error: Couldn't exec (/\S+): No such file or directory$}
308 or m{^Can't open perl script "(/\S+)": No such file or directory$}
309 or m{unable to open (/\S+) \(No such file or directory\)$}
310 or m{GConf-CRITICAL \*\*: No such file `(/.\S+?)'$}
311 or m{make.*: \*\*\* No rule to make target `(/\S+)'}
312 or m{g(?:cc|\+\+): (/\S+): No such file or directory$}
c728428f 313 or m{env: (/\S+): No such file or directory$}
c494424e 314 ) {
315 my $file = $1;
316 warn "Looking for file $file\n";
317 poldek_file( $file );
318 }
c728428f 319 if ( m{^ValueError: Couldn't find include '(.*\.gir)'} ) {
320 my $file = $1;
321 warn "Looking for gir file $file\n";
322 poldek_file( "/usr/share/gir-1.0/" . $file );
323 }
c494424e 324 if ( m{failed.*http://www\.oasis-open\.org/docbook/xml/([\d\.]+/\S+\.dtd)} ) {
325 my $dtd = $1;
326 warn "Looking for docbook file $dtd\n";
327 poldek_file( "/usr/share/sgml/docbook/xml-dtd-$dtd" );
328 }
329 if ( m{http://docbook.sourceforge.net/release/xsl/current/(\S+\.xsl)} ) {
330 my $db = $1;
331 next if m{^\s*(/usr/bin/)?xsltproc };
332 warn "Looking for docbook file $db\n";
333 poldek_file( "/usr/share/sgml/*/$db" );
334 }
a755261c 335
336 if ( m{LaTeX Error: File `(\S+)' not found} ) {
337 my $tex = $1;
338 warn "Looking for tex file $tex\n";
339 poldek_file( "/usr/share/tex*/$tex" );
340 }
341 if ( m{mv: cannot move `\S+' to `(/var/lib/texmf.*?)':} ) {
342 my $tex = $1;
343 warn "Looking for tex file $tex\n";
344 poldek_file( $tex );
345 }
346
c494424e 347 if ( m{configure: error: C\+\+ preprocessor "/lib/cpp" fails sanity check} ) {
348 add_br( "gcc-c++", "try: %undefine\t__cxx" );
349 }
350 if ( m{configure: error: C\+\+ compiler cannot create executables} ) {
351 add_br( "libstdc++-devel", "maybe try: %undefine\t__cxx" );
352 }
353 if ( m{configure: error: XML::Parser perl module is required for intltool} ) {
354 add_br( "perl-XML-Parser" );
355 }
9ffdd22c 356 if ( m{iconv: conversion from `\S+' is not supported} ) {
357 add_br( "iconv" );
358 }
c494424e 359
bfe0e7d5 360 if ( m{ (\S+) does not appear in AM_CONDITIONAL$} ) {
361 my $macro = $1;
362 warn "Looking for autotools macro $macro\n";
363 if ( my $br = $ac2br{ $macro } ) {
364 add_br( $br );
365 next;
366 } else {
367 $check_ac = 1;
368 }
369 }
370
c494424e 371 if ( m{configure\[\d+\]: syntax error: }
a75e2ecf 372 or m{\./configure\[\d+\]: \S+_\S+: not found}
373 or m{./configure\[\d+\]: .*unexpected}
374 or m{does not appear in AM_CONDITIONAL$}
375 ) {
c494424e 376 warn "Need to check configure source: $reason\n";
377 $check_ac = 1;
378 }
022b6e5b 379 if ( m{^configure: error:} ) {
380 $check_config_log = 1 unless defined $check_config_log;
381 }
c494424e 382
383 if ( m{^CMake Error at (?:\S+/)?(\S+?)\.cmake:(\d+) } ) {
384 my ( $module, $line ) = ( lc $1, $2 );
385 my $br;
386 if ( $module eq "findqt4" ) {
387 my $l = $lines[0];
388 chomp $l;
389 if ( $l =~ /qmake/ ) {
390 add_br( "qt4-qmake", $l );
391 } elsif ( $l =~ /rcc/ ) {
392 add_br( "qt4-build", $l );
393 } elsif ( $l =~ /Could NOT find (Qt\S+) header/ ) {
394 add_br( "$1-devel", $l );
395 } else {
396 warn "unrecognized Qt requirement: $l\n";
397 }
398 } elsif ( $module eq "cmakedeterminecxxcompiler" ) {
399 add_br( "libstdc++-devel",
400 '"try: -DCMAKE_CXX_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER="%{__cc}"' );
401 } elsif ( $br = $cmake2br{ $module . ":" . $line } ) {
402 add_br( $br );
403 } elsif ( $br = $cmake2br{ $module } ) {
404 add_br( $br );
405 } elsif ( $br = guess_package( $module =~ /find(.+)/ ) ) {
406 add_br( $br );
407 } else {
408 $cmake_get_call = 1;
409 warn "Unrecognized cmake error: $reason\n";
410 }
411 }
412 if ( m{^\s*ERROR: (?:\S+/)?(\S+?\.cmake) not found} ) {
413 my $cmake = $1;
414 warn "Looking for cmake file: $cmake\n";
415 poldek_file( "/usr/*/cmake/*/$cmake" )
416 }
417 if ( $cmake_get_call ) {
418 if ( m{^\s*/\S+/(\S+)\.cmake:(\d+) } ) {
419 my ( $module, $line ) = ( lc $1, $2 );
420 my $br;
421 if ( $br = $cmake2br{ $module . ":" . $line } ) {
422 add_br( $br );
423 $cmake_get_call = 0;
424 } elsif ( $br = $cmake2br{ $module } ) {
425 add_br( $br );
426 $cmake_get_call = 0;
427 } elsif ( $br = guess_package( $module =~ /find(.+)/ ) ) {
428 add_br( $br );
429 $cmake_get_call = 0;
430 }
431 }
432 }
433 if ( m{^-- WARNING: you are using the obsolete 'PKGCONFIG' macro} ) {
434 add_br( "pkgconfig" );
435 }
436 if ( m{QT_(QT\S+)_LIBRARY \(ADVANCED\)}
437 or m{X11_(\S+)_LIB \(ADVANCED\)}
438 or m{Qt (\S+) library not found} ) {
439 my $find = $1;
440 my $pkg = guess_package( $find );
441 if ( $pkg ) {
442 add_br( $pkg );
443 } else {
444 warn "Cannot quess qt package: $find\n";
445 }
446 }
447
e6da4d63 448 if ( m{Unable to find a javac compiler;$} ) {
449 add_br( "jdk" );
450 }
9ffdd22c 451 if ( m{Could not find (\S+) Java extension for this JVM$} ) {
452 my $jar = $1;
453 warn "Looking for jar file: $jar\n";
454 poldek_file( "/usr/share/java/$jar.jar", "*/$jar.jar" )
455 }
e6da4d63 456
457
c494424e 458 if ( m{^-- The following OPTIONAL packages could NOT be located on your system} ) {
459 $cmake_pkg_list = 1;
460 }
461 if ( $cmake_pkg_list ) {
462 if ( /\s+\* (\S+) / ) {
463 my $find = $1;
464 my $pkg = guess_package( $find );
465 if ( $pkg ) {
466 add_br( $pkg );
467 } else {
468 warn "Cannot quess optional package: $find\n";
469 }
470 } elsif ( /^\s*$/ ) {
471 $cmake_pkg_list = 0;
472 }
473 }
c728428f 474
475 if ( m{^configure:\d+: checking for (?:"(\S+)"|(\S+))$} ) {
476 my $exec = $1 || $2;
477 if ( @lines and $lines[0] =~ m{^configure:\d+: result: no$} ) {
a6c4aafb 478 next if $skip{ $exec };
c728428f 479 warn "Looking for executable $exec\n";
480 poldek_file( $exec ) if $exec =~ m#^/#;
481 poldek_file( "/usr/bin/$exec", "/bin/$exec" );
482 }
483 }
c494424e 484}
485
486
487
488sub wanted
489{
490 return unless /^configure(\.(?:ac|in|in\.in))?$/;
491 return unless -r;
492
493 warn "$File::Find::name\n";
494 open F_IN, "<", $_;
495 my $file = $_;
496 while ( <F_IN> ) {
497 chomp;
498 if ( m{^\s*([A-Za-z0-9_]+)\s*(\(.*)?$} ) {
499 my $def = $1;
500 if ( my $br = $ac2br{ $def } ) {
501 add_br( $br, "$file: $_" );
502 } elsif ( $def !~ /^A[CM]_/ and $def =~ /^_?[A-Z]+_[A-Z_0-9a-z]+$/ ) {
503 #warn "Possible macro unrecognized: $def [[[$_]]]\n";
504 }
505 }
506 }
507 close F_IN;
508}
509
510use File::Find;
511if ( $check_ac ) {
512 find( \&wanted, $builddir );
513}
514
022b6e5b 515sub wanted2
516{
517 return unless /^config\.log$/;
518 return unless -r;
519
520 warn "$File::Find::name\n";
521 open F_IN, "<", $_;
522 push @lines, <F_IN>;
523 close F_IN;
524}
525
526if ( $check_config_log ) {
527 $check_config_log = 0;
528 find( \&wanted2, $builddir );
529 goto start_check if @lines;
530}
531
c494424e 532foreach my $pkg ( sort keys %out ) {
533 print "$pkg -- $out{$pkg}\n";
534}
535# vim: ts=4 sw=4
This page took 0.208535 seconds and 4 git commands to generate.