PageRenderTime 73ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/build/mt-dists/make-dists

https://code.google.com/p/movabletype/
Perl | 238 lines | 175 code | 41 blank | 22 comment | 13 complexity | cdc3a7758d7d328682d5e3849acf7962 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. #!/usr/bin/perl -w
  2. # Movable Type (r) (C) 2001-2010 Six Apart, Ltd. All Rights Reserved.
  3. # This code cannot be redistributed without permission from www.sixapart.com.
  4. # For more information, consult your Movable Type license.
  5. #
  6. # $Id: make-dists 5333 2010-02-25 03:20:03Z takayama $
  7. use strict;
  8. use lib 'extlib', 'lib';
  9. use ExtUtils::Manifest qw( maniread manicopy mkmanifest );
  10. use File::Copy;
  11. use File::Find;
  12. use File::Spec::Functions;
  13. use File::Basename;
  14. use Getopt::Long;
  15. my $langlist = '';
  16. my $stamp = '';
  17. my $package = '';
  18. my $license = '';
  19. my $silent = 0;
  20. no warnings;
  21. # WHY, oh why?
  22. *ExtUtils::Manifest::cp = sub {
  23. my ($srcFile, $dstFile) = @_;
  24. my ($perm,$access,$mod) = (stat $srcFile)[2,8,9];
  25. copy($srcFile,$dstFile);
  26. utime $access, $mod, $dstFile;
  27. # chmod a+rX-w,go-w
  28. chmod( 0644 | ( $perm & 0111 ? 0111 : 0 ), $dstFile )
  29. unless ($^O eq 'MacOS');
  30. };
  31. use warnings;
  32. # disables resource fork handling for tar command on OS X
  33. $ENV{COPYFILE_DISABLE} = 'true';
  34. GetOptions(
  35. 'language:s' => \$langlist,
  36. 'package:s' => \$package,
  37. 'silent' => \$silent,
  38. 'license:s' => \$license,
  39. 'stamp:s' => \$stamp,
  40. ) or die "ERROR: Couldn't get the command-line options";
  41. my %options;
  42. my $make = 'make';
  43. $make .= ' -s' if $silent;
  44. $ExtUtils::Manifest::Quiet = $silent;
  45. $ExtUtils::Manifest::Verbose = ! $silent;
  46. my $skip = 'MANIFEST.SKIP';
  47. my $skip_bak = "$skip.bak";
  48. my $orig = eval {
  49. verbose_command("$make clean");
  50. verbose_command("$make lib/MT.pm");
  51. require MT;
  52. $package . '-' . MT->VERSION;
  53. } or die "ERROR: Failed to get version from package $package";
  54. my $skip_rules = `cat $skip`;
  55. if ($skip_rules =~ m/^#\?/m) { # conditional rule
  56. move($skip, $skip_bak);
  57. }
  58. my @languages = split(/,/, $langlist);
  59. @languages = qw( en_US nl fr de es ja ) unless @languages;
  60. for my $lang (@languages) {
  61. $options{language} = $lang;
  62. $options{package} = $package;
  63. $options{license} = $license;
  64. print join(" ", @languages), "\n";
  65. my $short_lang = $lang;
  66. # If there are not any _'s in the language double it: xx_XX.
  67. my $long_lang = ($lang =~ /_/ ? $lang : $lang . '_' . uc($lang));
  68. # ..unless we are Japanese.
  69. $long_lang = 'ja' if ($lang eq 'ja');
  70. # Override the distribution name if we are given a stamp.
  71. my $distname = defined $stamp && $stamp ne ''
  72. ? $stamp
  73. : $orig . '-' . $long_lang;
  74. print "---------------- Building $lang ----------------\n";
  75. verbose_command("$make clean"); # to clean MT.pm
  76. verbose_command($make);
  77. update_default_lang( $lang );
  78. make_manifest_skip($skip_rules, $skip);
  79. mkmanifest();
  80. # Copy files for non-GPL license since we will be modifying the content
  81. manicopy(maniread(), $distname, ( $license eq 'GPL' ? 'best' : 'cp' ));
  82. if (($license || '') ne 'GPL') {
  83. assign_license( $distname );
  84. }
  85. verbose_command("find $distname -name .exists | xargs rm");
  86. verbose_command("chmod +x $distname/*.cgi");
  87. verbose_command("chmod +x $distname/tools/*");
  88. my $options = $silent ? 'cf' : 'cvf';
  89. verbose_command("tar $options $distname.tar --wildcards --exclude '*.zip' $distname");
  90. $options = $silent ? '-q' : '';
  91. verbose_command("gzip $options --best $distname.tar");
  92. $options = $silent ? '-rq' : '-r';
  93. verbose_command("zip $options $distname.zip $distname -x $distname/extras/\*.gz");
  94. verbose_command("rm -rf $distname");
  95. unlink("MANIFEST");
  96. }
  97. END {
  98. move($skip_bak, $skip) if -e $skip_bak;
  99. }
  100. sub assign_license {
  101. my ($dir) = @_;
  102. find( { wanted => \&process_file_for_license, no_chdir => 1 },
  103. $dir );
  104. }
  105. sub process_file_for_license {
  106. my $file = $_;
  107. # skip any '.git', '.svn' directory
  108. return if $file =~ m! / \. !x;
  109. # must be a file, not a directory
  110. return unless -f $file;
  111. # must have a source file extension or be a utility script (extensionless)
  112. return unless $file =~ m! / ( [A-Za-z0-9_.-]+ \. ( pl | php | pm | cgi | js | t ) | [a-z0-9_-] + ) $ !x;
  113. my $content;
  114. open FIN, "<$file";
  115. {
  116. local $/;
  117. $content = <FIN>;
  118. }
  119. close FIN;
  120. my $open = quotemeta('# Movable Type (r) Open Source (C)');
  121. # skip file if it doesn't contain the Open Source license
  122. return unless $content =~ m/$open/;
  123. my $close = quotemeta('# GNU General Public License, version 2.');
  124. # non-distributable license text
  125. my $license = <<EOT;
  126. # This code cannot be redistributed without permission from www.sixapart.com.
  127. # For more information, consult your Movable Type license.
  128. EOT
  129. chomp($license);
  130. if ($content =~ s{$open (\d+(-\d+)?).*?$close}
  131. { '# Movable Type (r) (C) ' . $1 . ' Six Apart, Ltd. All Rights Reserved.' . $license }se) {
  132. ## print "applying license changes to $file...\n"; return;
  133. open FOUT, ">$file";
  134. print FOUT $content;
  135. close FOUT;
  136. }
  137. }
  138. sub make_manifest_skip {
  139. my ($rules, $file) = @_;
  140. my @rules = split /\n/, $rules;
  141. my @result;
  142. foreach my $rule (@rules) {
  143. if ($rule =~ m/^#\?([^=]+)=([^ ]+) +(.+)$/) {
  144. # a conditional rule
  145. my $var = $1;
  146. my $val = $2;
  147. my $skip = $3;
  148. if (($options{$var} || '') eq $val) {
  149. push @result, $skip;
  150. }
  151. }
  152. push @result, $rule;
  153. }
  154. my $result = join "\n", @result;
  155. local *FOUT;
  156. open *FOUT, ">$file";
  157. print FOUT $result;
  158. close FOUT;
  159. }
  160. sub verbose_command {
  161. my $command = shift;
  162. print 'Execute:', " $command" unless $silent;
  163. system $command;
  164. if( $? == -1 ) {
  165. die "ERROR: Failed to execute: $!";
  166. }
  167. elsif( $? & 127 ) {
  168. die sprintf( "ERROR: Child died with signal %d, with%s coredump\n",
  169. ( $? & 127 ), ( $? & 128 ? '' : 'out' )
  170. );
  171. }
  172. else {
  173. # printf "Child exited with value %d\n", $? >> 8;
  174. }
  175. return $command;
  176. }
  177. sub update_default_lang {
  178. my $lang = shift;
  179. my $config;
  180. open FH, "<mt-config.cgi-original";
  181. {
  182. local $/;
  183. $config = <FH>;
  184. }
  185. close FH;
  186. $config =~ s/(DefaultLanguage ).*/$1$lang/;
  187. open FH, ">mt-config.cgi-original";
  188. print FH $config;
  189. close FH;
  190. }