Commit | Line | Data |
---|---|---|
46c573de | 1 | #!/usr/bin/env perl |
525c441c | 2 | # Copyright (c) The Exim Maintainers 2016-2018 |
3634fc25 | 3 | |
8a483da6 NM |
4 | use strict; |
5 | use warnings; | |
6 | use Carp; | |
525c441c HSHR |
7 | use Cwd qw'abs_path'; |
8 | use File::Basename; | |
9 | use File::Path qw(make_path remove_tree); | |
8f29c950 | 10 | use File::Temp; |
8a483da6 | 11 | use Getopt::Long; |
ba41f854 | 12 | use IO::File; |
8a483da6 | 13 | use Pod::Usage; |
162e16b1 | 14 | use Digest::SHA; |
525c441c HSHR |
15 | use if $ENV{DEBUG} => 'Smart::Comments'; |
16 | ||
17 | my $ME = basename $0; | |
18 | ||
8a483da6 | 19 | |
cbae9e74 | 20 | my $debug = undef; |
8a483da6 NM |
21 | my $verbose = 0; |
22 | ||
525c441c HSHR |
23 | # MAJOR.MINOR[.SECURITY[.FIXES]][-RCX] |
24 | # 4 .90 .0 .22 -RC1 | |
25 | my $version_pattern = qr/ | |
26 | (?<release> | |
cbae9e74 | 27 | (?<target_release> |
525c441c HSHR |
28 | (?<major>\d) # 4 |
29 | \.(?<minor>\d\d) # .90 | |
30 | (?:\.(?<security>\d+) # .0 | |
31 | (?:\.(?<fixes>)\d+)?)? # .22 | |
cbae9e74 | 32 | ) # target-release ->| |
525c441c HSHR |
33 | (?:-(?<rc>RC\d+)?)? # -RC1 |
34 | ) | |
35 | /x; | |
8a483da6 | 36 | |
cbae9e74 HSHR |
37 | my $quick_version_pattern = qr/ |
38 | (?<release> | |
39 | (?<last_tag> | |
40 | (?<major>\d) # 4 | |
41 | \.(?<minor>\d\d) # .90 | |
42 | (?:\.(?<security>\d+) # .0 | |
43 | (?:\.(?<fixes>)\d+)?)? # .22 | |
44 | ) # last-tag ->| | |
45 | (?:-(?<quick>\d+-g[[:xdigit:]]+))? # -3-gdeadbef | |
46 | ) | |
47 | /x; | |
48 | ||
525c441c | 49 | # ------------------------------------------------------------------ |
8a483da6 | 50 | |
525c441c HSHR |
51 | package Context { |
52 | use strict; # not strictly necessary yet, until in an own package | |
53 | use warnings; # not strictly necessary yet, ... | |
54 | use File::Spec::Functions qw'splitpath catfile catdir splitdir'; | |
55 | use File::Path qw'make_path remove_tree'; | |
56 | use File::Copy; | |
57 | use Cwd qw'abs_path'; | |
58 | use Carp; | |
59 | ||
60 | package PWD { | |
61 | use Cwd; | |
62 | sub TIESCALAR { bless do {\my $x} } | |
63 | sub FETCH { cwd } | |
8a483da6 | 64 | } |
be914e6c | 65 | |
cbae9e74 | 66 | tie my $cwd => 'PWD' or die; # this returns the current dir now, dynamically |
8a483da6 | 67 | |
525c441c HSHR |
68 | sub new { |
69 | my $class = shift; | |
70 | return bless { @_ } => $class; | |
71 | } | |
8a483da6 | 72 | |
525c441c HSHR |
73 | sub check_version { |
74 | my $context = shift; | |
cbae9e74 HSHR |
75 | my $version = shift // 'HEAD'; |
76 | ||
77 | # | |
78 | # v => { | |
79 | # release => 4.92-RC4 | 4.92-27-gabcdef | |
80 | # target_release|last_tag => 4.92 | 4.92 | |
81 | # | |
82 | # major => 4 | |
83 | # minor => 92 | |
84 | # security => | |
85 | # fixes => | |
86 | # | |
87 | # rc|quick => RC4 | 27-gabcdef | |
88 | # } | |
89 | ||
90 | if ($context->{quick}) { | |
91 | # Try to find suitable version description | |
92 | chomp(my $describe = do { # we wrap it into a open() to avoid hassle with | |
93 | open(my $fh, '-|', # strange version descriptions | |
94 | 'git', describe => $version) or die; | |
95 | <$fh> | |
96 | } // exit 1); | |
97 | $describe =~ /$quick_version_pattern/; | |
98 | ||
99 | %{$context->{v}} = %+; | |
100 | ($context->{commit}) = $version // ($context->{v}{quick} =~ /g([[:xdigit:]]+)/); | |
101 | } | |
102 | else { | |
103 | croak "The given version number does not look right - $version" | |
104 | if not $version =~ /$version_pattern/; | |
105 | %{$context->{v}} = %+; | |
106 | ||
107 | # find a valid vcs tag matching the version | |
108 | my $pattern = "$context->{pkgname}-$context->{v}{release}" =~ s/[-_.]/[-_.]/gr; | |
109 | chomp(my @tags = qx{git tag --list '$pattern'}); | |
8a483da6 | 110 | |
cbae9e74 HSHR |
111 | croak "The given version is ambigous, tags: @tags\n" if @tags > 1; |
112 | croak "The given version does not exist (no such tag: exim-$version)\n" if @tags == 0; | |
8a483da6 | 113 | |
cbae9e74 HSHR |
114 | $context->{commit} = $tags[0]; |
115 | # target_release: the release we aim to reach with release candidates | |
116 | # FIXME: re-construct from the parsed version number | |
117 | } | |
8a483da6 | 118 | |
b315e9a9 HSHR |
119 | die "$ME: This script doesn't work for versions prior 4.92-RCx. " |
120 | ."Please checkout an older version.\n" | |
aa672401 HSHR |
121 | if $context->{v}{major} < 4 |
122 | or $context->{v}{major} == 4 && $context->{v}{minor} < 92; | |
123 | ||
525c441c | 124 | ### v: $context->{v} |
8a483da6 | 125 | |
46c573de | 126 | } |
8a483da6 | 127 | |
8a483da6 | 128 | |
525c441c HSHR |
129 | # We prefer gtar to tar if gtar exists in $PATH |
130 | sub override_tar_cmd { | |
131 | my $context = shift; | |
132 | my $tar = $context->{tar_cmd}; | |
8a483da6 | 133 | |
525c441c | 134 | return unless $tar eq 'tar'; |
8a483da6 | 135 | |
525c441c HSHR |
136 | foreach my $d (File::Spec->path()) { |
137 | my $p = catfile($d, 'gtar'); | |
138 | if (-x $p) { | |
139 | $context->{tar_cmd} = $p; | |
140 | print "Switched tar command to: $p\n" if $verbose; | |
141 | return; | |
142 | } | |
143 | } | |
144 | } | |
8a483da6 | 145 | |
525c441c HSHR |
146 | sub prepare_working_directory { |
147 | my $context = shift; | |
148 | my $workspace = $context->{workspace}; | |
8f29c950 | 149 | |
525c441c HSHR |
150 | if (not defined $workspace) { |
151 | $workspace = $context->{workspace} = File::Temp->newdir(File::Spec->tmpdir . '/exim-packaging-XXXX'); | |
152 | } | |
153 | else { | |
154 | # ensure the working directory is not in place | |
155 | if (-e $workspace) { | |
156 | if ($context->{delete}) { | |
157 | print "Deleting existing $workspace\n" if $verbose; | |
158 | remove_tree $workspace, { verbose => $verbose || $debug }; | |
159 | } | |
160 | else { | |
161 | croak "Working directory $workspace exists" if -e $workspace; | |
162 | } | |
163 | } | |
164 | ||
165 | # create base directory | |
166 | make_path( $context->{directory}, { verbose => $verbose || $debug } ); | |
167 | } | |
8f29c950 | 168 | |
525c441c HSHR |
169 | # Set(!) and create subdirectories |
170 | foreach (qw(vcs_export pkg_tars pkg_trees tmp)) { # {dookbook} | |
171 | make_path( | |
172 | $context->{d}{$_} = catdir($workspace, $_), | |
173 | { verbose => $verbose || $debug }); | |
174 | } | |
175 | } | |
8f29c950 | 176 | |
525c441c HSHR |
177 | sub export_git_tree { |
178 | my $context = shift; | |
179 | ||
180 | # build git command | |
181 | my $archive_file = $context->{tmp_archive_file} = sprintf'%s/%s-%s.tar', $context->{d}{tmp}, $context->{pkgname}, $context->{v}{release}; | |
182 | ### $archive_file | |
cbae9e74 | 183 | my @cmd = ( 'git', 'archive', '--format=tar', "--output=$archive_file", $context->{commit} ); |
525c441c HSHR |
184 | ### @cmd |
185 | # run git command | |
186 | print "[$cwd] Running: @cmd\n" if $verbose; | |
187 | 0 == system @cmd or croak "Export failed"; | |
188 | } | |
8f29c950 | 189 | |
525c441c HSHR |
190 | sub unpack_tree { |
191 | # TODO: Why can't we combine the export_git_tree with the | |
192 | # unpack_tree function? | |
193 | my $context = shift; | |
ba41f854 | 194 | |
525c441c HSHR |
195 | ### $context |
196 | die "Cannot see archive file\n" unless -f $context->{tmp_archive_file}; | |
197 | my @cmd = ('tar', | |
198 | xf => $context->{tmp_archive_file}, | |
199 | -C => $context->{d}{vcs_export} ); | |
5901f0ab | 200 | |
525c441c HSHR |
201 | # run command |
202 | print "[$cwd] Running: @cmd\n" if $verbose; | |
203 | system @cmd and croak "Unpack failed\n"; | |
5901f0ab | 204 | |
ba41f854 PP |
205 | } |
206 | ||
525c441c HSHR |
207 | sub make_version_script { |
208 | my $context = shift; | |
209 | ||
210 | #my $variant = substr( $context->{v}{release}, length($context->{v}{target_release}) ); | |
211 | #if ( $context->{v}{release} ne $context->{v}{target_release} . $variant ) { | |
212 | # die "Broken version numbering, I'm buggy"; | |
213 | #} | |
214 | ||
215 | ||
216 | # Work | |
217 | if (not my $pid = fork // die "$ME: Cannot fork: $!\n") { | |
218 | ||
219 | my $source_tree = catdir($context->{d}{vcs_export}, 'src', 'src'); | |
220 | ### $source_tree | |
221 | ||
222 | chdir $source_tree or die "chdir $source_tree: $!\n"; | |
223 | ||
525c441c HSHR |
224 | croak "WARNING: version.sh already exists - leaving it in place\n" |
225 | if -f 'version.sh'; | |
226 | ||
227 | # Currently (25. Feb. 2016) the mk_exim_release.pl up to now can't | |
228 | # deal with security releases.!? So we need a current | |
229 | # mk_exim_release.pl. But if we use a current (master), the | |
230 | # reversion script returns wrong version info (it's running inside | |
231 | # the Git tree and uses git --describe, which always returns the | |
232 | # current version of master.) I do not want to change the old | |
233 | # reversion scripts (in 4.86.1, 4.85.1). | |
234 | # | |
235 | # Thus we've to provide the version.sh, based on the info we have | |
236 | # about the release. If reversion finds this, it doesn't try to find | |
237 | # it's own way to get a valid version number from the git. | |
238 | # | |
239 | # 4.89 series: the logic here did not handle _RC<N> thus breaking RC | |
240 | # status in versions. nb: rc in context should be same as $variant | |
241 | # in local context. | |
242 | ||
243 | #my $stamp = $context->{minor} ? '_'.$context->{minor} : ''; | |
244 | #$stamp .= $context->{rc} if $context->{rc}; | |
cbae9e74 HSHR |
245 | my $release = $context->{v}{rc} ? $context->{v}{target_release} |
246 | : $context->{v}{last_tag}; | |
247 | ||
248 | my $variant = | |
249 | $context->{v}{rc} ? $context->{v}{rc} | |
250 | : $context->{v}{quick} ? $context->{v}{quick} | |
251 | : ''; | |
525c441c HSHR |
252 | |
253 | print "[$cwd] create version.sh\n" if $verbose; | |
254 | open(my $v, '>', 'version.sh') or die "Can't open version.sh for writing: $!\n"; | |
255 | print {$v} <<__; | |
256 | # initial version automatically generated by $0 | |
cbae9e74 | 257 | EXIM_RELEASE_VERSION=$release |
525c441c | 258 | EXIM_VARIANT_VERSION=$variant |
9677df8a | 259 | EXIM_COMPILE_NUMBER=0 |
525c441c | 260 | # echo "[[[ \$EXIM_RELEASE_VERSION | \$EXIM_VARIANT_VERSION | \$EXIM_COMPILE_NUMBER ]]]" |
9677df8a | 261 | __ |
525c441c HSHR |
262 | close $v or die "$0: Can not close $source_tree/version.h: $!\n"; |
263 | unlink 'version.h' or die "$ME: Can not unlink $source_tree/version.h: $!\n" | |
264 | if -f 'version.h'; | |
9677df8a | 265 | |
525c441c HSHR |
266 | # Later, if we get the reversion script fixed, we can call it again. |
267 | # For now (25. Feb. 2016) we'll leave it unused. | |
cbae9e74 | 268 | #my @cmd = ('../scripts/reversion', 'release', $context->{commit}); |
5901f0ab | 269 | |
525c441c HSHR |
270 | my @cmd = ('../scripts/reversion', 'release'); |
271 | print "[$cwd] Running: @cmd\n" if $verbose; | |
272 | system(@cmd) and croak "reversion failed"; | |
ba41f854 | 273 | |
525c441c HSHR |
274 | die "$ME: failed to create version.sh" |
275 | unless -f 'version.sh'; | |
ba41f854 | 276 | |
525c441c HSHR |
277 | exit 0; |
278 | } | |
279 | else { | |
280 | $pid == waitpid($pid, 0) or die "$0: waidpid: $!\n"; | |
281 | exit $? >> 8 if $?; | |
282 | } | |
283 | } | |
ba41f854 | 284 | |
525c441c HSHR |
285 | sub build_documentation { |
286 | my $context = shift; | |
287 | my $docdir = catdir $context->{d}{vcs_export}, 'doc', 'doc-docbook'; | |
288 | ||
289 | # documentation building does a chdir, so we'll do it in a | |
290 | # subprocess | |
291 | if (not my $pid = fork // die "$ME: Can't fork: $!\n") { | |
292 | chdir $docdir or die "$ME: Can't chdir to $docdir: $!\n"; | |
293 | system('./OS-Fixups') == 0 or exit $?; | |
294 | exec $context->{make_cmd}, | |
295 | "EXIM_VER=$context->{v}{target_release}" . | |
cbae9e74 HSHR |
296 | ($context->{v}{rc} ? "-$context->{v}{rc}" |
297 | : $context->{v}{quick} ? "-$context->{v}{quick}" | |
298 | : ''), | |
525c441c HSHR |
299 | 'everything'; |
300 | die "$ME: [$cwd] Cannot exec $context->{make_cmd}: $!\n"; | |
301 | } | |
302 | else { | |
303 | waitpid($pid, 0); | |
304 | exit $? >> 8 if $?; | |
305 | } | |
be914e6c | 306 | |
525c441c | 307 | $context->copy_docbook_files; |
525c441c | 308 | } |
46c573de | 309 | |
525c441c HSHR |
310 | sub copy_docbook_files { |
311 | my $context = shift; | |
be914e6c | 312 | |
525c441c HSHR |
313 | # where the generated docbook files can be found |
314 | my $docdir = catdir $context->{d}{vcs_export}, 'doc', 'doc-docbook'; | |
be914e6c | 315 | |
525c441c HSHR |
316 | foreach ('spec.xml', 'filter.xml') { |
317 | my $from = catfile $docdir, $_; | |
318 | my $to = catdir $context->{d}{tmp}; # {dookbook} | |
319 | copy $from => $to or die $@; | |
320 | } | |
321 | } | |
be914e6c | 322 | |
525c441c HSHR |
323 | sub build_html_documentation { |
324 | my $context = shift; | |
46c573de | 325 | |
525c441c HSHR |
326 | # where the website docbook source dir is - push the generated |
327 | # files there | |
328 | { | |
329 | my $webdir = catdir $context->{website_base}, 'docbook', $context->{v}{target_release}; | |
cbae9e74 | 330 | make_path $webdir, { verbose => $verbose || $debug }; |
525c441c HSHR |
331 | copy catfile($context->{d}{vcs_export}, 'doc', 'doc-docbook', $_) |
332 | => $webdir or die $@ | |
333 | for 'spec.xml', 'filter.xml'; | |
334 | } | |
46c573de | 335 | |
525c441c HSHR |
336 | my $gen = catfile $context->{website_base}, 'script/gen'; |
337 | my $outdir = catdir $context->{d}{pkg_trees}, "exim-html-$context->{v}{release}"; | |
46c573de | 338 | |
525c441c | 339 | make_path $outdir, { verbose => $verbose || $debug }; |
46c573de | 340 | |
525c441c HSHR |
341 | my @cmd = ( |
342 | $gen, | |
343 | '--spec' => catfile($context->{d}{tmp}, 'spec.xml'), # {dookbook} | |
344 | '--filter' => catfile($context->{d}{tmp}, 'filter.xml'), # {dookbok} | |
345 | '--latest' => $context->{v}{target_release}, | |
346 | '--docroot' => $outdir, | |
347 | '--localstatic', | |
348 | ($verbose || $debug ? '--verbose' : ()), | |
349 | ); | |
46c573de | 350 | |
525c441c HSHR |
351 | print "[$cwd] Executing @cmd\n"; |
352 | 0 == system @cmd or exit $? >> 8; | |
46c573de | 353 | |
46c573de | 354 | } |
be914e6c | 355 | |
162e16b1 HSHR |
356 | sub sign { |
357 | my $context = shift; | |
358 | foreach my $tar (glob "$context->{d}{pkg_tars}/*") { | |
359 | system gpg => | |
360 | '--quiet', '--batch', | |
361 | defined $context->{gpg}{key} | |
362 | ? ('--local-user' => $context->{gpg}{key}) | |
363 | : (), | |
364 | '--detach-sig', '--armor', $tar; | |
365 | } | |
366 | } | |
367 | ||
525c441c HSHR |
368 | sub move_to_outdir { |
369 | my $context = shift; | |
370 | make_path $context->{OUTDIR}, { verbose => $verbose || $debug }; | |
371 | move $_ => $context->{OUTDIR} or die $@ | |
372 | for glob "$context->{d}{pkg_tars}/*"; | |
373 | } | |
8a483da6 | 374 | |
525c441c HSHR |
375 | sub build_src_package_directory { |
376 | my $context = shift; | |
8a483da6 | 377 | |
525c441c HSHR |
378 | # build the exim package directory path |
379 | $context->{d}{src} = catdir $context->{d}{pkg_trees}, "exim-$context->{v}{release}"; | |
8a483da6 | 380 | |
525c441c HSHR |
381 | # initially we move the exim-src directory to the new directory name |
382 | move | |
383 | catdir( $context->{d}{vcs_export}, 'src') | |
384 | => $context->{d}{src} | |
385 | or croak "Move of src dir failed - $!"; | |
8a483da6 | 386 | |
525c441c HSHR |
387 | # add Local subdirectory |
388 | make_path( catdir( $context->{d}{src}, 'Local' ), { verbose => $verbose || $debug } ); | |
8a483da6 | 389 | |
525c441c HSHR |
390 | # now add the text docs |
391 | $context->move_text_docs_into_pkg; | |
8a483da6 | 392 | } |
8a483da6 | 393 | |
525c441c HSHR |
394 | sub build_doc_packages_directory { |
395 | my $context = shift; | |
396 | ||
397 | ##foreach my $format (qw/pdf postscript texinfo info/) { | |
398 | foreach my $format (qw/pdf postscript/) { | |
399 | my $target = catdir $context->{d}{pkg_trees}, "exim-$format-$context->{v}{release}", 'doc'; | |
400 | make_path( $target, { verbose => $verbose || $debug } ); | |
401 | ||
402 | # move documents across | |
403 | foreach my $file ( | |
404 | glob( | |
405 | catfile( | |
406 | $context->{d}{vcs_export}, | |
407 | 'doc', | |
408 | 'doc-docbook', | |
409 | ( | |
410 | ( $format eq 'postscript' ) | |
411 | ? '*.ps' | |
412 | : ( '*.' . $format ) | |
413 | ) | |
8a483da6 NM |
414 | ) |
415 | ) | |
416 | ) | |
525c441c HSHR |
417 | { |
418 | move( $file, catfile( $target, ( splitpath($file) )[2] ) ); | |
419 | } | |
8a483da6 NM |
420 | } |
421 | } | |
46c573de | 422 | |
525c441c HSHR |
423 | sub move_text_docs_into_pkg { |
424 | my $context = shift; | |
9d0311ff | 425 | |
525c441c HSHR |
426 | my $old_docdir = catdir( $context->{d}{vcs_export}, 'doc', 'doc-docbook' ); |
427 | my $old_txtdir = catdir( $context->{d}{vcs_export}, 'doc', 'doc-txt' ); | |
428 | my $new_docdir = catdir( $context->{d}{src}, 'doc' ); | |
429 | make_path( $new_docdir, { verbose => $verbose || $debug } ); | |
9d0311ff | 430 | |
525c441c HSHR |
431 | # move generated documents from docbook stuff |
432 | foreach my $file (qw/exim.8 spec.txt filter.txt/) { | |
433 | die "Empty file \"$file\"\n" if -z catfile( $old_docdir, $file ); | |
434 | move( catfile( $old_docdir, $file ), catfile( $new_docdir, $file ) ); | |
435 | } | |
9d0311ff | 436 | |
525c441c HSHR |
437 | # move text documents across |
438 | foreach my $file ( glob( catfile( $old_txtdir, '*' ) ) ) { | |
439 | ||
440 | # skip a few we dont want | |
441 | my $fn = ( splitpath($file) )[2]; | |
442 | next | |
443 | if ( ( $fn eq 'ABOUT' ) | |
444 | || ( $fn eq 'ChangeLog.0' ) | |
445 | || ( $fn eq 'test-harness.txt' ) | |
446 | # Debian issue re licensing of RFCs | |
447 | || ( $fn =~ /^draft-ietf-.*/ ) | |
448 | || ( $fn =~ /^rfc.*/ ) | |
449 | ); | |
450 | move( $file, catfile( $new_docdir, $fn ) ); | |
9d0311ff PP |
451 | } |
452 | } | |
9d0311ff | 453 | |
525c441c HSHR |
454 | sub create_tar_files { |
455 | my $context = shift; | |
9d0311ff | 456 | |
525c441c HSHR |
457 | my $pkg_tars = $context->{d}{pkg_tars}; |
458 | my $pkg_trees = $context->{d}{pkg_trees}; | |
459 | my $tar = $context->{tar_cmd}; | |
460 | if ($verbose) { | |
461 | foreach my $c (keys %{ $context->{compressors} }) { | |
462 | print "Compression: $c\t$context->{compressors}{$c}\n"; | |
463 | } | |
464 | } | |
8a483da6 | 465 | |
525c441c HSHR |
466 | # We ideally do not want local system user information in release tarballs; |
467 | # those are artifacts of use of tar for backups and have no place in | |
468 | # software release packaging; if someone extracts as root, then they should | |
469 | # get sane file ownerships. | |
b315e9a9 HSHR |
470 | my @ownership = ( |
471 | '--owner' => $context->{tar_perms}{user}, | |
472 | '--group' => $context->{tar_perms}{group}, | |
525c441c | 473 | # on this GNU tar, --numeric-owner works during creation too |
b315e9a9 HSHR |
474 | '--numeric-owner' |
475 | ) if qx/tar --help 2>&1/ =~ /^\s*--owner=/m; | |
9d0311ff | 476 | |
525c441c | 477 | # See also environment variables set in main, tuning compression levels |
b315e9a9 HSHR |
478 | my %COMPRESSION = ( |
479 | gzip => { extension => 'gz', flags => '--gzip' }, | |
480 | bzip2 => { extension => 'bz2', flags => '--bzip2' }, | |
481 | lzip => { extension => 'lz', flags => '--lzip' }, | |
482 | xz => { extension => 'xz', flags => '--xz' }, | |
525c441c HSHR |
483 | ); |
484 | ||
b315e9a9 | 485 | |
162e16b1 | 486 | my (%size, %sha256); |
b315e9a9 | 487 | |
525c441c HSHR |
488 | foreach my $dir ( glob( catdir( $pkg_trees, ( 'exim*-' . $context->{v}{release} ) ) ) ) { |
489 | my $dirname = ( splitdir($dir) )[-1]; | |
b315e9a9 HSHR |
490 | foreach my $comp (keys %COMPRESSION) { |
491 | next unless $context->{compressors}{$comp}; | |
162e16b1 | 492 | |
b315e9a9 | 493 | my $basename = "$dirname.tar.$COMPRESSION{$comp}{extension}"; |
162e16b1 HSHR |
494 | my $outfile = catfile $pkg_tars, $basename; |
495 | ||
496 | print "Creating: $outfile\n" if $verbose || $debug; | |
b315e9a9 HSHR |
497 | 0 == system($tar, |
498 | cf => $outfile, | |
499 | $COMPRESSION{$comp}{flags}, | |
500 | @ownership, -C => $pkg_trees, $dirname) | |
525c441c | 501 | or exit $? >> 8; |
162e16b1 HSHR |
502 | |
503 | # calculate size and md5sum | |
504 | $size{$basename} = -s $outfile; | |
505 | $sha256{$basename} = do { | |
506 | my $sha = Digest::SHA->new(256); | |
507 | $sha->addfile($outfile); | |
508 | $sha->hexdigest; | |
509 | }; | |
525c441c HSHR |
510 | } |
511 | } | |
162e16b1 HSHR |
512 | |
513 | # write the sizes file | |
cbae9e74 HSHR |
514 | if ($context->{sizes}) { |
515 | open my $sizes, '>', $_ = catfile $pkg_tars, 'sizes.txt' | |
516 | or die "$ME: Can't open `$_': $!\n"; | |
b315e9a9 | 517 | |
cbae9e74 HSHR |
518 | print $sizes join "\n", |
519 | (map { "SIZE($_) = $size{$_}" } sort keys %size), | |
520 | (map { "SHA256($_) = $sha256{$_}" } sort keys %sha256); | |
b315e9a9 | 521 | |
cbae9e74 HSHR |
522 | close($sizes) or die "$ME: Can't close $_: $!\n"; |
523 | } | |
45b75b0a PP |
524 | } |
525 | ||
525c441c HSHR |
526 | sub do_cleanup { |
527 | my $context = shift; | |
00f7a87b | 528 | |
525c441c | 529 | print "Cleaning up\n" if $verbose; |
cbae9e74 | 530 | remove_tree $context->{d}{tmp}, { verbose => $verbose || $debug }; |
8a483da6 | 531 | } |
00f7a87b | 532 | |
8a483da6 NM |
533 | } |
534 | ||
91bde4a0 HSHR |
535 | MAIN: { |
536 | ||
525c441c HSHR |
537 | # some of these settings are useful only if we're in the |
538 | # exim-projekt-root, but the check, if we're, is deferred | |
539 | my $context = Context->new( | |
be914e6c | 540 | pkgname => 'exim', |
525c441c | 541 | website_base => abs_path('../exim-website'), |
9d0311ff | 542 | tar_cmd => 'tar', |
45b75b0a PP |
543 | tar_perms => { |
544 | user => '0', | |
545 | group => '0', | |
546 | }, | |
cbae9e74 | 547 | make_cmd => 'make', # for 'make'ing the docs |
9d0311ff PP |
548 | compressors => { |
549 | gzip => 1, | |
550 | bzip2 => 1, | |
00f7a87b | 551 | xz => 1, |
e099cd0d | 552 | lzip => 0, |
9d0311ff | 553 | }, |
525c441c | 554 | docs => 1, |
2820726f | 555 | web => 1, |
525c441c HSHR |
556 | delete => 0, |
557 | cleanup => 1, | |
162e16b1 HSHR |
558 | gpg => { |
559 | sign => 1, | |
560 | key => undef, | |
561 | }, | |
cbae9e74 | 562 | quick => 0, |
525c441c HSHR |
563 | ); |
564 | ||
8f29c950 | 565 | ##$ENV{'PATH'} = '/opt/local/bin:' . $ENV{'PATH'}; |
00f7a87b | 566 | # We are creating files for mass distribution, so work harder to make smaller files. |
525c441c HSHR |
567 | $ENV{GZIP} = -9; |
568 | $ENV{BZIP2} = -9; | |
00f7a87b PP |
569 | # xz documents minimum file sizes for levels higher than -6 to be useful and each |
570 | # requires more RAM on the decompressing system. Exim tarball currently 24MiB so | |
571 | # using -8. | |
525c441c | 572 | $ENV{XZ_DEFAULTS} = -8; |
8a483da6 | 573 | |
91bde4a0 | 574 | GetOptions( |
525c441c | 575 | $context, |
cbae9e74 HSHR |
576 | qw(workspace|tmp=s website_base|webgen_base=s tar_cmd|tar-cmd=s make_cmd|make-cmd=s |
577 | docs|build-docs! web|build-web! | |
578 | delete! cleanup! quick|quick-release! minimal), | |
162e16b1 HSHR |
579 | 'sign!' => \$context->{gpg}{sign}, |
580 | 'key=s' => \$context->{gpg}{key}, | |
91bde4a0 HSHR |
581 | 'lzip!' => \$context->{compressors}{lzip}, |
582 | 'verbose!' => \$verbose, | |
cbae9e74 HSHR |
583 | 'debug:s' => \$debug, |
584 | 'quick' => sub { $context->{web}--; $context->{quick} = 1 }, | |
91bde4a0 HSHR |
585 | 'help|?' => sub { pod2usage(-verbose => 1, -exit => 0) }, |
586 | 'man!' => sub { pod2usage(-verbose => 2, -exit => 0, -noperldoc => system('perldoc -V >/dev/null 2>&1')) }, | |
cbae9e74 HSHR |
587 | ) and (@ARGV == 2 or ($context->{quick} and @ARGV >= 1)) |
588 | or pod2usage; | |
525c441c | 589 | |
162e16b1 HSHR |
590 | -f '.exim-project-root' |
591 | or die "$ME: please call this script from the root of the Exim project sources\n"; | |
525c441c HSHR |
592 | |
593 | $context->{OUTDIR} = pop @ARGV; | |
594 | ||
162e16b1 HSHR |
595 | if ($context->{gpg}{sign}) { |
596 | $context->{gpg}{key} //= do { chomp($_ = qx/git config user.signingkey/); $_ } | |
597 | || $ENV{EXIM_KEY} | |
598 | || do { | |
599 | warn "$ME: No GPG key, using default\n"; | |
600 | undef; | |
601 | } | |
602 | } | |
603 | ||
525c441c HSHR |
604 | |
605 | warn "$ME: changed umask to 022\n" if umask(022) != 022; | |
606 | ||
cbae9e74 HSHR |
607 | $context->check_version(shift); # may be undef for a quick release |
608 | ||
609 | if ($debug//'' eq 'version') { | |
610 | for (sort keys %{$context->{v}}) { | |
611 | print "version $_: $context->{v}{$_}\n"; | |
612 | } | |
613 | print "git commit: $context->{commit}\n"; | |
614 | exit 0; | |
615 | } | |
525c441c HSHR |
616 | $context->override_tar_cmd; |
617 | $context->prepare_working_directory; | |
618 | $context->export_git_tree; | |
619 | $context->unpack_tree; | |
620 | $context->make_version_script; | |
cbae9e74 | 621 | |
525c441c | 622 | $context->build_documentation if $context->{docs}; |
51420ec3 | 623 | $context->build_html_documentation if $context->{docs} && $context->{web}; |
525c441c HSHR |
624 | |
625 | $context->build_src_package_directory; | |
626 | $context->build_doc_packages_directory if $context->{docs}; | |
627 | ||
628 | $context->create_tar_files; | |
162e16b1 | 629 | $context->sign if $context->{gpg}{sign}; |
525c441c HSHR |
630 | $context->move_to_outdir; |
631 | $context->do_cleanup if $context->{cleanup}; | |
632 | ||
633 | ### $context | |
8a483da6 NM |
634 | } |
635 | ||
636 | 1; | |
637 | ||
638 | __END__ | |
639 | ||
640 | =head1 NAME | |
641 | ||
6bfa380e | 642 | mk_exim_release - Build an exim release |
8a483da6 NM |
643 | |
644 | =head1 SYNOPSIS | |
645 | ||
525c441c | 646 | mk_exim_release [options] version PKG-DIRECTORY |
cbae9e74 | 647 | mk_exim_release [options] --quick [version] PKG-DIRECTORY |
91bde4a0 HSHR |
648 | |
649 | =head1 DESCRIPTION | |
650 | ||
651 | B<mk_exim_release> builds an exim release. | |
652 | ||
653 | Starting in a populated git repo that has already been tagged for | |
654 | release it builds docs, packages etc. Parameter is the version number | |
525c441c HSHR |
655 | to build as - ie 4.72 4.72-RC1, 4.86.1, etc, without any prefix. |
656 | ||
657 | This scripts expects to find a tag "exim-<version>". | |
91bde4a0 HSHR |
658 | |
659 | After creating the release files, they should be signed. There is another | |
660 | helper for creating the signatures: | |
661 | F<release-process/scripts/sign_exim_packages>. | |
662 | ||
663 | Call B<mk_exim_release> about like this: | |
664 | ||
525c441c | 665 | release-process/scripts/mk_exim_release 4.99 OUT-DIR |
8a483da6 | 666 | |
8a483da6 NM |
667 | |
668 | =head1 OPTIONS | |
669 | ||
670 | =over 4 | |
671 | ||
525c441c HSHR |
672 | =item B<--[no]cleanup> |
673 | ||
674 | Do (or do not) cleanup the tmp directory at exit (default: do cleanup) | |
675 | ||
cbae9e74 HSHR |
676 | =item B<--debug[=I<item>]> |
677 | ||
678 | Forces debug mode. If (default: no debug info) | |
679 | ||
680 | =over 4 | |
681 | ||
682 | =item item: B<version> | |
683 | ||
684 | Output the parsed/found version number and exit. | |
8a483da6 | 685 | |
cbae9e74 | 686 | =back |
8a483da6 | 687 | |
91bde4a0 | 688 | =item B<--[no]delete> |
9d0311ff | 689 | |
525c441c | 690 | Delete a pre-existing tmp- and package-directory at start. (default: don't delete) |
9d0311ff | 691 | |
cbae9e74 | 692 | =item B<--[no]doc> |
a7637438 | 693 | |
cbae9e74 | 694 | Do (not) build the documentation. This needs C<gnu-make> (default: build the docs) |
a7637438 | 695 | |
91bde4a0 | 696 | =item B<--[no]help> |
9d0311ff | 697 | |
91bde4a0 | 698 | Display short help and exit cleanly. (default: don't do that) |
9d0311ff | 699 | |
cbae9e74 HSHR |
700 | =item B<--key> I<GPG key> |
701 | ||
702 | Use this GPG key for signing. If nothing is specified the first one of this list | |
703 | is used: | |
704 | ||
705 | =over 8 | |
706 | ||
707 | =item - git config user.signingkey | |
708 | ||
709 | =item - environment C<EXIM_KEY> | |
710 | ||
711 | =item - default GPG key | |
712 | ||
713 | =back | |
714 | ||
91bde4a0 | 715 | =item B<--[no]lzip> |
8a483da6 | 716 | |
91bde4a0 | 717 | Control the creation of B<lzip> tarballs. (default: do not use lzip) |
8a483da6 | 718 | |
cbae9e74 | 719 | =item B<--make-cmd> I<cmd> |
8a483da6 | 720 | |
91bde4a0 | 721 | Force the use of a specific C<make> command. This may be necessary if C<make> is not |
cbae9e74 | 722 | C<gmake>. This is necessary to build the docs. (default: C<make>) |
8a483da6 | 723 | |
91bde4a0 | 724 | =item B<--[no]man> |
8a483da6 | 725 | |
91bde4a0 | 726 | Display man page and exit cleanly. (default: don't do that) |
8a483da6 | 727 | |
cbae9e74 | 728 | =item B<--quick> |
8a483da6 | 729 | |
cbae9e74 HSHR |
730 | Create a quick release. The I<version> mandatory argument needs to be a git commit-ish. |
731 | (try I<master> or I<HEAD> or similar). This mode switches off the | |
732 | website creation (which can be enabled by B<--web> again). | |
8a483da6 | 733 | |
162e16b1 HSHR |
734 | =item B<--[no]sign> |
735 | ||
736 | Sign the created archive files (and the sizes.txt). (default: sign) | |
737 | ||
cbae9e74 | 738 | =item B<--tar-cmd> I<cmd> |
162e16b1 | 739 | |
cbae9e74 HSHR |
740 | Use to override the path to the C<tar> command. Need GNU tar in case |
741 | I<lzip> is selected. (default: C<gtar>, if not found, use C<tar>) | |
162e16b1 | 742 | |
cbae9e74 | 743 | =item B<--tmpdir> I<dir> |
162e16b1 | 744 | |
cbae9e74 | 745 | Change the name of the tmp directory (default: temporary directory) |
162e16b1 | 746 | |
cbae9e74 | 747 | =item B<--verbose> |
162e16b1 | 748 | |
cbae9e74 | 749 | Force verbose mode. (default: no verbosity) |
162e16b1 | 750 | |
91bde4a0 | 751 | =item B<--[no]web> |
8a483da6 | 752 | |
91bde4a0 | 753 | Control the creation of the website. For creation of the website, the F<../exim-website> |
cbae9e74 HSHR |
754 | (but see the B<website-base> option) directory must exist. (default: create the website, except when |
755 | in B<quick> mode) | |
525c441c HSHR |
756 | |
757 | =item B<--website-base> I<dir> | |
758 | ||
759 | Base directory for the web site generation (default: F<../exim-website>) | |
8a483da6 | 760 | |
cbae9e74 | 761 | =item B<-workspace>|B<--tmp> I<directory> |
91bde4a0 | 762 | |
cbae9e74 HSHR |
763 | During release gerneration temporary storage is necessary. (default: F<exim-packaging-XXXX> |
764 | under your system's default temporary directory (typically this is F</tmp>)). | |
91bde4a0 HSHR |
765 | |
766 | =back | |
8a483da6 NM |
767 | |
768 | =head1 AUTHOR | |
769 | ||
91bde4a0 HSHR |
770 | Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>, |
771 | some changes by Heiko Schlittermann <hs@schlittermann.de> | |
8a483da6 NM |
772 | |
773 | =head1 COPYRIGHT | |
774 | ||
91bde4a0 | 775 | Copyright 2010-2016 Exim Maintainers. All rights reserved. |
8a483da6 NM |
776 | |
777 | =cut | |
9d0311ff | 778 | # vim: set sw=4 et : |