[Git][reproducible-builds/strip-nondeterminism][master] Add support for custom .zip filename filtering and exclude two patterns of...
Chris Lamb
gitlab at salsa.debian.org
Fri Apr 17 10:29:20 UTC 2020
Chris Lamb pushed to branch master at Reproducible Builds / strip-nondeterminism
Commits:
2578d3dc by Chris Lamb at 2020-04-17T11:28:38+01:00
Add support for custom .zip filename filtering and exclude two patterns of files generated by Maven projects in "fork" mode. (Closes: reproducible-builds/strip-nondeterminism#13)
- - - - -
2 changed files:
- lib/File/StripNondeterminism/handlers/jar.pm
- lib/File/StripNondeterminism/handlers/zip.pm
Changes:
=====================================
lib/File/StripNondeterminism/handlers/jar.pm
=====================================
@@ -1,6 +1,6 @@
#
# Copyright 2014 Andrew Ayer
-# Copyright 2016-2018 Chris Lamb <lamby at debian.org>
+# Copyright 2016-2018, 2020 Chris Lamb <lamby at debian.org>
#
# This file is part of strip-nondeterminism.
#
@@ -42,6 +42,28 @@ sub _jar_filename_cmp($$) {
return $a cmp $b;
}
+sub _jar_filename_filter($) {
+ my @filenames = @_;
+
+ return grep {
+ # When a Maven project is built with the fork mode enabled for
+ # the maven-compiler.plugin, two extra files containing non
+ # reproducible elements are generated in the output directory
+ # and subsequently packaged in the jar.
+ #
+ # Remove executable script that could be run to recompile the
+ # project. It captures the build path.
+ $_ = undef if $_ eq "javac.sh";
+
+ # Contains the compiler arguments. The file name uses a random
+ # value.
+ $_ = undef if $_ =~ m/^org\.codehaus\.plexus\.compiler\.javac\.JavacCompiler\d+arguments$/;
+
+ # Allow all other files
+ $_;
+ } @filenames;
+}
+
sub _jar_normalize_manifest($) {
my ($filename) = @_;
@@ -127,6 +149,7 @@ sub normalize {
$jar_filename,
archive_filter => \&_jar_archive_filter,
filename_cmp => \&_jar_filename_cmp,
+ filename_filter => \&_jar_filename_filter,
member_normalizer => \&_jar_normalize_member
);
}
=====================================
lib/File/StripNondeterminism/handlers/zip.pm
=====================================
@@ -1,6 +1,6 @@
#
# Copyright 2014 Andrew Ayer
-# Copyright 2016-2019 Chris Lamb <lamby at debian.org>
+# Copyright 2016-2020 Chris Lamb <lamby at debian.org>
#
# This file is part of strip-nondeterminism.
#
@@ -201,6 +201,16 @@ sub normalize {
$canonical_time = SAFE_EPOCH
if not defined $canonical_time or $canonical_time < SAFE_EPOCH;
my @filenames = sort $filename_cmp $zip->memberNames();
+ if (exists($options{filename_filter})) {
+ @filenames = $options{filename_filter}->(@filenames);
+ # Remove any members deleted by the custom filter
+ my %seen = map { $_ => 1 } @filenames;
+ for my $filename ($zip->memberNames()) {
+ next if $seen{$filename};
+ print STDERR "Removing $filename from $zip_filename\n";
+ $zip->removeMember($filename);
+ }
+ }
for my $filename (@filenames) {
my $member = $zip->removeMember($filename);
if ($member->isEncrypted()) {
View it on GitLab: https://salsa.debian.org/reproducible-builds/strip-nondeterminism/-/commit/2578d3dccaf562f1ecb61ea4c68a1cef1ce11259
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/strip-nondeterminism/-/commit/2578d3dccaf562f1ecb61ea4c68a1cef1ce11259
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200417/e0b36b72/attachment.htm>
More information about the rb-commits
mailing list