Update of /cvsroot/leaf/src/The_UnNamed_One/buildtool/buildtool/Clean
In directory 
sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv15949/buildtool/buildtool/Clean

Added Files:
        Buildclean.pm Distclean.pm Remove.pm Srcclean.pm 
Log Message:
initial import


--- NEW FILE: Remove.pm ---
#$Id: Remove.pm,v 1.1 2008/03/01 16:24:16 hejl Exp $

# remove everything that is part of a package
# the installed files and the unpacked and downloaded sources

package buildtool::Clean::Remove;

use buildtool::Clean::Buildclean;
use Carp;
use strict;

use vars qw(@ISA);

@ISA = qw(buildtool::Clean::Buildclean);


sub clean () {
  my $self = shift;
  my @list;
  if (@_) {
    @list = @_ ;
  } else {
    # get a list of all pkg/sources that are installed:
    @list = $self->getEntries("source");
  }
  print "removing: ". join(",",@list) . " ";
  # first of all, call Buildclean clean for this :
  $self->SUPER::clean(@list);

  foreach my $pkg (@list) {
    # after that remove the source dir
    my $dir = $self->_getSourceDir($pkg);
    $self->_forceRemoveDir($dir);
    # now get it out of the list of installed source packages:
    $self->deleteEntry("source", $pkg);
    $self->writeToFile();

  }


  $self->printOk() ;
  print "\n";
}
  
1;

--- NEW FILE: Srcclean.pm ---
#$Id: Srcclean.pm,v 1.1 2008/03/01 16:24:16 hejl Exp $

package buildtool::Clean::Srcclean;

use buildtool::Clean;
use Carp;
use strict;

use vars qw(@ISA);

@ISA = qw(buildtool::Clean::Buildclean);

