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