]> git.pld-linux.org Git - projects/cleanbuild.git/blame - findbr
more finding pkgconfig errors (from xpra build)
[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 }
c494424e 239
bfe0e7d5 240 if ( /\S+\.[ch](?:pp|xx|c)?:\d+:\d+: error: (\S+): No such file or directory$/ or
241 /\S+\.[ch](?:pp|xx|c)?:\d+:\d+: fatal error: (\S+): No such file or directory$/ ) {
c494424e 242 my $h = $1;
243 warn "Looking for C(++) header $h\n";
244 poldek_file( "/usr/include*/$h" );
245 }
a7c421e2
ER
246 if ( m{^ImportError: No module named (\S+)$} or
247 m{^ERROR: Cannot find .+: No module named (\S+)$}
248 ) {
c494424e 249 my $mod = $1;
250 $mod =~ s#\.#/#g;
251 warn "Looking for python module $mod\n";
252 poldek_file( "/usr/share/python2*/$mod/__init__.py*",
253 "/usr/share/python2*/$mod.py*",
254 "/usr/lib*/python2*/$mod.py*",
9ac658a4 255 "/usr/lib*/python2*/_$mod.so",
256 "/usr/lib*/python2*/$mod.so" );
c494424e 257 }
a7c421e2 258 if ( /configure(?:\.in|\.ac)?:\d+: error: possibly undefined macro: (\S+)/
e6da4d63 259 or m{configure(?:\.in|\.ac)?:\d+: error: m4 macro `(\S+)' is not defined}
260 or m{warning: macro `(\S+)' not found in library} ) {
c494424e 261 my $macro = $1;
262 warn "Looking for autotools macro $macro\n";
263 if ( my $br = $ac2br{ $macro } ) {
264 add_br( $br );
265 next;
c728428f 266 } else {
267 $check_ac = 1;
c494424e 268 }
269 }
270 if ( /^No package '(\S+)' found$/ or
271 /Package (\S+) was not found in the pkg-config search path/
272 or m{None of the required '(\S+?)(?:[<>=].*)?' found}
273 or m{--\s+package '(\S+?)(?:[<>=].*)?' not found}
a7c421e2 274 or m{ERROR: cannot find a valid pkg-config package for \['(\S+?)(?:[<>=].*)?'\]}
c494424e 275 ) {
276 my $pkg = $1;
277 warn "Looking for package $pkg\n";
278 poldek_file( "/usr/lib*/pkgconfig/$pkg.pc" );
279 }
280 if ( m{^cp: cannot stat `(/.*)': No such file or directory$} ) {
281 my $f = $1;
282 warn "Looking for file $f\n";
283 poldek_file( $f );
284 }
285 if ( m{^find-lang.sh: Error: international files not found for '}
286 or m{ gettext tools not found}
287 ) {
288 add_br( "gettext-devel" );
289 #exit;
290 next;
291 }
292 if ( m{ pkg-config .*not .*found}
293 or m{^checking for pkg-config\.\.\. no} ) {
294 add_br( "pkgconfig" );
295 #exit;
296 next;
297 }
298 if ( m{^Can't locate (.*?\.pm) in \@INC} ) {
299 my $mod = $1;
300 warn "Looking for perl module $mod\n";
301 poldek_file( "/usr/lib*/perl*/$mod", "/usr/share/perl*/$mod" );
302 }
c728428f 303 if ( m{^(?:/usr/bin/ld: )?cannot find -l(.*?)$} ) {
c494424e 304 my $lib = $1;
305 warn "Looking for library $lib\n";
c728428f 306 poldek_file( "/usr/lib64/lib$lib.so", "/usr/lib/lib$lib.so",
307 "/usr/lib*/lib$lib.so" );
c494424e 308 }
309 if ( m{^error: Couldn't exec (/\S+): No such file or directory$}
310 or m{^Can't open perl script "(/\S+)": No such file or directory$}
311 or m{unable to open (/\S+) \(No such file or directory\)$}
312 or m{GConf-CRITICAL \*\*: No such file `(/.\S+?)'$}
313 or m{make.*: \*\*\* No rule to make target `(/\S+)'}
314 or m{g(?:cc|\+\+): (/\S+): No such file or directory$}
c728428f 315 or m{env: (/\S+): No such file or directory$}
c494424e 316 ) {
317 my $file = $1;
318 warn "Looking for file $file\n";
319 poldek_file( $file );
320 }
c728428f 321 if ( m{^ValueError: Couldn't find include '(.*\.gir)'} ) {
322 my $file = $1;
323 warn "Looking for gir file $file\n";
324 poldek_file( "/usr/share/gir-1.0/" . $file );
325 }
c494424e 326 if ( m{failed.*http://www\.oasis-open\.org/docbook/xml/([\d\.]+/\S+\.dtd)} ) {
327 my $dtd = $1;
328 warn "Looking for docbook file $dtd\n";
329 poldek_file( "/usr/share/sgml/docbook/xml-dtd-$dtd" );
330 }
331 if ( m{http://docbook.sourceforge.net/release/xsl/current/(\S+\.xsl)} ) {
332 my $db = $1;
333 next if m{^\s*(/usr/bin/)?xsltproc };
334 warn "Looking for docbook file $db\n";
335 poldek_file( "/usr/share/sgml/*/$db" );
336 }
a755261c 337
338 if ( m{LaTeX Error: File `(\S+)' not found} ) {
339 my $tex = $1;
340 warn "Looking for tex file $tex\n";
341 poldek_file( "/usr/share/tex*/$tex" );
342 }
343 if ( m{mv: cannot move `\S+' to `(/var/lib/texmf.*?)':} ) {
344 my $tex = $1;
345 warn "Looking for tex file $tex\n";
346 poldek_file( $tex );
347 }
348
c494424e 349 if ( m{configure: error: C\+\+ preprocessor "/lib/cpp" fails sanity check} ) {
350 add_br( "gcc-c++", "try: %undefine\t__cxx" );
351 }
352 if ( m{configure: error: C\+\+ compiler cannot create executables} ) {
353 add_br( "libstdc++-devel", "maybe try: %undefine\t__cxx" );
354 }
355 if ( m{configure: error: XML::Parser perl module is required for intltool} ) {
356 add_br( "perl-XML-Parser" );
357 }
9ffdd22c 358 if ( m{iconv: conversion from `\S+' is not supported} ) {
359 add_br( "iconv" );
360 }
c494424e 361
bfe0e7d5 362 if ( m{ (\S+) does not appear in AM_CONDITIONAL$} ) {
363 my $macro = $1;
364 warn "Looking for autotools macro $macro\n";
365 if ( my $br = $ac2br{ $macro } ) {
366 add_br( $br );
367 next;
368 } else {
369 $check_ac = 1;
370 }
371 }
372
c494424e 373 if ( m{configure\[\d+\]: syntax error: }
a75e2ecf 374 or m{\./configure\[\d+\]: \S+_\S+: not found}
375 or m{./configure\[\d+\]: .*unexpected}
376 or m{does not appear in AM_CONDITIONAL$}
377 ) {
c494424e 378 warn "Need to check configure source: $reason\n";
379 $check_ac = 1;
380 }
022b6e5b 381 if ( m{^configure: error:} ) {
382 $check_config_log = 1 unless defined $check_config_log;
383 }
c494424e 384
385 if ( m{^CMake Error at (?:\S+/)?(\S+?)\.cmake:(\d+) } ) {
386 my ( $module, $line ) = ( lc $1, $2 );
387 my $br;
388 if ( $module eq "findqt4" ) {
389 my $l = $lines[0];
390 chomp $l;
391 if ( $l =~ /qmake/ ) {
392 add_br( "qt4-qmake", $l );
393 } elsif ( $l =~ /rcc/ ) {
394 add_br( "qt4-build", $l );
395 } elsif ( $l =~ /Could NOT find (Qt\S+) header/ ) {
396 add_br( "$1-devel", $l );
397 } else {
398 warn "unrecognized Qt requirement: $l\n";
399 }
400 } elsif ( $module eq "cmakedeterminecxxcompiler" ) {
401 add_br( "libstdc++-devel",
402 '"try: -DCMAKE_CXX_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER="%{__cc}"' );
403 } elsif ( $br = $cmake2br{ $module . ":" . $line } ) {
404 add_br( $br );
405 } elsif ( $br = $cmake2br{ $module } ) {
406 add_br( $br );
407 } elsif ( $br = guess_package( $module =~ /find(.+)/ ) ) {
408 add_br( $br );
409 } else {
410 $cmake_get_call = 1;
411 warn "Unrecognized cmake error: $reason\n";
412 }
413 }
414 if ( m{^\s*ERROR: (?:\S+/)?(\S+?\.cmake) not found} ) {
415 my $cmake = $1;
416 warn "Looking for cmake file: $cmake\n";
417 poldek_file( "/usr/*/cmake/*/$cmake" )
418 }
419 if ( $cmake_get_call ) {
420 if ( m{^\s*/\S+/(\S+)\.cmake:(\d+) } ) {
421 my ( $module, $line ) = ( lc $1, $2 );
422 my $br;
423 if ( $br = $cmake2br{ $module . ":" . $line } ) {
424 add_br( $br );
425 $cmake_get_call = 0;
426 } elsif ( $br = $cmake2br{ $module } ) {
427 add_br( $br );
428 $cmake_get_call = 0;
429 } elsif ( $br = guess_package( $module =~ /find(.+)/ ) ) {
430 add_br( $br );
431 $cmake_get_call = 0;
432 }
433 }
434 }
435 if ( m{^-- WARNING: you are using the obsolete 'PKGCONFIG' macro} ) {
436 add_br( "pkgconfig" );
437 }
438 if ( m{QT_(QT\S+)_LIBRARY \(ADVANCED\)}
439 or m{X11_(\S+)_LIB \(ADVANCED\)}
440 or m{Qt (\S+) library not found} ) {
441 my $find = $1;
442 my $pkg = guess_package( $find );
443 if ( $pkg ) {
444 add_br( $pkg );
445 } else {
446 warn "Cannot quess qt package: $find\n";
447 }
448 }
449
e6da4d63 450 if ( m{Unable to find a javac compiler;$} ) {
451 add_br( "jdk" );
452 }
9ffdd22c 453 if ( m{Could not find (\S+) Java extension for this JVM$} ) {
454 my $jar = $1;
455 warn "Looking for jar file: $jar\n";
456 poldek_file( "/usr/share/java/$jar.jar", "*/$jar.jar" )
457 }
e6da4d63 458
459
c494424e 460 if ( m{^-- The following OPTIONAL packages could NOT be located on your system} ) {
461 $cmake_pkg_list = 1;
462 }
463 if ( $cmake_pkg_list ) {
464 if ( /\s+\* (\S+) / ) {
465 my $find = $1;
466 my $pkg = guess_package( $find );
467 if ( $pkg ) {
468 add_br( $pkg );
469 } else {
470 warn "Cannot quess optional package: $find\n";
471 }
472 } elsif ( /^\s*$/ ) {
473 $cmake_pkg_list = 0;
474 }
475 }
c728428f 476
477 if ( m{^configure:\d+: checking for (?:"(\S+)"|(\S+))$} ) {
478 my $exec = $1 || $2;
479 if ( @lines and $lines[0] =~ m{^configure:\d+: result: no$} ) {
a6c4aafb 480 next if $skip{ $exec };
c728428f 481 warn "Looking for executable $exec\n";
482 poldek_file( $exec ) if $exec =~ m#^/#;
483 poldek_file( "/usr/bin/$exec", "/bin/$exec" );
484 }
485 }
c494424e 486}
487
488
489
490sub wanted
491{
492 return unless /^configure(\.(?:ac|in|in\.in))?$/;
493 return unless -r;
494
495 warn "$File::Find::name\n";
496 open F_IN, "<", $_;
497 my $file = $_;
498 while ( <F_IN> ) {
499 chomp;
500 if ( m{^\s*([A-Za-z0-9_]+)\s*(\(.*)?$} ) {
501 my $def = $1;
502 if ( my $br = $ac2br{ $def } ) {
503 add_br( $br, "$file: $_" );
504 } elsif ( $def !~ /^A[CM]_/ and $def =~ /^_?[A-Z]+_[A-Z_0-9a-z]+$/ ) {
505 #warn "Possible macro unrecognized: $def [[[$_]]]\n";
506 }
507 }
508 }
509 close F_IN;
510}
511
512use File::Find;
513if ( $check_ac ) {
514 find( \&wanted, $builddir );
515}
516
022b6e5b 517sub wanted2
518{
519 return unless /^config\.log$/;
520 return unless -r;
521
522 warn "$File::Find::name\n";
523 open F_IN, "<", $_;
524 push @lines, <F_IN>;
525 close F_IN;
526}
527
528if ( $check_config_log ) {
529 $check_config_log = 0;
530 find( \&wanted2, $builddir );
531 goto start_check if @lines;
532}
533
c494424e 534foreach my $pkg ( sort keys %out ) {
535 print "$pkg -- $out{$pkg}\n";
536}
537# vim: ts=4 sw=4
This page took 0.08337 seconds and 4 git commands to generate.