###############################################################################
sub callMakeClean () {
  my $self = shift;
  my $pkg = shift || confess "no pkg given!";
  my $path = $self->_getSourceDir($pkg);

  my %globConf = %{$self->{'CONFIG'}}; 

  $self->SUPER::callMakeClean($pkg);

  print "calling 'make srcclean' for $pkg: ";
  # check if dir exists, if not, it is o.k.
  $self->dumpIt(\%globConf,0);
  if (! -d $path) {
        $self->debug("$path is not there, might be ok");
  } else {

        system("make -d -C ".$path. " -f ./".$globConf{'buildtool_makefile'}." 
srcclean MASTERMAKEFILE=".$globConf{'root_dir'}. "/make/MasterInclude.mk". " 
BT_BUILDROOT=". $globConf{'root_dir'}. " >>".$globConf{'logfile'}. " 2>&1" ) == 0
          or die "make clean ". $self->make_text_red("failed")." for 
".$path."/".$globConf{'buildtool_makefile'}." , please have a look at the 
logfile " . $globConf{'logfile'};
  }
  $self->print_ok();
  print "\n";
  return 1
}

sub clean () {
  my $self = shift;
  my $pkg ;
  my @list;

  if (@_) {
    @list = @_ ;
  } else {
    # get a list of all pkg/sources that are installed:
    @list = $self->getEntries("build");
  }

  foreach $pkg (@list) {
    # first have a look if already deleted:
    # if yes, do nothing!
    if (! $self->searchInstalled4Pkg("source", $pkg)) {
      $self->debug("$pkg is not in source list, maybe already cleaned!\n");
      if (!$self->{'CONFIG'}{'force'}) {
        # force is not enabled, so continue with next one
        next;
      } else {
        $self->debug("force enabled, trying to remove anyway");
      }
    }
    # first call make clean for the package buildtool.mk itself
    $self->callMakeClean($pkg);

    # now remove everything from our list:
    $self->_removePackageFiles($pkg);
    # remove the list
    $self->_removePackageListFile($pkg);

    # remove the pkg name from the list of build files:
    $self->deleteEntry("build", $pkg);
    $self->deleteEntry("source", $pkg);
    $self->writeToFile();

  }
}
1;

--- NEW FILE: Distclean.pm ---
#$Id: Distclean.pm,v 1.1 2008/03/01 16:24:16 hejl Exp $

# remove everything that is part of a package
# the installed files and the unpacked and downloaded sources

package buildtool::Clean::Distclean;

use buildtool::Common::Object;
use Carp;
use strict;

use vars qw(@ISA);

@ISA = qw(buildtool::Common::Object);


sub clean () {
      
      my $self = shift;
      $self->debug("starting");
  
      # remove the dirs in here...
      my @dirs = @{$self->{'CONFIG'}{'buildenv_dir'}};
      foreach my $dir (@dirs) {
            my $dir1 = $self->absoluteFilename($dir);
            print "removing $dir1 recursive ";
            if (system("rm -rf $dir1") != 0 ) {
                  my $err = "" . $!;
                  $self->die("removing $dir1 failed", $err);
            }
            $self->print_ok();
            print "\n";
      }
      # remove the installed packages file
      my $listfile = 
$self->absoluteFilename($self->{'CONFIG'}{'installedfile'});
      # read in the file if it exists
      if ( -e $listfile) {
            system ("rm -f $listfile") == 0 or
              die"removing $listfile failed: " . $!;
      }
      # now at last remove the directory for the installedfiles
      confess("buildtracedir not set in global config!") if 
(!$self->{'CONFIG'}{'buildtracedir'} or $self->{'CONFIG'}{'buildtracedir'} eq 
"");

      system ("rm", "-rf", $self->{'CONFIG'}{'buildtracedir'}) == 0 or
        $self->die("removing ". $self->{'CONFIG'}{'buildtracedir'}. "failed: ", 
"".$!);
      
}

1;


--- NEW FILE: Buildclean.pm ---
#$Id: Buildclean.pm,v 1.1 2008/03/01 16:24:16 hejl Exp $

package buildtool::Clean::Buildclean;

use buildtool::Clean;
use Carp;
use strict;

use vars qw(@ISA);

@ISA = qw(buildtool::Clean);

###############################################################################
sub callMakeClean () {
  my $self = shift;
  my $pkg = shift || confess "no pkg given!";
  my $path = $self->_getSourceDir($pkg);

  my %globConf = %{$self->{'CONFIG'}}; 

  print "calling 'make clean' for $pkg: ";
  # check if dir exists, if not, it is o.k.
  $self->dumpIt(\%globConf,0);
  if (! -d $path) {
        $self->debug("$path is not there, might be ok");
  } else {

        system("make -C ".$path. " -f ./".$globConf{'buildtool_makefile'}." 
clean MASTERMAKEFILE=".$globConf{'root_dir'}. "/make/MasterInclude.mk". " 
BT_BUILDROOT=". $globConf{'root_dir'}. " >>".$globConf{'logfile'}. " 2>&1" ) == 0
          or die "make clean ". $self->make_text_red("failed")." for 
".$path."/".$globConf{'buildtool_makefile'}." , please have a look at the 
logfile " . $globConf{'logfile'};
  }
  $self->print_ok();
  print "\n";
  return 1
}


###############################################################################
sub clean () {
  my $self = shift;
  my $pkg ;
  my @list;

  if (@_) {
    @list = @_ ;
  } else {
    # get a list of all pkg/sources that are installed:
    @list = $self->getEntries("build");
  }
  
  foreach $pkg (@list) {
    # first have a look if already deleted:
    # if yes, do nothing!
    if (! $self->searchInstalled4Pkg("build", $pkg)) {
      $self->debug("$pkg is not in build list, maybe already cleaned!\n");
      if (!$self->{'CONFIG'}{'force'}) {
        # force is not enabled, so continue with next one
        next;
      } else {
        $self->debug("force enabled, trying to remove anyway");
      }
    }
    # first call make clean for the package buildtool.mk itself
    $self->callMakeClean($pkg);

    # now remove everything from our list:
    $self->_removePackageFiles($pkg);
    # remove the list
    $self->_removePackageListFile($pkg);

    # remove the pkg name from the list of build files:
    $self->deleteEntry("build", $pkg);
    $self->writeToFile();

  }
}

###############################################################################
# remove the package file list
sub _removePackageListFile () {
  my $self = shift;
  my $pkg = shift;
  my $file = $self->_getInstalledListFileName($pkg);
  return $self->_removeFile($file);
}

###############################################################################
# remove the package files
sub _removePackageFiles () {
  my $self = shift;
  my $pkg = shift;

  print "removing installed files for package $pkg ";
  
  my @filelist = $self->_getFileList($pkg);
  $self->_removeFiles(@filelist);
  
  $self->print_ok();
  print "\n";


}


###############################################################################
sub _getInstalledListFileName () {
  my $self = shift;
  my $pkg = shift || confess "no package name given";
  return $self->absoluteFilename($self->{'CONFIG'}{'buildtracedir'}). "/". 
"$pkg" . ".list";
}

###############################################################################
sub _getFileList () {
  my $self = shift;
  my $pkg = shift;
  my $filename = $self->_getInstalledListFileName($pkg);
  my @list = ();

  # check if file exists:
  if ( -e $filename and (-f $filename > 0)) {
    my $fh = Symbol::gensym();
    
    open($fh, '< ' . $filename);
    while (my $line = <$fh>) {
      chop $line;
      if ($line ne "") {
        push @list, $line;
      }
    }
    close $fh;
 


  } else {
    $self->debug("$filename is not there or empty");

    }
  return @list;
}

1;


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
leaf-cvs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/leaf-cvs-commits

Reply via email to