Package: strip-nondeterminism Version: 0.003-1 Severity: wishlist Tags: patch
The attached aims to fix: https://reproducible.debian.net/issues/timestamps_generated_by_docbook_to_man_issue.html This should make an additional ~115 packages build reproducibly. Patch attached (against git HEAD, not 0.003-1). Regards, -- ,''`. : :' : Chris Lamb `. `'` [email protected] / chris-lamb.co.uk `-
From 428716ce728c29c9c320959e301926976fa67b31 Mon Sep 17 00:00:00 2001 From: Chris Lamb <[email protected]> Date: Sat, 24 Jan 2015 12:21:25 +0000 Subject: [PATCH] Replace generated times in files generated by docbook-to-man. Signed-off-by: Chris Lamb <[email protected]> --- lib/File/StripNondeterminism.pm | 6 +++ .../StripNondeterminism/handlers/docbooktoman.pm | 59 ++++++++++++++++++++++ t/docbooktoman.t | 51 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 lib/File/StripNondeterminism/handlers/docbooktoman.pm create mode 100644 t/docbooktoman.t diff --git a/lib/File/StripNondeterminism.pm b/lib/File/StripNondeterminism.pm index e6dd1ab..5738cf1 100644 --- a/lib/File/StripNondeterminism.pm +++ b/lib/File/StripNondeterminism.pm @@ -22,6 +22,7 @@ use strict; use warnings; use File::StripNondeterminism::handlers::ar; +use File::StripNondeterminism::handlers::docbooktoman; use File::StripNondeterminism::handlers::gzip; use File::StripNondeterminism::handlers::jar; use File::StripNondeterminism::handlers::javadoc; @@ -52,6 +53,10 @@ sub get_normalizer_for_file { if (m/\.a$/ && _get_file_type($_) =~ m/ar archive/) { return \&File::StripNondeterminism::handlers::ar::normalize; } + # docbook-to-man + if (m/\.\d$/ && _get_file_type($_) =~ m/troff/) { + return \&File::StripNondeterminism::handlers::docbooktoman::normalize; + } # gzip if (m/\.(gz|dz)$/ && _get_file_type($_) =~ m/gzip compressed data/) { return \&File::StripNondeterminism::handlers::gzip::normalize; @@ -82,6 +87,7 @@ sub get_normalizer_for_file { sub get_normalizer_by_name { $_ = shift; return \&File::StripNondeterminism::handlers::ar::normalize if $_ eq 'ar'; + return \&File::StripNondeterminism::handlers::docbooktoman::normalize if $_ eq 'docbooktoman'; return \&File::StripNondeterminism::handlers::gzip::normalize if $_ eq 'gzip'; return \&File::StripNondeterminism::handlers::jar::normalize if $_ eq 'jar'; return \&File::StripNondeterminism::handlers::javadoc::normalize if $_ eq 'javadoc'; diff --git a/lib/File/StripNondeterminism/handlers/docbooktoman.pm b/lib/File/StripNondeterminism/handlers/docbooktoman.pm new file mode 100644 index 0000000..2760409 --- /dev/null +++ b/lib/File/StripNondeterminism/handlers/docbooktoman.pm @@ -0,0 +1,59 @@ +# +# Copyright 2015 Chris Lamb <[email protected]> +# +# This file is part of strip-nondeterminism. +# +# strip-nondeterminism is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# strip-nondeterminism is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with strip-nondeterminism. If not, see <http://www.gnu.org/licenses/>. +# +package File::StripNondeterminism::handlers::docbooktoman; + +use strict; +use warnings; + +use File::Temp; +use File::Basename; +use POSIX qw( strftime ); + +sub normalize { + my ($filename) = @_; + + open(my $fh, '<', $filename) + or die "Unable to open $filename for reading: $!"; + + my $modified = 0; + my $tempfile = File::Temp->new(DIR => dirname($filename)); + my $canonical_time = $File::StripNondeterminism::canonical_time // 0; + + # Format is specified in docbook-to-man:Instant/main.c + my $timestamp = strftime('%a %d %b %Y, %R', localtime($canonical_time)); + + while (defined(my $line = <$fh>)) { + if ($line =~ s/(?<=^\.\\" created by instant \/ docbook-to-man, ).*/$timestamp/g) { + $modified = 1; + } + + print $tempfile $line; + } + + if ($modified) { + chmod((stat($fh))[2] & 07777, $tempfile->filename); + rename($tempfile->filename, $filename) + or die "$filename: unable to overwrite: rename: $!"; + $tempfile->unlink_on_destroy(0); + } + + return $modified; +} + +1; diff --git a/t/docbooktoman.t b/t/docbooktoman.t new file mode 100644 index 0000000..8072c42 --- /dev/null +++ b/t/docbooktoman.t @@ -0,0 +1,51 @@ +#!perl + +# +# Copyright 2015 Chris Lamb <[email protected]> +# +# This file is part of strip-nondeterminism. +# +# strip-nondeterminism is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# strip-nondeterminism is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with strip-nondeterminism. If not, see <http://www.gnu.org/licenses/>. +# + +use File::Temp 'tempdir'; +use Test::More tests => 2; +use File::StripNondeterminism; + +$dir = tempdir( CLEANUP => 1 ); +$path = "$dir/connect-proxy.1"; + +open(my $fh, '>', $path) or die("error opening $path"); +print $fh <<'EOF'; +.TH "CONNECT-PROXY" "1" +.SH "NAME" +connect-proxy \(em connect over SOCKS4/5 proxy + +.\" created by instant / docbook-to-man, Sat 24 Jan 2015, 11:43 +EOF +close $fh; + +$normalizer = File::StripNondeterminism::get_normalizer_for_file($path); +isnt(undef, $normalizer); +$normalizer->($path); + +open FILE,$path or die("error opening $path"); +local $/ = undef; +is(<FILE>, <<'EOF'); +.TH "CONNECT-PROXY" "1" +.SH "NAME" +connect-proxy \(em connect over SOCKS4/5 proxy + +.\" created by instant / docbook-to-man, Thu 01 Jan 1970, 00:00 +EOF -- 2.1.0

