[Git][reproducible-builds/strip-nondeterminism][master] Support OpenJDK ".jmod" files. Thanks to Emmanuel Bourg for the bug report and...
Chris Lamb
gitlab at salsa.debian.org
Tue Jul 30 12:28:53 UTC 2019
Chris Lamb pushed to branch master at Reproducible Builds / strip-nondeterminism
Commits:
7d9324db by Chris Lamb at 2019-07-30T12:28:41Z
Support OpenJDK ".jmod" files. Thanks to Emmanuel Bourg for the bug report and implementation idea. (Closes: reproducible-builds/strip-nondeterminism#11, Debian:#933337)
- - - - -
4 changed files:
- lib/File/StripNondeterminism.pm
- + lib/File/StripNondeterminism/handlers/jmod.pm
- + t/fixtures/jmod/test1.jmod.in
- + t/fixtures/jmod/test1.jmod.out
Changes:
=====================================
lib/File/StripNondeterminism.pm
=====================================
@@ -64,6 +64,16 @@ sub get_normalizer_for_file($) {
&& _get_file_type($_) =~ m/(Java|Zip) archive data/) {
return _handler('jar');
}
+ # jmod
+ if (m/\.jmod$/) {
+ # Loading the handler forces the load of the jmod package as well
+ my $handler = _handler('jmod');
+
+ # Only recent versions of file(1) can detect Jmod file so we
+ # perform a manual test.
+ return $handler
+ if File::StripNondeterminism::handlers::jmod::is_jmod_file($_);
+ }
# javadoc
if (m/\.html$/) {
# Loading the handler forces the load of the javadoc package as well
@@ -105,6 +115,7 @@ our %KNOWN_HANDLERS = (
gzip => 1,
jar => 1,
javadoc => 1,
+ jmod => 1,
uimage => 1,
png => 1,
javaproperties => 1,
@@ -136,6 +147,7 @@ sub get_normalizer_by_name($) {
# From Debian::Debhelper::Dh_Lib
my $_disable_file_seccomp;
+
sub _internal_optional_file_args {
if (not defined($_disable_file_seccomp)) {
my $consider_disabling_seccomp = 0;
=====================================
lib/File/StripNondeterminism/handlers/jmod.pm
=====================================
@@ -0,0 +1,86 @@
+#
+# Copyright 2019 Chris Lamb <lamby at debian.org>
+#
+# 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::jmod;
+
+use strict;
+use warnings;
+
+use File::StripNondeterminism::handlers::jar;
+
+use File::Temp;
+use File::Basename;
+
+sub is_jmod_file($) {
+ # Only recent versions of file(1) can detect Jmod file so we perform a
+ # manual test.
+ my ($filename) = @_;
+
+ my $fh;
+ my $str;
+ return
+ open($fh, '<', $filename)
+ && read($fh, $str, 4)
+ && $str =~ /^JM..$/;
+}
+
+sub normalize {
+ my ($filename) = @_;
+
+ # .jmod files are .jar files with an extra 4-bytes at the top.
+
+ open(my $fh, '<', $filename)
+ or die "Unable to open $filename for reading: $!";
+
+ # Save the (exact) 4-byte header for subsequent replay
+ read($fh, my $header, 4) == 4 or die "$filename: read failed: $!";
+
+ # Output the tail of the file into a temporary file
+ my $buf;
+ my $tempfile = File::Temp->new(DIR => dirname($filename), CLEANUP => 0);
+ my $bytes_read;
+ while ($bytes_read = read($fh, $buf, 4096)) {
+ print $tempfile $buf;
+ }
+ defined($bytes_read) or die "$filename: read failed: $!";
+ close $tempfile;
+
+ # Call the underlying Jar normalizer
+ return 0
+ if not File::StripNondeterminism::handlers::jar::normalize(
+ $tempfile->filename);
+
+ open(my $in, '<', $tempfile->filename)
+ or die "Unable to open $tempfile->filename for reading: $!";
+ open(my $out, '>', $filename)
+ or die "Unable to open $filename for writing: $!";
+
+ # Write the header back to the final target...
+ print $out $header;
+
+ # ... followed by the rest of the modified file.
+ while ($bytes_read = read($in, $buf, 4096)) {
+ print $out $buf;
+ }
+ close $in;
+ close $out;
+
+ return 1;
+}
+
+1;
=====================================
t/fixtures/jmod/test1.jmod.in
=====================================
Binary files /dev/null and b/t/fixtures/jmod/test1.jmod.in differ
=====================================
t/fixtures/jmod/test1.jmod.out
=====================================
Binary files /dev/null and b/t/fixtures/jmod/test1.jmod.out differ
View it on GitLab: https://salsa.debian.org/reproducible-builds/strip-nondeterminism/commit/7d9324dbba8f921bebf36f799762ae410c05852c
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/strip-nondeterminism/commit/7d9324dbba8f921bebf36f799762ae410c05852c
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/20190730/46393991/attachment.html>
More information about the rb-commits
mailing list