[Bps-public-commit] r10556 - bpsbuilder/Shipwright/lib/Shipwright

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Jan 29 15:08:58 EST 2008


Author: sunnavy
Date: Tue Jan 29 15:08:53 2008
New Revision: 10556

Modified:
   bpsbuilder/Shipwright/lib/Shipwright/Backend.pm

Log:
set default install-base dir to a better name, and added clean arg

Modified: bpsbuilder/Shipwright/lib/Shipwright/Backend.pm
==============================================================================
--- bpsbuilder/Shipwright/lib/Shipwright/Backend.pm	(original)
+++ bpsbuilder/Shipwright/lib/Shipwright/Backend.pm	Tue Jan 29 15:08:53 2008
@@ -199,8 +199,11 @@
 }
 
 my %args;
-GetOptions( \%args, 'install-base=s', 'perl=s', 'skip=s', 'skip-test',
-    'only-test', 'force', 'help' );
+GetOptions(
+    \%args,      'install-base=s', 'perl=s', 'skip=s',
+    'skip-test', 'only-test',      'force',  'clean',
+    'project-name', 'help',
+);
 
 my $USAGE = <<'END'
 run: ./bin/shipwright-builder
@@ -229,10 +232,12 @@
     it's used to be sure everything is ok after we install with success. 
     need to specify --install-base.
 
+clean: clean the source
+
 END
-;
+  ;
 
