[Bps-public-commit] r9918 - bpsbuilder/bin

jesse at bestpractical.com jesse at bestpractical.com
Wed Dec 12 12:50:40 EST 2007


Author: jesse
Date: Wed Dec 12 12:50:40 2007
New Revision: 9918

Added:
   bpsbuilder/bin/build-bin-dist
      - copied, changed from r8198, /bpsbuilder/bin/build
   bpsbuilder/bin/build-source-dist
      - copied, changed from r8198, /bpsbuilder/bin/build

Log:
*it helps if I commit stuff

Copied: bpsbuilder/bin/build-bin-dist (from r8198, /bpsbuilder/bin/build)
==============================================================================
--- /bpsbuilder/bin/build	(original)
+++ bpsbuilder/bin/build-bin-dist	Wed Dec 12 12:50:40 2007
@@ -3,41 +3,183 @@
 use strict;
 use Getopt::Long;
 use YAML;
-use BPSBuilder::Util;
-use File::Temp qw/tempdir/;
+use File::Copy qw/move/;
+use File::Find qw/find/;
 
 my %flags;
+our $WRAPPER = join('',<DATA>);
 
-GetOptions( \%flags, 'project=s', 'target=s', 'mode=s' );
 
-unless ( $flags{'project'} ) {
-    die "--project needed. (What is the name of the project we're building?)";
+GetOptions( \%flags, 'target=s', 'source=s' );
+
+my $DEST_PATH;
+my $SOURCE_PATH =  $flags{'source'} || '.' ;
+my $SUBSTITUTE = { INSTALLDIR => $DEST_PATH, PERL => $^X };
+
+if  (! $flags{'target'} ) {
+    die '--target required. (Where should I install to?)';
+} else {
+    $DEST_PATH = $flags{'target'};
+
 }
 
-unless ( $flags{'target'} ) {
-    die '--target required. (Where should I install to?';
+
+for (qw(LD_LIBRARY_PATH DYLD_LIBRARY_PATH)) {
+    $ENV{$_} = $DEST_PATH . "/lib:" . $ENV{$_} if ( $ENV{$_} );
 }
+create_build_directories();
+build_project();
+wrap_project_bins();
+print "Your distribution awaits in ". $DEST_PATH;
+exit;
 
 
+sub create_build_directories {
 
-my $tmp_dir = tempdir( CLEANUP => 0 );
+    unless ( -d $DEST_PATH ) {
+        mkdir( $DEST_PATH ) || die $DEST_PATH . ": $!";
+    }
+}
 
-my $backend = BPSBuilder::Util->new(
-    {   build_path   => File::Spec->catpath( $tmp_dir, 'autobuild' ),
-        project      => lc( $flags{project} ),
-        install_path => $flags{'target'}
+sub build_project {
+    warn "Now installing";
+    my $total_build_order
+        = YAML::LoadFile( $SOURCE_PATH . '/buildscripts/_order.yml' );
+    foreach my $item (@$total_build_order) {
+        warn "considering  " . YAML::Dump($item);
+        if ( $item->{meta} eq 'CPAN' ) {
+            install_cpan_modules( build_dir => $SOURCE_PATH );
+        } else {
+            install_package( $item->{'package'} );
+        }
     }
-);
+}
 
-for (qw(LD_LIBRARY_PATH DYLD_LIBRARY_PATH)) {
-$ENV{$_} = $backend->install_path . "/lib:" . $ENV{$_} if ($ENV{$_}); 
+sub install_cpan_modules {
+
+    my $build_order = YAML::LoadFile(
+        $SOURCE_PATH . '/cpan/_cpan_autobuild_order/order.yml' );
+
+    my $base_wd;
+    chomp( $base_wd = `pwd` );
+    foreach my $dist (@$build_order) {
+        warn "Installing  $dist";
+        chdir( 'autobuild/cpan/' . $dist );
+        install_from_cwd($dist);
+        chdir($base_wd);
+    }
+}
+
+sub install_package {
+    my $package = shift;
+    my $wd;
+    chomp( $wd = `pwd` );
+    my $packagedir = 'autobuild/packages/' . $package;
+    unless ( -d $packagedir ) {
+        die "$packagedir doesn't exist. Perhaps that software isn't packaged";
+    }
+    chdir($packagedir);
+    install_from_cwd($package);
+    chdir($wd);
+
+}
+
+
+
+sub wrap_project_bins {
+    mkdir( $DEST_PATH . "/etc" );
+    open( my $wrapper, ">" . $DEST_PATH . "/etc/bps-script-wrapper" )
+        || die $!;
+    print $wrapper $WRAPPER || die $!;
+    close($wrapper)         || die $!;
+
+    foreach my $dir (qw(bin sbin libexec)) {
+        find( \&wrapperize_directory,
+            grep    { -d $_ }
+                map { $DEST_PATH . "/" . $_ } qw(bin sbin libexec) );
+    }
+    our %seen;
+
+    sub wrapperize_directory {
+        my $file = $_;
+        return unless $file and -f $file;
+        return if $seen{$File::Find::name}++;
+        my $dir = $File::Find::dir;
+        $dir =~ s/^.*\///g;    # We want the last part only
+        warn "Making ../$dir-wrapped for $file";
+        mkdir("../$dir-wrapped");
+        warn "Moving $file to ../$dir-wrapped/";
+        move( $file => "../$dir-wrapped/" ) || die $@;
+        warn $File::Find::dir . '/../etc/bps-script-wrapper' => $file;
+        link( $File::Find::dir . '/../etc/bps-script-wrapper' => $file )
+            || die $!;
+
+    }
+
+}
+
+sub install_from_cwd {
+    my $package = shift;
+    my $buildfile = $SOURCE_PATH . '/buildscripts/' . $package . '/build.yml';
+
+    my @commands;
+    warn "In " . `pwd` . "for $package " . $buildfile;
+    if ( -f $buildfile ) {
+        my $directions = YAML::LoadFile($buildfile);
+        foreach my $cmd ( @{ $directions->{'commands'} } ) {
+            push @commands, $cmd;
+        }
+    } elsif ( -f 'Build.PL' ) {
+        push @commands, "%%PERL%% Build.PL --install_base=%%INSTALLDIR%%";
+        push @commands, "%%PERL%% ./Build test install";
+    } elsif ( -f 'Makefile.PL' ) {
+        push @commands, "%%PERL%% Makefile.PL INSTALL_BASE=%%INSTALLDIR%%";
+        push @commands, "make all test install";
+
+    } else {
+        warn "I have no idea how to build this distribution";
+    }
+
+    foreach my $cmd (@commands) {
+        $cmd =~ s/%%(.*?)%%/$SUBSTITUTE->{$1}/ge;
+        run($cmd);
+
+    }
 }
-$backend->create_build_directories();
-warn "Created dirs";
-$backend->checkout_project();
-warn "Checked out project";
-$backend->install_project();
-warn "Installed project";
-$backend->wrap_project_bins();
-warn "DONE";
+
+
+=head2 run @CMD
+
+execs the command. currently it doesn't capture the output. But it should
+
+=cut
+
+sub run {
+    my @cmd  = @_;
+    print "Running Command: ".join(" ", @cmd)."\n";
+    system(@cmd);    # if ($!) {  die "$cmd failed: $!"};
+}
+
 1;
+
+
+__DATA__
+#!/bin/sh
+if [ -z `which readlink` ]; then  
+    # if we don't have readlink, we're on some pitiful platform like solaris
+    test -h $0 && BASE=`ls -l $0 | awk -F\>  '{print $NF}'`
+else
+    BASE=`readlink $0`
+fi
+if [ -z "$BASE" ]; then
+        BASE=$0
+fi
+BASE_DIR=`dirname "$BASE"`
+BASE_DIR=` (cd "$BASE_DIR"; pwd) `
+FILENAME=`basename "$BASE"`
+WRAPPED_DIR=`basename "$BASE_DIR"`
+LD_LIBRARY_PATH=${BASE_DIR}/../lib:${LD_LIBRARY_PATH}\
+    DYLD_LIBRARY_PATH=${BASE_DIR}/../lib:${DYLD_LIBRARY_PATH}\
+    exec ${BASE_DIR}/../${WRAPPED_DIR}-wrapped/${FILENAME}  "$@"
+
+EOF

Copied: bpsbuilder/bin/build-source-dist (from r8198, /bpsbuilder/bin/build)
==============================================================================
--- /bpsbuilder/bin/build	(original)
+++ bpsbuilder/bin/build-source-dist	Wed Dec 12 12:50:40 2007
@@ -36,8 +36,4 @@
 warn "Created dirs";
 $backend->checkout_project();
 warn "Checked out project";
-$backend->install_project();
-warn "Installed project";
-$backend->wrap_project_bins();
-warn "DONE";
 1;



More information about the Bps-public-commit mailing list