[Bps-public-commit] r10059 - bpsbuilder/BPB/bin

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Dec 24 04:16:58 EST 2007


Author: sunnavy
Date: Mon Dec 24 04:16:57 2007
New Revision: 10059

Added:
   bpsbuilder/BPB/bin/bpb-builder

Log:
added build script

Added: bpsbuilder/BPB/bin/bpb-builder
==============================================================================
--- (empty file)
+++ bpsbuilder/BPB/bin/bpb-builder	Mon Dec 24 04:16:57 2007
@@ -0,0 +1,157 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use File::Spec;
+use File::Temp qw/tempdir/;
+use File::Copy qw/move copy/;
+use File::Find qw/find/;
+use Config;
+use Getopt::Long;
+use Cwd;
+my $build_base = getcwd;
+
+my %args;
+GetOptions( \%args, 'install-base=s', 'perl=s', 'skip-test' );
+
+unless ( $args{'install-base'} ) {
+    die 'need install-base option';
+}
+
+$args{perl} ||= 'perl';
+
+mkdir $args{'install-base'} unless -e $args{'install-base'};
+
+copy(
+    File::Spec->catfile( 'etc',                 'bpb-script-wrapper' ),
+    File::Spec->catfile( $args{'install-base'}, 'etc', 'bpb-script-wrapper' )
+);
+
+chmod 0755,
+  File::Spec->catfile( $args{'install-base'}, 'etc', 'bpb-script-wrapper' );
+
+my $order = parse_order( File::Spec->catfile( 'bpb', 'order.yml' ) );
+
+for (@$order) {
+    s/::/-/g;
+    install($_);
+    chdir $build_base;
+}
+
+wrap_bin();
+
+sub install {
+    my $dir = shift;
+    chdir File::Spec->catfile( 'dists', $dir );
+
+    my $lib = " -I"
+      . File::Spec->catfile( $args{'install-base'}, 'lib', 'perl5' ) . " -I"
+      . File::Spec->catfile( $args{'install-base'}, 'lib', 'perl5',
+        $Config{archname} );
+
+    if ( ! -f '__build' ) {
+        my @commands;
+
+        if ( -f 'configure' ) {
+            push @commands, './configure --prefix=' . $args{'install-base'},
+              'make', 'make install';
+        }
+        elsif ( -f 'Build.PL' ) {
+            push @commands,
+              $args{'perl'} 
+              . $lib
+              . " Build.PL --install_base="
+              . $args{'install-base'};
+            unless ( $args{'skip-test'} ) {
+                push @commands, "./Build test";
+            }
+            push @commands, "./Build install";
+        }
+        elsif ( -f 'Makefile.PL' ) {
+            push @commands,
+              $args{'perl'} 
+              . $lib
+              . " Makefile.PL INSTALL_BASE="
+              . $args{'install-base'};
+            unless ( $args{'skip-test'} ) {
+                push @commands, 'make test';
+            }
+
+            push @commands, "make install";
+        }
+        else {
+            warn "I have no idea how to build this distribution";
+        }
+        open my $fh, '>', '__build' or die $!;
+        print $fh $_, "\n" for @commands;
+        close $fh;
+    }
+    else {
+        substitute('__build');
+    }
+    chmod 0755, '__build';
+    system('./__build');
+}
+
+sub wrap_bin {
+    my $self = shift;
+
+    my %seen;
+
+    my $sub = sub {
+        my $file = $_;
+        return unless $file and -f $file;
+        return if $seen{$File::Find::name}++;
+        my $dir = ( File::Spec->splitdir($File::Find::dir) )[-1];
+        mkdir File::Spec->catfile( $args{'install-base'}, "$dir-wrapped" )
+          unless -d File::Spec->catfile( $args{'install-base'},
+            "$dir-wrapped" );
+        move( $file =>
+              File::Spec->catfile( $args{'install-base'}, "$dir-wrapped" ) )
+          or die $!;
+        link File::Spec->catfile( $args{'install-base'}, 'etc',
+            'bpb-script-wrapper' ) => $file
+          or die $!;
+    };
+
+    for my $dir (qw(bin sbin libexec)) {
+        find( $sub,
+            grep { -d $_ }
+              map { File::Spec->catfile( $args{'install-base'}, $_ ) }
+              qw/bin sbin libexec/ );
+    }
+}
+
+sub substitute {
+    my $file = shift;
+    return unless $file;
+
+    my $text;
+    {
+        local $/;
+        open my $fh, '<', $file or die $!;
+        $text = <$fh>;
+        close $fh;
+    }
+    my $perl         = $args{'perl'};
+    my $install_base = $args{'install-base'};
+    $text =~ s/%%PERL%%/$perl/g;
+    $text =~ s/%%INSTALL_BASE%%/$install_base/g;
+
+    open my $fh, '>', $file or die $!;
+    print $fh $text;
+    close $fh;
+}
+
+sub parse_order {
+    my $file  = shift;
+    my $order = [];
+    open my $fh, '<', $file or die $!;
+    while (<$fh>) {
+        if (/^- ([-\w]+)/) {
+            push @$order, $1;
+        }
+    }
+    return $order;
+}
+



More information about the Bps-public-commit mailing list