-if ( $args{'help'} ) { 
+if ( $args{'help'} ) {
     print $USAGE;
     exit 0;
 }
@@ -240,65 +245,77 @@
 unlink 'build.log' if -e 'build.log';
 open my $log, '>', 'build.log' or die $!;
 
-unless ( $args{'install-base'} ) {
-    $args{'install-base'} = tempdir;
-    print $log "no default install-base, will set it to $args{'install-base'}\n";
-}
-
 $args{skip} = [ split /,\s*/, $args{skip} || '' ];
 
 my $order = parse_order( File::Spec->catfile( 'shipwright', 'order.yml' ) );
 
-unless ( $args{perl} ) {
-    if ( ( grep { $_ eq 'perl' } @$order )
-        && !( grep { $_ eq 'perl' } @{ $args{skip} } ) )
-    {
-        $args{perl} =
-          File::Spec->catfile( $args{'install-base'}, 'bin', 'perl' );
-    }
-    else {
-        $args{perl} = $^X;
-    }
-}
-
-{
-    no warnings 'uninitialized';
-    $ENV{DYLD_LIBRARY_PATH} =
-      File::Spec->catfile( $args{'install-base'}, 'lib' ) . ':'
-      . $ENV{DYLD_LIBRARY_PATH};
-    $ENV{LD_LIBRARY_PATH} =
-      File::Spec->catfile( $args{'install-base'}, 'lib' ) . ':'
-      . $ENV{LD_LIBRARY_PATH};
-    $ENV{PERL5LIB} =
-      File::Spec->catfile( $args{'install-base'}, 'lib', 'perl5', 'site_perl' )
-      . ':'
-      . File::Spec->catfile( $args{'install-base'}, 'lib', 'perl5' ) . ':'
-      . $ENV{PERL5LIB};
-    $ENV{PATH} =
-        File::Spec->catfile( $args{'install-base'}, 'bin' ) . ':'
-      . File::Spec->catfile( $args{'install-base'}, 'sbin' ) . ':'
-      . $ENV{PATH};
-    $ENV{PERL_MM_USE_DEFAULT} = 1;
-}
-
 if ( $args{'only-test'} ) {
     test();
 }
+elsif ( $args{'clean'} ) {
+    for my $dist (@$order) {
+        unless ( grep { $dist eq $_ } @{ $args{skip} } ) {
+            clean($dist);
+        }
+        chdir $build_base;
+    }
+}
 else {
+
+    # for install
+
+    my ($project_name) = $build_base =~ /([-\w]+)$/;
+    unless ( $args{'install-base'} ) {
+        my $dir = tempdir( $project_name . '-XXXXXX', DIR => '/tmp' );
+        $args{'install-base'} = File::Spec->catfile( $dir, $project_name );
+
+        print $log
+          "no default install-base, will set it to $args{'install-base'}\n";
+    }
+
+    unless ( $args{perl} ) {
+        if ( ( grep { $_ eq 'perl' } @$order )
+            && !( grep { $_ eq 'perl' } @{ $args{skip} } ) )
+        {
+            $args{perl} =
+              File::Spec->catfile( $args{'install-base'}, 'bin', 'perl' );
+        }
+        else {
+            $args{perl} = $^X;
+        }
+    }
+
+    {
+        no warnings 'uninitialized';
+        $ENV{DYLD_LIBRARY_PATH} =
+          File::Spec->catfile( $args{'install-base'}, 'lib' ) . ':'
+          . $ENV{DYLD_LIBRARY_PATH};
+        $ENV{LD_LIBRARY_PATH} =
+          File::Spec->catfile( $args{'install-base'}, 'lib' ) . ':'
+          . $ENV{LD_LIBRARY_PATH};
+        $ENV{PERL5LIB} =
+          File::Spec->catfile( $args{'install-base'}, 'lib', 'perl5',
+            'site_perl' )
+          . ':'
+          . File::Spec->catfile( $args{'install-base'}, 'lib', 'perl5' ) . ':'
+          . $ENV{PERL5LIB};
+        $ENV{PATH} =
+            File::Spec->catfile( $args{'install-base'}, 'bin' ) . ':'
+          . File::Spec->catfile( $args{'install-base'}, 'sbin' ) . ':'
+          . $ENV{PATH};
+        $ENV{PERL_MM_USE_DEFAULT} = 1;
+    }
+
     mkdir $args{'install-base'} unless -e $args{'install-base'};
 
     mkdir File::Spec->catfile( $args{'install-base'},       'etc' )
       unless -e File::Spec->catfile( $args{'install-base'}, 'etc' );
 
     for ( 'shipwright-script-wrapper', 'shipwright-perl-wrapper' ) {
-        copy(
-            File::Spec->catfile( 'etc', $_ ),
-            File::Spec->catfile(
-                $args{'install-base'}, 'etc', $_
-            )
-        );
+        copy( File::Spec->catfile( 'etc', $_ ),
+            File::Spec->catfile( $args{'install-base'}, 'etc', $_ ) );
     }
-    
+
     for my $dist (@$order) {
         unless ( grep { $dist eq $_ } @{ $args{skip} } ) {
             install($dist);
@@ -317,30 +334,13 @@
 sub install {
     my $dir = shift;
 
-    my @cmds;
-    {
-        open my $fh, '<', File::Spec->catfile( 'scripts', $dir, 'build' )
-          or die $!;
-        @cmds = <$fh>;
-        close $fh;
-        chomp @cmds;
-        @cmds = map { substitute($_) } @cmds;
-    }
+    my $cmds = cmds($dir);
 
     chdir File::Spec->catfile( 'dists', $dir );
 
-    for (@cmds) {
-        my ( $type, $cmd );
-        next unless /\S/;
-
-        if (/^(\S+):\s*(.*)/) {
-            $type = $1;
-            $cmd  = $2;
-        }
-        else {
-            $type = '';
-            $cmd  = $_;
-        }
+    for (@$cmds) {
+        my ( $type, $cmd ) = @$_;
+        next if $type eq 'clean';
 
         if ( $args{'skip-test'} && $type eq 'test' ) {
             print $log "skip build $type part in $dir\n";
@@ -385,7 +385,8 @@
             open my $fh, '<', $file or die "can't open $file: $!";
             my $shebang = <$fh>;
             if ( $shebang =~
-                m{\Q$args{'install-base'}\E(?:/|\\)(?:s?bin|libexec)(?:/|\\)(\w+)} )
+m{\Q$args{'install-base'}\E(?:/|\\)(?:s?bin|libexec)(?:/|\\)(\w+)}
+              )
             {
                 $type = $1;
             }
@@ -397,7 +398,8 @@
 
     # if we have this $type(e.g. perl) installed and have that specific wrapper,
     # then link to it, else link to the normal one
-        if ( $type && grep( { $_ eq $type } @$order )
+        if (   $type
+            && grep( { $_ eq $type } @$order )
             && -e File::Spec->catfile( '..', 'etc', "shipwright-$type-wrapper" )
           )
         {
@@ -422,7 +424,6 @@
 
 }
 
-
 sub substitute {
     my $text = shift;
     return unless $text;
@@ -477,7 +478,56 @@
 
 }
 
-EOF
+sub cmds {
+    my $dir = shift;
+
+    my @cmds;
+    {
+        open my $fh, '<', File::Spec->catfile( 'scripts', $dir, 'build' )
+          or die $!;
+        @cmds = <$fh>;
+        close $fh;
+        chomp @cmds;
+        @cmds = map { substitute($_) } @cmds;
+    }
+
+    my $return = [];
+    for (@cmds) {
+        my ( $type, $cmd );
+        next unless /\S/;
+
+        if (/^(\S+):\s*(.*)/) {
+            $type = $1;
+            $cmd  = $2;
+        }
+        else {
+            $type = '';
+            $cmd  = $_;
+        }
+        push @$return, [ $type, $cmd ];
+    }
+
+    return $return;
+}
+
+sub clean {
+    my $dir = shift;
+
+    my $cmds = cmds($dir);
+
+    chdir File::Spec->catfile( 'dists', $dir );
+
+    for (@$cmds) {
+        my ( $type, $cmd ) = @$_;
+        next unless $type eq 'clean';
+
+        print "we'll run the cmd: $cmd\n";
+        if ( system($cmd) ) {
+            print $log "clean $dir with failure: $!\n";
+        }
+    }
+}
+
 , 
 null => '',    
 );



More information about the Bps-public-commit mailing list