| 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | # A tool to build a perl release tarball |
| 4 | # Very basic but functional - if you're on a unix system. |
| 5 | # |
| 6 | # If you're on Win32 then it should still work, but various Unix command-line |
| 7 | # tools will need to be available somewhere. An obvious choice is to install |
| 8 | # Cygwin and ensure its 'bin' folder is on the PATH in the shell where you run |
| 9 | # this script. The Cygwin 'bin' folder needs to precede the Windows 'system32' |
| 10 | # folder so that Cygwin's 'find' command is found in preference to the Windows |
| 11 | # 'find' command. In addition to the commands installed by default, your Cygwin |
| 12 | # installation will need to contain at least the 'cpio' and '7z' commands. |
| 13 | # Finally, ensure that the 'awk', 'shasum' (if you have it) and '7z' commands |
| 14 | # are copies of 'gawk.exe', 'sha1sum.exe' and 'lib\p7zip\7z.exe' respectively, |
| 15 | # rather than the links to them that only work in a Cygwin bash shell which |
| 16 | # they are by default. |
| 17 | # |
| 18 | # No matter how automated this gets, you'll always need to read |
| 19 | # and re-read pumpkin.pod and release_managers_guide.pod to |
| 20 | # check for things to be done at various stages of the process. |
| 21 | # |
| 22 | # Tim Bunce, June 1997 |
| 23 | |
| 24 | use ExtUtils::Manifest qw(fullcheck); |
| 25 | $ExtUtils::Manifest::Quiet = 1; |
| 26 | use Getopt::Std; |
| 27 | |
| 28 | $|=1; |
| 29 | |
| 30 | sub usage { die <<EOF; } |
| 31 | usage: $0 [ -r rootdir ] [-s suffix ] [ -b ] [ -n ] |
| 32 | -r rootdir directory under which to create the build dir and tarball |
| 33 | defaults to '..' |
| 34 | -s suffix suffix to append to to the perl-x.y.z dir and tarball name |
| 35 | defaults to the concatenation of the local_patches entry |
| 36 | in patchlevel.h (or blank, if none) |
| 37 | -b make a .bz2 file in addtion to a .gz file |
| 38 | -n do not make any tarballs, just the directory |
| 39 | EOF |
| 40 | |
| 41 | my %opts; |
| 42 | getopts('bnr:s:', \%opts) or usage; |
| 43 | @ARGV && usage; |
| 44 | |
| 45 | $relroot = defined $opts{r} ? $opts{r} : ".."; |
| 46 | |
| 47 | die "Must be in root of the perl source tree.\n" |
| 48 | unless -f "./MANIFEST" and -f "patchlevel.h"; |
| 49 | |
| 50 | open PATCHLEVEL,"<patchlevel.h" or die; |
| 51 | my @patchlevel_h = <PATCHLEVEL>; |
| 52 | close PATCHLEVEL; |
| 53 | my $patchlevel_h = join "", grep { /^#\s*define/ } @patchlevel_h; |
| 54 | print $patchlevel_h; |
| 55 | $revision = $1 if $patchlevel_h =~ /PERL_REVISION\s+(\d+)/; |
| 56 | $patchlevel = $1 if $patchlevel_h =~ /PERL_VERSION\s+(\d+)/; |
| 57 | $subversion = $1 if $patchlevel_h =~ /PERL_SUBVERSION\s+(\d+)/; |
| 58 | die "Unable to parse patchlevel.h" unless $subversion >= 0; |
| 59 | $vers = sprintf("%d.%d.%d", $revision, $patchlevel, $subversion); |
| 60 | |
| 61 | # fetch list of local patches |
| 62 | my (@local_patches, @lpatch_tags, $lpatch_tags); |
| 63 | @local_patches = grep { !/^\s*,?NULL/ && ! /,"uncommitted-changes"/ } |
| 64 | grep { /^static.*local_patches/../^};/ } |
| 65 | @patchlevel_h; |
| 66 | @lpatch_tags = map { /^\s*,"(\w+)/ } @local_patches; |
| 67 | $lpatch_tags = join "-", @lpatch_tags; |
| 68 | |
| 69 | $perl = "perl-$vers"; |
| 70 | $reldir = "$perl"; |
| 71 | |
| 72 | $lpatch_tags = $opts{s} if defined $opts{s}; |
| 73 | $reldir .= "-$lpatch_tags" if $lpatch_tags; |
| 74 | |
| 75 | print "\nMaking a release for $perl in $relroot/$reldir\n\n"; |
| 76 | |
| 77 | print "Cross-checking the MANIFEST...\n"; |
| 78 | ($missfile, $missentry) = fullcheck(); |
| 79 | @$missentry |
| 80 | = grep {$_ !~ m!^\.git/! and $_ !~ m!(?:/|^)\.gitignore!} @$missentry; |
| 81 | if (@$missfile ) { |
| 82 | warn "Can't make a release with MANIFEST files missing:\n"; |
| 83 | warn "\t".$_."\n" for (@$missfile); |
| 84 | } |
| 85 | if (@$missentry ) { |
| 86 | warn "Can't make a release with files not listed in MANIFEST\n"; |
| 87 | warn "\t".$_."\n" for (@$missentry); |
| 88 | |
| 89 | } |
| 90 | if ("@$missentry" =~ m/\.orig\b/) { |
| 91 | # Handy listing of find command and .orig files from patching work. |
| 92 | # I tend to run 'xargs rm' and copy and paste the file list. |
| 93 | my $cmd = "find . -name '*.orig' -print"; |
| 94 | print "$cmd\n"; |
| 95 | system($cmd); |
| 96 | } |
| 97 | die "Aborted.\n" if @$missentry or @$missfile; |
| 98 | print "\n"; |
| 99 | |
| 100 | # VMS no longer has hardcoded version numbers descrip.mms |
| 101 | |
| 102 | print "Creating $relroot/$reldir release directory...\n"; |
| 103 | die "$relroot/$reldir release directory already exists\n" if -e "$relroot/$reldir"; |
| 104 | die "$relroot/$reldir.tar.gz release file already exists\n" if -e "$relroot/$reldir.tar.gz"; |
| 105 | mkdir("$relroot/$reldir", 0755) or die "mkdir $relroot/$reldir: $!\n"; |
| 106 | print "\n"; |
| 107 | |
| 108 | |
| 109 | print "Copying files to release directory...\n"; |
| 110 | # ExtUtils::Manifest maniread does not preserve the order |
| 111 | $cmd = "awk '{print \$1}' MANIFEST | cpio -pdm $relroot/$reldir"; |
| 112 | system($cmd) == 0 |
| 113 | or die "$cmd failed"; |
| 114 | print "\n"; |
| 115 | |
| 116 | chdir "$relroot/$reldir" or die $!; |
| 117 | |
| 118 | |
| 119 | print "Setting file permissions...\n"; |
| 120 | system("find . -type f -print | xargs chmod 0444"); |
| 121 | system("find . -type d -print | xargs chmod 0755"); |
| 122 | my @exe = map { my ($f) = split; glob($f) } |
| 123 | grep { $_ !~ /\A#/ && $_ !~ /\A\s*\z/ } |
| 124 | map { split "\n" } |
| 125 | do { local (@ARGV, $/) = 'Porting/exec-bit.txt'; <> }; |
| 126 | |
| 127 | system("chmod +x @exe") == 0 |
| 128 | or die "system: $!"; |
| 129 | |
| 130 | my @writables = qw( |
| 131 | NetWare/config_H.wc |
| 132 | NetWare/Makefile |
| 133 | feature.h |
| 134 | lib/feature.pm |
| 135 | keywords.h |
| 136 | keywords.c |
| 137 | opcode.h |
| 138 | opnames.h |
| 139 | pp_proto.h |
| 140 | proto.h |
| 141 | embed.h |
| 142 | embedvar.h |
| 143 | overload.c |
| 144 | overload.h |
| 145 | mg_vtable.h |
| 146 | perlapi.h |
| 147 | perlapi.c |
| 148 | cpan/Devel-PPPort/module2.c |
| 149 | cpan/Devel-PPPort/module3.c |
| 150 | reentr.c |
| 151 | reentr.h |
| 152 | regcharclass.h |
| 153 | regnodes.h |
| 154 | warnings.h |
| 155 | lib/warnings.pm |
| 156 | win32/Makefile |
| 157 | win32/Makefile.ce |
| 158 | win32/makefile.mk |
| 159 | win32/config_H.ce |
| 160 | win32/config_H.gc |
| 161 | win32/config_H.vc |
| 162 | utils/Makefile |
| 163 | uconfig.h |
| 164 | ); |
| 165 | system("chmod u+w @writables") == 0 |
| 166 | or die "system: $!"; |
| 167 | |
| 168 | chdir ".." or die $!; |
| 169 | |
| 170 | exit if $opts{n}; |
| 171 | |
| 172 | my $src = (-e $perl) ? $perl : 'perl'; # 'perl' in maint branch |
| 173 | |
| 174 | print "Checking if you have 7z...\n"; |
| 175 | my $output_7z = `7z 2>&1`; |
| 176 | my $have_7z = defined $output_7z && $output_7z =~ /7-Zip/; |
| 177 | |
| 178 | print "Checking if you have advdef...\n"; |
| 179 | my $output_advdef = `advdef --version 2>&1`; |
| 180 | my $have_advdef = defined $output_advdef && $output_advdef =~ /advancecomp/; |
| 181 | |
| 182 | if ($have_7z) { |
| 183 | print "Creating and compressing the tar.gz file with 7z...\n"; |
| 184 | $cmd = "tar cf - $reldir | 7z a -tgzip -mx9 -bd -si $reldir.tar.gz"; |
| 185 | system($cmd) == 0 or die "$cmd failed"; |
| 186 | } else { |
| 187 | print "Creating and compressing the tar.gz file...\n"; |
| 188 | $cmd = "tar cf - $reldir | gzip --best > $reldir.tar.gz"; |
| 189 | system($cmd) == 0 or die "$cmd failed"; |
| 190 | if ($have_advdef) { |
| 191 | print "Recompressing the tar.gz file with advdef...\n"; |
| 192 | $cmd = "advdef -z -4 $reldir.tar.gz"; |
| 193 | system($cmd) == 0 or die "$cmd failed"; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if ($opts{b}) { |
| 198 | if ($have_7z) { |
| 199 | print "Creating and compressing the tar.bz2 file with 7z...\n"; |
| 200 | $cmd = "tar cf - $reldir | 7z a -tbzip2 -mx9 -bd -si $reldir.tar.bz2"; |
| 201 | system($cmd) == 0 or die "$cmd failed"; |
| 202 | } else { |
| 203 | print "Creating and compressing the tar.bz2 file...\n"; |
| 204 | $cmd = "tar cf - $reldir | bzip2 > $reldir.tar.bz2"; |
| 205 | system($cmd) == 0 or die "$cmd failed"; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | print "\n"; |
| 210 | |
| 211 | system("ls -ld $perl*"); |
| 212 | print "\n"; |
| 213 | |
| 214 | my $null = $^O eq 'MSWin32' ? 'NUL' : '/dev/null'; |
| 215 | for my $sha (qw(sha1 shasum sha1sum)) { |
| 216 | if (`which $sha 2>$null`) { |
| 217 | system("$sha $perl*.tar.*"); |
| 218 | last; |
| 219 | } |
| 220 | } |