[Bps-public-commit] r9789 - in bpsbuilder/BPB/lib/BPB: Backend

sunnavy at bestpractical.com sunnavy at bestpractical.com
Sun Dec 2 11:38:40 EST 2007


Author: sunnavy
Date: Sun Dec  2 11:38:39 2007
New Revision: 9789

Modified:
   bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
   bpsbuilder/BPB/lib/BPB/Script/Import.pm

Log:
we can import modules's dependances automatically now, as long as we have it in source directory

Modified: bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend/SVK.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Backend/SVK.pm	Sun Dec  2 11:38:39 2007
@@ -3,6 +3,8 @@
 use warnings;
 use strict;
 use Carp;
+use File::Spec;
+use CPAN::DistnameInfo;
 
 # command option is svk's path info, e.g. '/usr/bin/svk'
 # path is under repository/project/, e.g.
@@ -74,9 +76,9 @@
     my $self = shift;
     my $type = shift;
     my %args = @_;
-    $args{extra} ||= [];
+    $args{extra}    ||= [];
     $args{category} ||= '';
-    $args{path} ||= '';
+    $args{path}     ||= '';
 
     for ( @{ $REQUIRE_OPTIONS{$type} } ) {
         croak "$type need option $_" unless $args{$_};
@@ -88,14 +90,16 @@
 
         # if category is null, will checkout the whole project
         # if path is null, will check the whole category part
-        my $path =
-          $self->_absolute_path( $args{category}, $args{path} );
+        my $path = $self->_absolute_path( $args{category}, $args{path} );
         $cmd = join ' ', $self->command, 'checkout', $path, $args{target};
     }
     elsif ( $type eq 'import' ) {
-        push @{ $args{extra} }, '-m', $args{comment} || 'import';
+        push @{ $args{extra} }, '-m', q{'} . ( $args{comment} || 'import' ) .  q{'};
         my $path = $self->_absolute_path( $args{category} );
-        $cmd = join ' ', $self->command, 'import', $args{source}, $path;
+        my $name = $args{source};
+        $name =~ s!^.*/(.+)/?$!$1.tar.gz!;
+        $name = CPAN::DistnameInfo->new($name)->dist;
+        $cmd = join ' ', $self->command, 'import', $args{source}, "$path/$name";
     }
     else {
         croak "invalid command";

Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm	Sun Dec  2 11:38:39 2007
@@ -8,24 +8,62 @@
 __PACKAGE__->mk_accessors(qw/config moniker category comment source/);
 
 use BPB;
+use File::Spec;
+use BPB::Config;
 
 sub options {
-    ( 'c|config=s' => 'config',
-      'k|moniker=s' => 'moniker',
-      'g|category=s' => 'category',
-      'm|comment=s' => 'comment',
-      's|source=s' => 'source',
-    )
+    (
+        'c|config=s'   => 'config',
+        'k|moniker=s'  => 'moniker',
+        'g|category=s' => 'category',
+        'm|comment=s'  => 'comment',
+        's|source=s'   => 'source',
+    );
 }
 
-
 sub run {
     my $self = shift;
     my $bpb = BPB->new( config => $self->config, moniker => $self->moniker );
     $bpb->backend->import( map { $_, $self->$_ } qw/category comment source/ );
-
+    $self->import_req( $self->source, $bpb );
 }
 
+my %imported;
+
+sub import_req {
+    my $self         = shift;
+    my $source       = shift;
+    my $bpb = shift;
+    my $require_file = File::Spec->catfile( $source, '_require.yml' );
+
+    if ( -e $require_file ) {
+        my $req = BPB::Config::LoadFile($require_file);
+        opendir my $dir, $bpb->config->moniker->{source}{directory};
+        my @sources = readdir $dir;
+        close $dir;
+
+        for my $module ( keys %$req ) {
+            $module =~ s/::/-/g;
+            unless ( $imported{$module} ) {
+                $imported{$module}++;
+                my $dir = ( grep { /^$module/ } @sources )[0];
+                warn "we don't have $module in source which is for "
+                  . $self->source
+                  unless $dir;
+                $bpb->backend->import(
+                    category => 'dependance',
+                    comment  => 'deps for ' . $source,
+                    source => File::Spec->catfile(
+                        $bpb->config->moniker->{source}{directory}, $dir
+                    )
+                );
+                $self->import_req( $source, $bpb );
+            }
+
+        }
+
+    }
+} 
 
 1;
 



More information about the Bps-public-commit mailing list