From ac054f8d51c2a59968dd9d37b5c4da3b7dddb284 Mon Sep 17 00:00:00 2001 From: knaccc Date: Sun, 30 Jun 2019 06:45:35 +0100 Subject: [PATCH] normalizeZip now uses specified timestamp, since git will not propagate VERSION file timestamp during git clone --- bin/build-launcher.sh | 1 - bin/build-normalize-zip.sh | 1 - bin/convert-jars-to-modules.sh | 1 - bin/java-config.sh | 16 ++++++++++++++++ bin/util.sh | 17 ----------------- bin/zip-all.sh | 2 +- .../util/normalizeZip/NormalizeZip.java | 14 +++++--------- 7 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 bin/util.sh diff --git a/bin/build-launcher.sh b/bin/build-launcher.sh index 4d5abbc..7a41ce7 100755 --- a/bin/build-launcher.sh +++ b/bin/build-launcher.sh @@ -7,7 +7,6 @@ else fi source "$basedir/bin/java-config.sh" -source "$basedir/bin/util.sh" echo "*** Compiling CLI" "$JAVA_HOME"/bin/javac --module-path target/modules/combined.jar -d target/classes/org.getmonero.i2p.zero $(find org.getmonero.i2p.zero/src -name '*.java') diff --git a/bin/build-normalize-zip.sh b/bin/build-normalize-zip.sh index c017ae7..8e829e1 100755 --- a/bin/build-normalize-zip.sh +++ b/bin/build-normalize-zip.sh @@ -7,7 +7,6 @@ else fi source "$basedir/bin/java-config.sh" -source "$basedir/bin/util.sh" echo "*** Compiling Zip normalizer utility" "$JAVA_HOME"/bin/javac --module-path import/commons-compress-1.18/commons-compress-1.18.jar -d target/classes/org.getmonero.util.normalizeZip $(find org.getmonero.util.normalizeZip/src -name '*.java') diff --git a/bin/convert-jars-to-modules.sh b/bin/convert-jars-to-modules.sh index ca264b5..9b6d601 100755 --- a/bin/convert-jars-to-modules.sh +++ b/bin/convert-jars-to-modules.sh @@ -7,7 +7,6 @@ else fi source "$basedir/bin/java-config.sh" -source "$basedir/bin/util.sh" cp "$basedir"/import/jetty-lib/*.jar "$basedir/import/lib/" diff --git a/bin/java-config.sh b/bin/java-config.sh index b39d7c7..74d55b6 100644 --- a/bin/java-config.sh +++ b/bin/java-config.sh @@ -46,3 +46,19 @@ if [ $OS = "Darwin" ]; then else export JAVA_HOME=$JAVA_HOME_LINUX fi + +# get the SHA-256 hash of the specified file +getHash () { + if [ $(uname -s) = Darwin ]; then + h=`shasum -a 256 $1 | awk '{print $1}'` + else + h=`sha256sum $1 | awk '{print $1}'` + fi + echo $h +} + +# normalizes the specified jar or zip for reproducible build. Enforces consistent zip file order and sets all timestamps to midnight on Jan 1 2019 +normalizeZip () { + $JAVA_HOME/bin/java --module-path "$basedir/import/commons-compress-1.18/commons-compress-1.18.jar":"$basedir/target/org.getmonero.util.normalizeZip.jar" \ + -m org.getmonero.util.normalizeZip 1546300800000 "$1" +} \ No newline at end of file diff --git a/bin/util.sh b/bin/util.sh deleted file mode 100644 index 32b6ec5..0000000 --- a/bin/util.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# get the SHA-256 hash of the specified file -getHash () { - if [ $(uname -s) = Darwin ]; then - h=`shasum -a 256 $1 | awk '{print $1}'` - else - h=`sha256sum $1 | awk '{print $1}'` - fi - echo $h -} - -# normalizes the specified jar or zip for reproducible build. Enforces consistent zip file order and sets all timestamps to the last modified date of the VERSION file -normalizeZip () { - $JAVA_HOME/bin/java --module-path "$basedir/import/commons-compress-1.18/commons-compress-1.18.jar":"$basedir/target/org.getmonero.util.normalizeZip.jar" \ - -m org.getmonero.util.normalizeZip "$basedir/org.getmonero.i2p.zero/src/org/getmonero/i2p/zero/VERSION" "$1" -} \ No newline at end of file diff --git a/bin/zip-all.sh b/bin/zip-all.sh index 20dd08e..ce842f5 100755 --- a/bin/zip-all.sh +++ b/bin/zip-all.sh @@ -6,7 +6,7 @@ else basedir=$(dirname $(dirname $(readlink -fm $0))) fi -source "$basedir/bin/util.sh" +source "$basedir/bin/java-config.sh" VERSION=$(head -n 1 "$basedir/org.getmonero.i2p.zero/src/org/getmonero/i2p/zero/VERSION") diff --git a/org.getmonero.util.normalizeZip/src/org/getmonero/util/normalizeZip/NormalizeZip.java b/org.getmonero.util.normalizeZip/src/org/getmonero/util/normalizeZip/NormalizeZip.java index a1bf70c..2a05ffe 100644 --- a/org.getmonero.util.normalizeZip/src/org/getmonero/util/normalizeZip/NormalizeZip.java +++ b/org.getmonero.util.normalizeZip/src/org/getmonero/util/normalizeZip/NormalizeZip.java @@ -36,30 +36,26 @@ public final class NormalizeZip { public static void main(String[] args) throws Exception { if(args.length!=2) { - System.out.println("Arguments: timestampSource zip"); + System.out.println("Arguments: timestamp zip"); System.exit(1); } - File timestampSourceFile = Path.of(args[0]).toFile(); + long timestamp = Long.parseLong(args[0]); File sourceZipFile = Path.of(args[1]).toFile(); File destZipFile = Path.of(args[1]+".tmp").toFile(); - if(!timestampSourceFile.exists()) { - System.out.println("Timestamp source file does not exist"); - System.exit(1); - } if(!sourceZipFile.exists()) { System.out.println("Source zip file does not exist"); System.exit(1); } - System.out.println("Normalizing zip " + sourceZipFile.getCanonicalPath() + " to timestamp: " + new Date(timestampSourceFile.lastModified())); + System.out.println("Normalizing zip " + sourceZipFile.getCanonicalPath() + " to timestamp: " + new Date(timestamp)); - NormalizeZip nz = new NormalizeZip(timestampSourceFile.lastModified(), true).addFileStripper("META-INF/MANIFEST.MF", new ManifestStripper()); + NormalizeZip nz = new NormalizeZip(timestamp, true).addFileStripper("META-INF/MANIFEST.MF", new ManifestStripper()); nz.strip(sourceZipFile, destZipFile); if(!sourceZipFile.delete()) System.out.println("Cannot delete source file"); if(!destZipFile.renameTo(sourceZipFile)) System.out.println("Cannot rename temporary zip file"); destZipFile = sourceZipFile; - if(!destZipFile.setLastModified(timestampSourceFile.lastModified())) System.out.println("Cannot update zip last modified date"); + if(!destZipFile.setLastModified(timestamp)) System.out.println("Cannot update zip last modified date"); } /**