[Bps-public-commit] r9908 - in bpsbuilder/BPB/lib/BPB: . Source

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Dec 12 04:54:58 EST 2007


Author: sunnavy
Date: Wed Dec 12 04:54:58 2007
New Revision: 9908

Modified:
   bpsbuilder/BPB/lib/BPB/Build.pm
   bpsbuilder/BPB/lib/BPB/Script/Import.pm
   bpsbuilder/BPB/lib/BPB/Source.pm
   bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
   bpsbuilder/BPB/lib/BPB/Source/Directory.pm

Log:
now the workflow is create, import and build. :)

Modified: bpsbuilder/BPB/lib/BPB/Build.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Build.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Build.pm	Wed Dec 12 04:54:58 2007
@@ -9,12 +9,13 @@
 __PACKAGE__->mk_accessors(qw/install_directory perl build_directory skip_test/);
 
 use File::Spec;
-
-use Data::Dumper;
+use File::Temp qw/tempdir/;
 
 sub new {
     my $class = shift;
     my $self  = {@_};
+    $self->{build_directory} =
+      File::Spec->catfile( tempdir( CLEANUP => 0 ), 'build' );
     bless $self, $class;
 }
 
@@ -26,8 +27,6 @@
         $self->$_( $args{$_} ) if $args{$_};
     }
 
-    croak 'need build_directory option' unless $self->build_directory;
-
     mkdir $self->install_directory unless -e $self->install_directory;
 
     chdir $self->build_directory;

Modified: bpsbuilder/BPB/lib/BPB/Script/Import.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Script/Import.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Script/Import.pm	Wed Dec 12 04:54:58 2007
@@ -23,8 +23,16 @@
 sub run {
     my $self   = shift;
     my $source = shift;
+
     $self->source($source) if $source;
-    my $bpb = BPB->new( config => $self->config, name => $self->name );
+    my $bpb = BPB->new(
+        config => $self->config,
+        name   => $self->name,
+        source => $self->source
+    );
+
+    $self->source($bpb->source->run);
+
     $self->import_req( $self->source, $bpb );
     $bpb->backend->import( map { $_, $self->$_ } qw/comment source/ );
 }
@@ -37,18 +45,21 @@
     my $bpb          = shift;
     my $require_file = File::Spec->catfile( $source, '_require.yml' );
 
+    my $dir = parent_dir( $source );
+
+    my $map_file     = File::Spec->catfile( $dir, 'map.yml' );
+
     if ( -e $require_file ) {
         my $req = BPB::Config::LoadFile($require_file);
         my $map = {};
 
-        if ( -e $bpb->config->name->{source}{map_path} ) {
-            $map =
-                BPB::Config::LoadFile($bpb->config->name->{source}{map_path});
+        if ( -e $map_file ) {
+            $map = BPB::Config::LoadFile($map_file);
         }
 
-        opendir my $dir, $bpb->config->name->{source}{directory};
-        my @sources = readdir $dir;
-        close $dir;
+        opendir my( $d ), $dir;
+        my @sources = readdir $d;
+        close $d;
 
         for my $module ( keys %$req ) {
             my $dist = $map->{$module} || $module;
@@ -56,17 +67,17 @@
 
             unless ( $imported{$dist} ) {
                 $imported{$dist}++;
-                my $dir = ( grep { /^$dist/ } @sources )[0];
+                my $s = ( grep { /^$dist/ } @sources )[0];
                 warn "we don't have $dist in source which is for "
                   . $self->source
-                  unless $dir;
-                $self->import_req( $source, $bpb );
+                  unless $s;
+                $s = File::Spec->catfile( $dir, $s );
+                $self->import_req( $dir, $s, $bpb );
+
                 $bpb->backend->import(
                     _deps   => 1,
                     comment => 'deps for ' . $source,
-                    source  => File::Spec->catfile(
-                        $bpb->config->name->{source}{directory}, $dir
-                    )
+                    source  => $s,
                 );
             }
         }
@@ -74,6 +85,14 @@
     }
 }
 
+
+sub parent_dir {
+    my $source = shift;
+    my @dirs = File::Spec->splitdir( $source );
+    pop @dirs;
+    return File::Spec->catfile( @dirs );
+}
+
 1;
 
 __END__

Modified: bpsbuilder/BPB/lib/BPB/Source.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source.pm	Wed Dec 12 04:54:58 2007
@@ -5,22 +5,20 @@
 use Carp;
 use UNIVERSAL::require;
 use Hash::Merge qw/merge/;
-
+use File::Temp qw/tempdir/;
 
 Hash::Merge::set_behavior('RIGHT_PRECEDENT');
 
 our %DEFAULT = (
-    directory => '/tmp',
-    command   => {
-        compressed => 'tar',
-        http       => 'wget',
-        ftp        => 'wget',
-        directory  => 'cp',
-    },
-    follow => 1,
+    follow            => 1,
     mini_perl_version => 5.008.008,
 );
 
+$DEFAULT{directory} = tempdir( CLEANUP => 1 );
+$DEFAULT{download_directory} =
+  File::Spec->catfile( $DEFAULT{directory}, 'download' );
+$DEFAULT{map_path} = File::Spec->catfile( $DEFAULT{directory}, 'map.yml' );
+
 =head2 new
 
 =cut

Modified: bpsbuilder/BPB/lib/BPB/Source/Compressed.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Compressed.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Compressed.pm	Wed Dec 12 04:54:58 2007
@@ -13,9 +13,10 @@
 
 sub run {
     my $self = shift;
-    $self->SUPER::run();
+    my $ret = $self->SUPER::run();
     $self->_copy( @_ );
     $self->_follow($self->path) if $self->follow;
+    return $self->path;
 }
 
 =head2 path

Modified: bpsbuilder/BPB/lib/BPB/Source/Directory.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Source/Directory.pm	(original)
+++ bpsbuilder/BPB/lib/BPB/Source/Directory.pm	Wed Dec 12 04:54:58 2007
@@ -26,6 +26,7 @@
     my $self = shift;
     $self->SUPER::run();
     $self->_follow($self->path) if $self->follow;
+    return $self->path;
 }
 
 sub path {



More information about the Bps-public-commit mailing list