[Bps-public-commit] r10061 - in bpsbuilder/BPB/lib/BPB: .
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Mon Dec 24 04:37:37 EST 2007
Author: sunnavy
Date: Mon Dec 24 04:37:37 2007
New Revision: 10061
Modified:
bpsbuilder/BPB/lib/BPB/Backend.pm
bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
Log:
automatically add bin/bpb-builder when init a project
Modified: bpsbuilder/BPB/lib/BPB/Backend.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Backend.pm Mon Dec 24 04:37:37 2007
@@ -50,6 +50,167 @@
EOF
;
+our $BUILDER = <<'EOF'
+#!/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;
+}
+
+
+EOF
+;
1;
__END__
Modified: bpsbuilder/BPB/lib/BPB/Backend/SVK.pm
==============================================================================
--- bpsbuilder/BPB/lib/BPB/Backend/SVK.pm (original)
+++ bpsbuilder/BPB/lib/BPB/Backend/SVK.pm Mon Dec 24 04:37:37 2007
@@ -31,7 +31,7 @@
sub initialize {
my $self = shift;
my $dir = tempdir( CLEANUP => 1 );
- for (qw/bpb dists etc/) {
+ for (qw/bpb dists etc bin/) {
mkdir File::Spec->catfile( $dir, $_ );
}
open my $order, '>', File::Spec->catfile( $dir, 'bpb', 'order.yml' );
@@ -42,6 +42,11 @@
print $wrapper $BPB::Backend::WRAPPER;
close $wrapper;
+ open my $builder, '>', File::Spec->catfile( $dir, 'bin',
+ 'bpb-builder' );
+ print $builder $BPB::Backend::BUILDER;
+ close $builder;
+
$self->import( source => $dir, _initialize => 1 );
}
More information about the Bps-public-commit
mailing list