Changeset 621 in ProjectBuilder for devel/pb-modules
- Timestamp:
- Nov 30, 2008, 1:27:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/Distribution.pm
r620 r621 20 20 21 21 our @ISA = qw(Exporter); 22 our @EXPORT = qw(pb_distro_init pb_get_distro );22 our @EXPORT = qw(pb_distro_init pb_get_distro pb_distro_installdeps); 23 23 24 24 =pod … … 39 39 # Return information on the running distro 40 40 # 41 my ($ddir, $dver, $dfam, $dtype, $pbsuf ) = pb_distro_init();42 print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf )."\n";41 my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd) = pb_distro_init(); 42 print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd)."\n"; 43 43 # 44 44 # Return information on the requested distro 45 45 # 46 my ($ddir, $dver, $dfam, $dtype, $pbsuf ) = pb_distro_init("ubuntu","7.10");47 print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf )."\n";46 my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd) = pb_distro_init("ubuntu","7.10"); 47 print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd)."\n"; 48 48 # 49 49 # Return information on the running distro 50 50 # 51 51 my ($ddir,$dver) = pb_get_distro(); 52 my ($ddir, $dver, $dfam, $dtype, $pbsuf ) = pb_distro_init($ddir,$dver);53 print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf )."\n";52 my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd) = pb_distro_init($ddir,$dver); 53 print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd)."\n"; 54 54 55 55 =head1 USAGE … … 163 163 $dfam="unknown"; 164 164 } 165 166 # Update command needs to be run by root 167 $dupd = "sudo ".$dupd; 165 168 166 169 return($ddir, $dver, $dfam, $dtype, $dsuf, $dupd); … … 329 332 } 330 333 334 335 =over 4 336 337 =item B<pb_distro_installdeps> 338 339 This function install the dependencies required to build the package on an RPM based distro 340 dependencies can be passed as a prameter in which case they are not computed 341 342 =cut 343 344 sub pb_distro_installdeps { 345 346 # SPEC file 347 my $f = shift || undef; 348 my $dtype = shift || undef; 349 my $dupd = shift || undef; 350 my $deps = shift || undef; 351 352 # Protection 353 return if (not defined $dupd); 354 355 # Get dependecies in the build file if not forced 356 $deps = pb_distro_getdeps("$f", $dtype) if (not defined $deps); 357 pb_log(2,"deps: $deps\n"); 358 return if (not defined $deps); 359 if ($deps !~ /^[ ]*$/) { 360 pb_system("$dupd $deps","Installing dependencies ($deps)"); 361 } 362 } 363 364 =over 4 365 366 =item B<pb_distro_getdeps> 367 368 This function computes the dependencies indicated in the build file and return them as a string of packages to install 369 370 =cut 371 372 sub pb_distro_getdeps { 373 374 my $f = shift || undef; 375 my $dtype = shift || undef; 376 377 my $regexp = ""; 378 my $deps = ""; 379 my $sep = $/; 380 381 pb_log(3,"entering pb_distro_getdeps: $dtype - $f\n"); 382 # Protection 383 return if (not defined $dtype); 384 if ($dtype eq "rpm") { 385 # In RPM this could include files, but we do not handle them atm. 386 $regexp = '^BuildRequires:(.*)$'; 387 } elsif ($dtype eq "du") { 388 $regexp = '^Build-Depends:(.*)$'; 389 } elsif ($dtype eq "ebuild") { 390 $sep = '"'.$/; 391 $regexp = '^DEPEND="(.*)"\n' 392 } else { 393 # No idea 394 return; 395 } 396 pb_log(2,"regexp: $regexp\n"); 397 398 399 # Protection 400 return if (not defined $f); 401 402 # Preserve separator before using the one we need 403 my $oldsep = $/; 404 $/ = $sep; 405 open(DESC,"$f") || die "Unable to open $f"; 406 while (<DESC>) { 407 pb_log(4,"read: $_\n"); 408 next if (! /$regexp/); 409 chomp(); 410 # What we found with the regexp is the list of deps. 411 pb_log(2,"found deps: $_\n"); 412 s/$regexp/$1/; 413 # Remove conditions 414 s/>[=]*.*,//g; 415 # Improve string format (remove , and spaces at start, end and in double 416 s/,//g; 417 s/^\s*//; 418 s/\s*$//; 419 s/\s+/ /g; 420 $deps .= " ".$_; 421 } 422 close(DESC); 423 $/ = $oldsep; 424 pb_log(2,"now deps: $deps\n"); 425 my $deps2 = ""; 426 427 # Avoid to install what is already there 428 foreach my $p (split(/ /,$deps)) { 429 if ($dtype eq "rpm") { 430 my $res = pb_system("rpm -q --whatprovides --quiet $p","","quiet"); 431 next if ($res eq 0); 432 } elsif ($dtype eq "du") { 433 my $res = pb_system("dpkg -L $p","","quiet"); 434 next if ($res eq 0); 435 } elsif ($dtype eq "ebuild") { 436 } else { 437 # Not reached 438 } 439 pb_log(2,"found deps2: $p\n"); 440 $deps2 .= " $p"; 441 } 442 443 $deps2 =~ s/^\s*//; 444 pb_log(2,"now deps2: $deps2\n"); 445 return($deps2); 446 } 447 331 448 =back 332 449
Note:
See TracChangeset
for help on using the changeset viewer.