Changeset 995
- Timestamp:
- 12/29/06 17:51:48 (2 years ago)
- Files:
-
- branches/mt3.34/build/Build.pm (modified) (27 diffs)
- branches/mt3.34/build/exportmt (deleted)
- branches/mt3.34/build/exportmt.pl (modified) (2 diffs)
- branches/mt3.34/build/mt-dists/MT.mk (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/mt3.34/build/Build.pm
r688 r995 11 11 12 12 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 23 24 24 25 =head1 DESCRIPTION 25 26 26 A C<Build> object contains allthe internal routines needed to build27 Movable Type distributions .27 A C<Build> object contains the internal routines needed to build 28 Movable Type distributions in multiple languages. 28 29 29 30 Please see the full documentation at: … … 36 37 use Archive::Tar; 37 38 use Cwd; 38 use ExtUtils::Install 1.37_02;39 39 use File::Basename; 40 40 use File::Copy; … … 46 46 use Net::SMTP; 47 47 use Sys::Hostname; 48 49 =head2 METHODS50 51 =cut52 48 53 49 sub new { … … 70 66 'deploy:s' => '', #($ENV{USER}||$ENV{USERNAME}).'@rongo:/usr/local/cifs/intranet/mt-interest/', 71 67 'deploy-uri=s' => 'https://intranet.sixapart.com/mt-interest', 68 'build!' => 1, # Build distribution files? 72 69 'email-bcc:s' => undef, 73 70 'email-body=s' => '', # Constructed at run-time. … … 85 82 'ldap' => 0, # Use LDAP (and don't initialize the database). 86 83 'lang=s' => $ENV{BUILD_LANGUAGE} || 'en_US', # de,es,en_US,fr,ja,nl 84 'language=s@' => undef, # Constructed below. 87 85 'local' => 0, # Command-line --option alias 86 'make' => 0, # Command-line --option alias for simple legacy `make` 88 87 'notify:s' => undef, # Send email notification on completion. 89 88 'pack=s' => undef, # Constructed at run-time. … … 91 90 'plugin-uri=s' => 'http://code.sixapart.com/svn/mtplugins/trunk', 92 91 'prod' => 0, # Command-line --option alias 92 'prod-dir=s' => 'Production_Builds', 93 93 'qa' => 0, # Command-line --option alias 94 94 'repo=s' => 'trunk', # Reset at runtime depending on branch,tag. … … 106 106 ); 107 107 108 # Map all literal string values to a scalar referencebecause108 # Map all literal string values to scalar references because 109 109 # Getopt::Long wants it that way. 110 110 while( my( $key, $val ) = each %o ) { … … 120 120 } 121 121 122 # XXX Can't figure out how to pre-define arrays yet.123 122 # Make sure we have an archive file type list. 124 123 $self->{'arch=s@'} ||= [qw( .tar.gz .zip )]; 125 124 # Make the plugins an empty list unless defined. 126 125 $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'}; 127 130 } 128 131 129 132 sub setup { 130 133 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; 131 150 132 151 $self->{'pack=s'} ||= -e 'build/mt-dists/MTE.mk' ? 'MTE' : 'MT'; … … 138 157 $self->{'symlink!'} = 0; 139 158 } 159 if( $self->{'make'} ) { 160 $self->{'build!'} = 0; 161 $self->{'export!'} = 0; 162 } 140 163 if( $self->{'local'} ) { 141 164 $self->{'export!'} = 0; … … 147 170 # Grab our repository revision. 148 171 $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. 150 173 $self->set_repo(); 151 174 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 155 175 # Create the build-stamp if one is not already defined. 156 unless( $self->{'stamp=s'} ) {176 if( !$self->{'stamp=s'} || $args{language} ) { 157 177 # Read-in the configuration variables for substitution. 158 178 my $config = $self->read_conf( "build/mt-dists/$self->{'pack=s'}.mk" ); … … 162 182 : $self->{'beta=s'} ? "b$self->{'beta=s'}" 163 183 : '' ); 164 push @stamp, $self->{'short-lang=s'};165 184 # Add repo, date and ldap to the stamp if we are not production. 166 185 unless( $self->{'prod'} ) { 186 push @stamp, $self->{'short-lang=s'}; 167 187 if( $self->{'rev!'} ) { 168 188 push @stamp, lc( fileparse $self->{'repo=s'} ); … … 172 192 '%04d%02d%02d', (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3] 173 193 ) if $self->{'date!'}; 194 # Add -ldap to distingush them from Melody Nelson builds. 174 195 push @stamp, 'ldap' if $self->{'ldap'}; 175 196 } … … 184 205 # Set the full name to use for the distribution (e.g. MT-3.3b1-fr-r12345-20061225). 185 206 $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'}; 186 209 } 187 210 … … 197 220 } 198 221 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 } 207 235 208 236 if( !$self->{'debug'} && $self->{'export!'} ) { … … 250 278 # Add to the URL list depending on where we are deploying. 251 279 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'} ); 253 285 push @{ $distros->{url} }, $loc unless $seen{$loc}++; 254 286 } … … 272 304 if( $self->{'deploy:s'} =~ /:/ ) { 273 305 $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'} 275 309 ) ); 276 310 } … … 278 312 else { 279 313 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 283 333 copy( $dist, $dest ) or die( "ERROR: Can't copy $dist to $dest: $!" ) 284 334 unless $self->{'debug'}; 285 335 $self->verbose( "Copy $dist to $dest" ); 286 336 287 # Install if we are staging.337 # Install the build if we are staging. 288 338 $self->stage_distro( $dest ) if $self->{'stage'}; 289 339 290 # Update the staging html.340 # Update the build summary page. 291 341 $self->update_html( $dest ); 292 342 … … 315 365 my $cwd = cwd(); 316 366 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" ); 320 377 321 378 # Do we have a current symlink? … … 331 388 $current_db = 'stage_' . $current_db; 332 389 333 # Grabthe literal build directory name.390 # Set the stage_dir to the literal build directory name. 334 391 my $stage_dir = fileparse( $dest, @{ $self->{'arch=s@'} } ); 392 # Reset the staging root directory. 393 $stage_root = File::Spec->catdir( $stage_root, $stage_dir ); 335 394 336 395 # Remove any existing distro, with the same path name. 337 if( -d $stage_ dir) {338 rmtree( $stage_ dir) or339 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 $!" ) 340 399 unless $self->{'debug'}; 341 $self->verbose( "Remove: $stage_ dir" );400 $self->verbose( "Remove: $stage_root" ); 342 401 } 343 402 … … 354 413 } 355 414 356 # Tar-upthe distribution.415 # Un-tar the distribution. 357 416 my $tar; 358 417 unless( $self->{'debug'} ) { … … 364 423 365 424 # 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 $!" ) 367 426 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; 369 433 370 434 # Our database is named the same as the distribution (but with _'s) except for LDAP. … … 376 440 377 441 # 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 ); 380 449 381 450 # Give unto us a shiny, new config file. … … 467 536 !$self->{'prod'} && 468 537 !$self->{'ldap'} && 469 ($self->{'stage'} || $self->{'deploy:s'} eq $self->{'stage-dir=s'})538 ($self->{'stage'} || ($self->{'deploy:s'} eq $self->{'stage-dir=s'})) 470 539 ) { 471 540 my( $stage_dir, $suffix ); … … 567 636 sub plugin_export { 568 637 my $self = shift; 638 return unless $self->{'plugin=s@'}; 569 639 570 640 # Change to the export directory, if we are exporting. … … 729 799 my $self = shift; 730 800 $self->verbose( 'Entered inject_footer()' ); 731 return if $self->{'prod'} || $self->{'debug'} ;801 return if $self->{'prod'} || $self->{'debug'} || $self->{'make'}; 732 802 733 803 my $file = $self->{'export!'} … … 742 812 $fh->close(); 743 813 814 return if $contents =~ m/\Q$self->{'footer=s'}\E/; 815 744 816 $contents =~ s/Reserved.\n/Reserved.\n$self->{'footer=s'}/; 745 817 … … 756 828 } 757 829 830 sub languages { return @{ shift->{'language=s@'} } } 831 832 sub debug { return shift->{'debug'} } 833 834 sub help { return shift->{'help|h'} } 835 758 836 sub usage { 759 837 my $self = shift; 760 print << USAGE;838 print <<'USAGE'; 761 839 762 840 MT export build deployment notification automation. 763 764 841 Examples: 765 842 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 776 855 777 856 Please see the full documentation at: branches/mt3.34/build/exportmt.pl
r688 r995 1 1 #!/usr/bin/perl 2 #3 2 # $Id$ 4 #5 3 use strict; 6 4 use warnings; 7 5 use lib 'build'; 6 use Build; 8 7 use Data::Dumper; 9 8 $Data::Dumper::Indent = $Data::Dumper::Terse = $Data::Dumper::Sortkeys = 1; 10 11 use lib 'build';12 use Build;13 9 14 10 my $build = Build->new(); … … 20 16 21 17 # Show the usage if requested. 22 $build->usage() if $build-> {'help|h'};18 $build->usage() if $build->help(); 23 19 24 # Perform some preliminary contextual set-up. 25 $build->setup();20 for( $build->languages() ) { 21 $build->setup( language => $_ ); 26 22 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(); 32 27 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(); 35 30 36 # Export the latest files.37 $build->export();31 # Export the latest files. 32 $build->export(); 38 33 39 # Add the non-production footer.40 $build->inject_footer();34 # Export any plugins that are requested. 35 $build->plugin_export(); 41 36 42 # Make the all-important make calls.43 $build->make();37 # Add a non-production footer. 38 $build->inject_footer(); 44 39 45 # Create lists of the distributions.46 my $distros = $build->create_distro_list();40 # Actually build the distribution files. 41 $build->make(); 47 42 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(); 50 45 51 # Cleanup the exported files.52 $build->cleanup();46 # Deploy the distributions. 47 $build->deploy_distros( $distros ); 53 48 54 # Send email notification.55 $build->notify( $distros);49 # Cleanup the exported files. 50 $build->cleanup(); 56 51 57 exit; 52 # TODO Factor out the (rarely used) email notification. 53 $build->notify( $distros ); 54 } 55 56 __END__ 57 58 =head1 NAME 59 60 exportmt - Movable Type Export Build Deployment and Notification 61 62 =head1 SEE ALSO 63 64 https://intranet.sixapart.com/wiki/index.php/Movable_Type:MT_Export-Deploy 65 66 The L<Build> (F<build/Build.pm>) module. 67 68 =cut branches/mt3.34/build/mt-dists/MT.mk
r469 r995 2 2 PRODUCT_CODE = MT 3 3 PRODUCT_VERSION = 3.3 4 SCHEMA_VERSION = 3.3 4 SCHEMA_VERSION = 3.3007 5 API_VERSION = 3.34
