Changeset 995

Show
Ignore:
Timestamp:
12/29/06 17:51:48 (2 years ago)
Author:
gboggs
Message:

Updating the build system.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mt3.34/build/Build.pm

    r688 r995  
    1111 
    1212 cd $MT_DIR 
    13  svn up 
    14  perl $0 --alpha=1 
    15  perl $0 --beta=42 
    16  perl $0 --debug 
    17  perl $0 --help 
    18  perl $0 --local 
    19  perl $0 --plugin=Foo 
    20  perl $0 --prod 
    21  perl $0 --qa 
    22  perl $0 --stage 
     13 svn update 
     14 perl build/exportmt.pl --help 
     15 perl build/exportmt.pl --debug 
     16    # --alpha=1 
     17    # --beta=42 
     18    # --local 
     19    # --make 
     20    # --plugin=Foo --plugin=Bar 
     21    # --prod 
     22    # --qa 
     23    # --stage 
    2324 
    2425=head1 DESCRIPTION 
    2526 
    26 A C<Build> object contains all the internal routines needed to build 
    27 Movable Type distributions
     27A C<Build> object contains the internal routines needed to build 
     28Movable Type distributions in multiple languages
    2829 
    2930Please see the full documentation at: 
     
    3637use Archive::Tar; 
    3738use Cwd; 
    38 use ExtUtils::Install 1.37_02; 
    3939use File::Basename; 
    4040use File::Copy; 
     
    4646use Net::SMTP; 
    4747use Sys::Hostname; 
    48  
    49 =head2 METHODS 
    50  
    51 =cut 
    5248 
    5349sub new { 
     
    7066      'deploy:s'        => '', #($ENV{USER}||$ENV{USERNAME}).'@rongo:/usr/local/cifs/intranet/mt-interest/', 
    7167      'deploy-uri=s'    => 'https://intranet.sixapart.com/mt-interest', 
     68      'build!'          => 1,  # Build distribution files? 
    7269      'email-bcc:s'     => undef, 
    7370      'email-body=s'    => '',  # Constructed at run-time. 
     
    8582      'ldap'            => 0,  # Use LDAP (and don't initialize the database). 
    8683      'lang=s'          => $ENV{BUILD_LANGUAGE} || 'en_US',  # de,es,en_US,fr,ja,nl 
     84      'language=s@'     => undef,  # Constructed below. 
    8785      'local'           => 0,  # Command-line --option alias 
     86      'make'            => 0,  # Command-line --option alias for simple legacy `make` 
    8887      'notify:s'        => undef,  # Send email notification on completion. 
    8988      'pack=s'          => undef,  # Constructed at run-time. 
     
    9190      'plugin-uri=s'    => 'http://code.sixapart.com/svn/mtplugins/trunk', 
    9291      'prod'            => 0,  # Command-line --option alias 
     92      'prod-dir=s'      => 'Production_Builds', 
    9393      'qa'              => 0,  # Command-line --option alias 
    9494      'repo=s'          => 'trunk',  # Reset at runtime depending on branch,tag. 
     
    106106    ); 
    107107 
    108     # Map all literal string values to a scalar reference because 
     108    # Map all literal string values to scalar references because 
    109109    # Getopt::Long wants it that way.  
    110110    while( my( $key, $val ) = each %o ) { 
     
    120120    } 
    121121 
    122     # XXX Can't figure out how to pre-define arrays yet. 
    123122    # Make sure we have an archive file type list. 
    124123    $self->{'arch=s@'} ||= [qw( .tar.gz .zip )]; 
    125124    # Make the plugins an empty list unless defined. 
    126125    $self->{'plugin=s@'} ||= []; 
     126    # Construct the list of languages to build. 
     127    $self->{'lang=s'} = 'de,en_US,es,fr,ja,nl' 
     128        if lc( $self->{'lang=s'} ) eq 'all'; 
     129    push @{ $self->{'language=s@'} }, split /,/, $self->{'lang=s'}; 
    127130} 
    128131 
    129132sub setup { 
    130133    my $self = shift; 
     134    my %args = @_; 
     135 
     136    my $prereq = 'ExtUtils::Install 1.37_02'; 
     137    eval "use $prereq"; 
     138    die( "ERROR: Can't handle plugin directory manipulation: $@" ) 
     139        if ref($@) or $@ ne ''; 
     140 
     141    # Do we have SSL support? 
     142    $prereq = 'Crypt::SSLeay'; 
     143    eval { require $prereq }; 
     144    warn( "WARNING: $prereq not found. Can't use SSL.\n" ) if $@; 
     145 
     146    # Replace the current language if given one as an argument. 
     147    $self->{'lang=s'} = $args{language} if $args{language}; 
     148    # Strip the dialect portion of the language code (ab_CD into ab). 
     149    ($self->{'short-lang=s'} = $self->{'lang=s'}) =~ s/([a-z]{2})_[A-Z]{2}$/$1/o; 
    131150 
    132151    $self->{'pack=s'} ||= -e 'build/mt-dists/MTE.mk' ? 'MTE' : 'MT'; 
     
    138157        $self->{'symlink!'} = 0; 
    139158    } 
     159    if( $self->{'make'} ) { 
     160        $self->{'build!'} = 0; 
     161        $self->{'export!'} = 0; 
     162    } 
    140163    if( $self->{'local'} ) { 
    141164        $self->{'export!'} = 0; 
     
    147170    # Grab our repository revision. 
    148171    $self->{'revision=s'} = repo_rev(); 
    149     # Figure out what repository to use and make sure we can connect
     172    # Figure out what repository to use
    150173    $self->set_repo(); 
    151174 
    152     # Make ab_CD into just ab. 
    153     ($self->{'short-lang=s'} = $self->{'lang=s'}) =~ s/([a-z]{2})_[A-Z]{2}$/$1/o; 
    154  
    155175    # Create the build-stamp if one is not already defined. 
    156     unless( $self->{'stamp=s'} ) { 
     176    if( !$self->{'stamp=s'} || $args{language} ) { 
    157177        # Read-in the configuration variables for substitution. 
    158178        my $config = $self->read_conf( "build/mt-dists/$self->{'pack=s'}.mk" ); 
     
    162182          : $self->{'beta=s'}  ? "b$self->{'beta=s'}" 
    163183          : '' ); 
    164         push @stamp, $self->{'short-lang=s'}; 
    165184        # Add repo, date and ldap to the stamp if we are not production. 
    166185        unless( $self->{'prod'} ) { 
     186            push @stamp, $self->{'short-lang=s'}; 
    167187            if( $self->{'rev!'} ) { 
    168188                push @stamp, lc( fileparse $self->{'repo=s'} ); 
     
    172192                '%04d%02d%02d', (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3] 
    173193            ) if $self->{'date!'}; 
     194            # Add -ldap to distingush them from Melody Nelson builds. 
    174195            push @stamp, 'ldap' if $self->{'ldap'}; 
    175196        } 
     
    184205    # Set the full name to use for the distribution (e.g. MT-3.3b1-fr-r12345-20061225). 
    185206    $self->{'export-dir=s'} = "$self->{'pack=s'}-$self->{'stamp=s'}"; 
     207    # Name the exported directory (and archive) with the language. 
     208    $self->{'export-dir=s'} .= "-$self->{'short-lang=s'}" if $self->{'prod'}; 
    186209} 
    187210 
     
    197220    } 
    198221 
    199     $self->verbose_command( sprintf( 
    200         '%s build/mt-dists/make-dists --package=%s --language=%s --stamp=%s %s', 
    201         $^X, 
    202         $self->{'pack=s'}, 
    203         $self->{'lang=s'}, 
    204         $self->{'export-dir=s'}, 
    205         ($self->{'verbose!'} ? '' : '--silent') 
    206     )); 
     222    if( $self->{'build!'} ) { 
     223        $self->verbose_command( sprintf( 
     224            '%s build/mt-dists/make-dists --package=%s --language=%s --stamp=%s %s', 
     225            $^X, 
     226            $self->{'pack=s'}, 
     227            $self->{'lang=s'}, 
     228            $self->{'export-dir=s'}, 
     229            ($self->{'verbose!'} ? '--silent' : '') 
     230        )); 
     231    } 
     232    else { 
     233        $self->verbose_command( 'make' ); 
     234    } 
    207235 
    208236    if( !$self->{'debug'} && $self->{'export!'} ) { 
     
    250278            # Add to the URL list depending on where we are deploying. 
    251279            if( $self->{'stage'} ) { 
    252                 my $loc = sprintf "%s/%s/mt.cgi", $self->{'stage-uri=s'}, $self->{'export-dir=s'}; 
     280                # Magically use the internal production folder if it exists. 
     281                my $loc = $self->{'prod'} && $self->{'prod-dir=s'} && $dist =~ /$self->{'prod-dir=s'}/ 
     282                    ? sprintf( "%s/%s/%s/mt.cgi", 
     283                        $self->{'stage-uri=s'}, $self->{'prod-dir=s'}, $self->{'export-dir=s'} ) 
     284                    : sprintf( "%s/%s/mt.cgi", $self->{'stage-uri=s'}, $self->{'export-dir=s'} ); 
    253285                push @{ $distros->{url} }, $loc unless $seen{$loc}++; 
    254286            } 
     
    272304    if( $self->{'deploy:s'} =~ /:/ ) { 
    273305        $self->verbose_command( sprintf( '%s %s %s', 
    274             'scp', join(' ', @{ $distros->{path} }), $self->{'deploy:s'} 
     306            'scp', 
     307            join(' ', @{ $distros->{path} }), 
     308            $self->{'deploy:s'} 
    275309        ) ); 
    276310    } 
     
    278312    else { 
    279313        for my $dist ( @{ $distros->{path} } ) { 
    280             my $dest = File::Spec->catdir( 
    281                 $self->{'deploy:s'}, scalar fileparse( $dist ) 
    282             ); 
     314            my $dest = ''; 
     315 
     316            # Magically use the internal production folder if it exists. 
     317            if( $self->{'prod'} && $self->{'stage'} && $self->{'prod-dir=s'} && 
     318                -e File::Spec->catdir( $self->{'stage-dir=s'}, $self->{'prod-dir=s'} ) 
     319            ) { 
     320                $dest = File::Spec->catdir( 
     321                    $self->{'deploy:s'}, 
     322                    $self->{'prod-dir=s'}, 
     323                    scalar fileparse( $dist ), 
     324                ); 
     325            } 
     326            else { 
     327                $dest = File::Spec->catdir( 
     328                    $self->{'deploy:s'}, 
     329                    scalar fileparse( $dist ), 
     330                ); 
     331            } 
     332 
    283333            copy( $dist, $dest ) or die( "ERROR: Can't copy $dist to $dest: $!" ) 
    284334                unless $self->{'debug'}; 
    285335            $self->verbose( "Copy $dist to $dest" ); 
    286336 
    287             # Install if we are staging. 
     337            # Install the build if we are staging. 
    288338            $self->stage_distro( $dest ) if $self->{'stage'}; 
    289339 
    290             # Update the staging html
     340            # Update the build summary page
    291341            $self->update_html( $dest ); 
    292342 
     
    315365    my $cwd = cwd(); 
    316366 
    317     chdir $self->{'stage-dir=s'} or 
    318         die( "ERROR: Can't chdir to $self->{'stage-dir=s'}: $!" ); 
    319     $self->verbose( "Change to staging root $self->{'stage-dir=s'}" ); 
     367    my $prod = $self->{'prod'} && $self->{'stage'} && $self->{'prod-dir=s'} && -e File::Spec->catdir( $self->{'stage-dir=s'}, $self->{'prod-dir=s'} ); 
     368 
     369    # Add the prod-dir to the staged directory if appropriate. 
     370    my $stage_root = $self->{'stage-dir=s'}; 
     371    $stage_root = File::Spec->catdir( $self->{'stage-dir=s'}, $self->{'prod-dir=s'} ) 
     372        if $prod; 
     373 
     374    chdir $stage_root or 
     375        die( "ERROR: Can't chdir to $stage_root $!" ); 
     376    $self->verbose( "Change to staging root $stage_root" ); 
    320377 
    321378    # Do we have a current symlink? 
     
    331388    $current_db = 'stage_' . $current_db; 
    332389 
    333     # Grab the literal build directory name. 
     390    # Set the stage_dir to the literal build directory name. 
    334391    my $stage_dir = fileparse( $dest, @{ $self->{'arch=s@'} } ); 
     392    # Reset the staging root directory. 
     393    $stage_root = File::Spec->catdir( $stage_root, $stage_dir ); 
    335394 
    336395    # Remove any existing distro, with the same path name. 
    337     if( -d $stage_dir ) { 
    338         rmtree( $stage_dir ) or 
    339             die( "ERROR: Can't rmtree the old $stage_dir $!" ) 
     396    if( -d $stage_root ) { 
     397        rmtree( $stage_root ) or 
     398            die( "ERROR: Can't rmtree the old $stage_root $!" ) 
    340399            unless $self->{'debug'}; 
    341         $self->verbose( "Remove: $stage_dir" ); 
     400        $self->verbose( "Remove: $stage_root" ); 
    342401    } 
    343402 
     
    354413    } 
    355414 
    356     # Tar-up the distribution. 
     415    # Un-tar the distribution. 
    357416    my $tar; 
    358417    unless( $self->{'debug'} ) { 
     
    364423 
    365424    # Change to the distribution directory. 
    366     chdir( $stage_dir ) or die( "ERROR: Can't chdir $stage_dir: $!" ) 
     425    chdir( $stage_root ) or die( "ERROR: Can't chdir $stage_root $!" ) 
    367426        unless $self->{'debug'}; 
    368     $self->verbose( "Change to $stage_dir" ); 
     427    $self->verbose( "Change to $stage_root" ); 
     428 
     429    # Make sure there is a user-style so we don't barf unneccessarily into the error_log. 
     430    open STYLE, "> user_styles.css" or 
     431        die( "ERROR: Can't touch user_styles.css $@" ); 
     432    close STYLE; 
    369433 
    370434    # Our database is named the same as the distribution (but with _'s) except for LDAP. 
     
    376440 
    377441    # Set the staging URL to a real location now. 
    378     my $url = sprintf '%s/%s/', 
    379         $self->{'stage-uri=s'}, ($self->{'symlink!'} ? $link : $stage_dir); 
     442    my $url = sprintf '%s/%s/', $self->{'stage-uri=s'}, 
     443        ($prod 
     444            ? File::Spec->catdir( $self->{'prod-dir=s'}, $stage_dir ) 
     445            : $self->{'symlink!'} 
     446                ? $link 
     447                : $stage_dir 
     448        ); 
    380449 
    381450    # Give unto us a shiny, new config file. 
     
    467536        !$self->{'prod'} && 
    468537        !$self->{'ldap'} && 
    469         ($self->{'stage'} || $self->{'deploy:s'} eq $self->{'stage-dir=s'}
     538        ($self->{'stage'} || ($self->{'deploy:s'} eq $self->{'stage-dir=s'})
    470539    ) { 
    471540        my( $stage_dir, $suffix ); 
     
    567636sub plugin_export { 
    568637    my $self = shift; 
     638    return unless $self->{'plugin=s@'}; 
    569639 
    570640    # Change to the export directory, if we are exporting. 
     
    729799    my $self = shift; 
    730800    $self->verbose( 'Entered inject_footer()' ); 
    731     return if $self->{'prod'} || $self->{'debug'}
     801    return if $self->{'prod'} || $self->{'debug'} || $self->{'make'}
    732802 
    733803    my $file = $self->{'export!'} 
     
    742812    $fh->close(); 
    743813 
     814    return if $contents =~ m/\Q$self->{'footer=s'}\E/; 
     815 
    744816    $contents =~ s/Reserved.\n/Reserved.\n$self->{'footer=s'}/; 
    745817 
     
    756828} 
    757829 
     830sub languages { return @{ shift->{'language=s@'} } } 
     831 
     832sub debug { return shift->{'debug'} } 
     833 
     834sub help { return shift->{'help|h'} } 
     835 
    758836sub usage { 
    759837    my $self = shift; 
    760     print <<USAGE
     838    print <<'USAGE'
    761839 
    762840 MT export build deployment notification automation. 
    763  
    764841 Examples: 
    765842 
    766  cd \$MT_DIR 
    767  svn up 
    768  perl $0 --alpha=1 
    769  perl $0 --beta=42 
    770  perl $0 --debug 
    771  perl $0 --help 
    772  perl $0 --local 
    773  perl $0 --prod 
    774  perl $0 --qa 
    775  perl $0 --stage 
     843 cd $MT_DIR 
     844 svn update 
     845 perl build/exportmt.pl --help 
     846 perl build/exportmt.pl --debug 
     847    # --alpha=1 
     848    # --beta=42 
     849    # --local 
     850    # --make 
     851    # --plugin=Foo --plugin=Foo 
     852    # --prod 
     853    # --qa 
     854    # --stage 
    776855 
    777856 Please see the full documentation at: 
  • branches/mt3.34/build/exportmt.pl

    r688 r995  
    11#!/usr/bin/perl 
    2 # 
    32# $Id$ 
    4 # 
    53use strict; 
    64use warnings; 
    7  
     5use lib 'build'; 
     6use Build; 
    87use Data::Dumper; 
    98$Data::Dumper::Indent = $Data::Dumper::Terse = $Data::Dumper::Sortkeys = 1; 
    10  
    11 use lib 'build'; 
    12 use Build; 
    139 
    1410my $build = Build->new(); 
     
    2016 
    2117# Show the usage if requested. 
    22 $build->usage() if $build->{'help|h'}
     18$build->usage() if $build->help()
    2319 
    24 # Perform some preliminary contextual set-up. 
    25 $build->setup(); 
     20for( $build->languages() ) { 
     21    $build->setup( language => $_ ); 
    2622 
    27 # Summarize what we are about to do. 
    28 $build->verbose( sprintf '* Debug mode is %s and system calls %s be made.', 
    29     $build->{'debug'} ? 'ON' : 'OFF', $build->{'debug'} ? "WON'T" : 'WILL', 
    30 ); 
    31 $build->verbose( sprintf('Run options: %s', Dumper $build) ) if $build->{'debug'}; 
     23    # Summarize what we are about to do. 
     24    $build->verbose( sprintf '* Debug mode is %s and system calls %s be made.', 
     25        $build->debug() ? 'ON' : 'OFF', $build->debug() ? "WON'T" : 'WILL' ); 
     26    $build->verbose( sprintf 'Run options: %s', Dumper $build ) if $build->debug(); 
    3227 
    33 # Get any existing distro with the same path name, out of the way. 
    34 $build->remove_copy(); 
     28    # Get any existing distro with the same path name, out of the way. 
     29    $build->remove_copy(); 
    3530 
    36 # Export the latest files. 
    37 $build->export(); 
     31    # Export the latest files. 
     32    $build->export(); 
    3833 
    39 # Add the non-production footer
    40 $build->inject_footer(); 
     34    # Export any plugins that are requested
     35    $build->plugin_export(); 
    4136 
    42 # Make the all-important make calls
    43 $build->make(); 
     37    # Add a non-production footer
     38    $build->inject_footer(); 
    4439 
    45 # Create lists of the distributions. 
    46 my $distros = $build->create_distro_list(); 
     40    # Actually build the distribution files. 
     41    $build->make(); 
    4742 
    48 # Deploy the distributions. 
    49 $build->deploy_distros( $distros ); 
     43    # Create lists of the distribution paths and uris. 
     44    my $distros = $build->create_distro_list(); 
    5045 
    51 # Cleanup the exported files. 
    52 $build->cleanup(); 
     46    # Deploy the distributions. 
     47    $build->deploy_distros( $distros ); 
    5348 
    54 # Send email notification
    55 $build->notify( $distros ); 
     49    # Cleanup the exported files
     50    $build->cleanup(); 
    5651 
    57 exit; 
     52    # TODO Factor out the (rarely used) email notification. 
     53    $build->notify( $distros ); 
     54
     55 
     56__END__ 
     57 
     58=head1 NAME 
     59 
     60exportmt - Movable Type Export Build Deployment and Notification 
     61 
     62=head1 SEE ALSO 
     63 
     64https://intranet.sixapart.com/wiki/index.php/Movable_Type:MT_Export-Deploy 
     65 
     66The L<Build> (F<build/Build.pm>) module. 
     67 
     68=cut 
  • branches/mt3.34/build/mt-dists/MT.mk

    r469 r995  
    22PRODUCT_CODE = MT 
    33PRODUCT_VERSION = 3.3 
    4 SCHEMA_VERSION = 3.3 
     4SCHEMA_VERSION = 3.3007 
     5API_VERSION = 3.34