Ignore:
Timestamp:
Nov 30, 2008, 1:27:48 AM (15 years ago)
Author:
Bruno Cornec
Message:

Adds function pb_distro_installdeps to automatically istall dependencies on distro before building

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Distribution.pm

    r620 r621  
    2020 
    2121our @ISA = qw(Exporter);
    22 our @EXPORT = qw(pb_distro_init pb_get_distro);
     22our @EXPORT = qw(pb_distro_init pb_get_distro pb_distro_installdeps);
    2323
    2424=pod
     
    3939  # Return information on the running distro
    4040  #
    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";
    4343  #
    4444  # Return information on the requested distro
    4545  #
    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";
    4848  #
    4949  # Return information on the running distro
    5050  #
    5151  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";
    5454
    5555=head1 USAGE
     
    163163    $dfam="unknown";
    164164}
     165
     166# Update command needs to be run by root
     167$dupd = "sudo ".$dupd;
    165168
    166169return($ddir, $dver, $dfam, $dtype, $dsuf, $dupd);
     
    329332}
    330333
     334
     335=over 4
     336
     337=item B<pb_distro_installdeps>
     338
     339This function install the dependencies required to build the package on an RPM based distro
     340dependencies can be passed as a prameter in which case they are not computed
     341
     342=cut
     343
     344sub pb_distro_installdeps {
     345
     346# SPEC file
     347my $f = shift || undef;
     348my $dtype = shift || undef;
     349my $dupd = shift || undef;
     350my $deps = shift || undef;
     351
     352# Protection
     353return 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);
     357pb_log(2,"deps: $deps\n");
     358return if (not defined $deps);
     359if ($deps !~ /^[    ]*$/) {
     360    pb_system("$dupd $deps","Installing dependencies ($deps)");
     361    }
     362}
     363
     364=over 4
     365
     366=item B<pb_distro_getdeps>
     367
     368This function computes the dependencies indicated in the build file and return them as a string of packages to install
     369
     370=cut
     371
     372sub pb_distro_getdeps {
     373
     374my $f = shift || undef;
     375my $dtype = shift || undef;
     376
     377my $regexp = "";
     378my $deps = "";
     379my $sep = $/;
     380
     381pb_log(3,"entering pb_distro_getdeps: $dtype - $f\n");
     382# Protection
     383return if (not defined $dtype);
     384if ($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}
     396pb_log(2,"regexp: $regexp\n");
     397
     398
     399# Protection
     400return if (not defined $f);
     401
     402# Preserve separator before using the one we need
     403my $oldsep = $/;
     404$/ = $sep;
     405open(DESC,"$f") || die "Unable to open $f";
     406while (<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}
     422close(DESC);
     423$/ = $oldsep;
     424pb_log(2,"now deps: $deps\n");
     425my $deps2 = "";
     426
     427# Avoid to install what is already there
     428foreach 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*//;
     444pb_log(2,"now deps2: $deps2\n");
     445return($deps2);
     446}
     447
    331448=back
    332449
Note: See TracChangeset for help on using the changeset viewer.