From: Danny Milosavljevic Date: Wed, 18 Apr 2022 20:10:01 +0100 Subject: Make JARs reproducible --- jdk-09/make/common/JarArchive.gmk.orig 2022-04-08 21:56:04.075111687 +0200 +++ jdk-09/make/common/JarArchive.gmk 2022-04-11 00:49:16.809140388 +0200 @@ -249,12 +249,16 @@ $(ECHO) "Main-Class: $$(strip $$($1_JARMAIN))" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \ $$(if $$($1_EXTRA_MANIFEST_ATTR), \ $(PRINTF) "$$($1_EXTRA_MANIFEST_ATTR)\n" >> $$($1_MANIFEST_FILE) $$(NEWLINE)) \ - $(ECHO) Creating $$($1_NAME) $$(NEWLINE) \ + $(TOUCH) -h -c -t 197001010000.00 $$($1_MANIFEST_FILE) $$(NEWLINE) \ + $(ECHO) XCreating $$($1_NAME) $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ $(JAR) $$($1_JAR_CREATE_OPTIONS) $$@ $$($1_MANIFEST_FILE) $$(NEWLINE) \ $$($1_SCAPTURE_CONTENTS) \ $$($1_SCAPTURE_METAINF) \ $$($1_SUPDATE_CONTENTS) \ - $$($1_JARINDEX) && true \ + $$($1_JARINDEX) && true $$(NEWLINE) \ + $(ECHO) Kreppel2 $$@ $$(NEWLINE) \ + unzip -v $$@ $$(NEWLINE) \ + d="`mktemp -d`" && $(CP) -f $$@ "$$$$d/a.jar" && (cd "$$$$d" && unzip a.jar META-INF/MANIFEST.MF && $(TOUCH) -h -c -t 197001010000.00 META-INF && $(TOUCH) -h -c -t 197001010000.00 META-INF/MANIFEST.MF && (zip --symlinks -0 -X a.jar META-INF META-INF/MANIFEST.MF; zip --symlinks -0 -X a.jar META-INF META-INF/MANIFEST.MF)) && $(CP) -f "$$$$d/a.jar" $$@ \ , \ $(ECHO) Modifying $$($1_NAME) $$(NEWLINE) \ $$($1_CAPTURE_CONTENTS) \ --- jdk-09/make/JrtfsJar.gmk.orig 2022-04-10 13:48:57.385120008 +0200 +++ jdk-09/make/JrtfsJar.gmk 2022-04-10 13:58:04.688158538 +0200 @@ -57,13 +57,18 @@ # file will not be copied unless META-INF/services would also be added to the INCLUDES. # Adding META-INF/services would include all files in that directory when only the one # is needed, which is why this explicit copy is defined instead. -$(eval $(call SetupCopyFiles, COPY_JIMAGE_SERVICE_PROVIDER, \ +$(eval $(call SetupCopyFiles, COPY_JIMAGE_SERVICE_PROVIDER1, \ SRC := $(JDK_TOPDIR)/src/java.base/share/classes, \ DEST := $(SUPPORT_OUTPUTDIR)/jrtfs_classes, \ FILES := META-INF/services/java.nio.file.spi.FileSystemProvider)) +.PHONY: jrtfsfixtimestamps47 +jrtfsfixtimestamps47: $(COPY_JIMAGE_SERVICE_PROVIDER1) + find $(SUPPORT_OUTPUTDIR)/jrtfs_classes -exec $(TOUCH) -h -c -t 197001010000.00 {} \; + $(TOUCH) -h -c -t 197001010000.00 $(SUPPORT_OUTPUTDIR)/java-main-manifest.mf + $(eval $(call SetupJarArchive,BUILD_JRTFS_JAR, \ - DEPENDENCIES := $(BUILD_JRTFS) $(COPY_JIMAGE_SERVICE_PROVIDER), \ + DEPENDENCIES := $(BUILD_JRTFS) jrtfsfixtimestamps47, \ SRCS := $(SUPPORT_OUTPUTDIR)/jrtfs_classes, \ JAR := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base/jrt-fs.jar, \ MANIFEST := $(SUPPORT_OUTPUTDIR)/java-main-manifest.mf, \ --- jdk-09/jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java.orig 2022-04-10 02:05:50.983247794 +0200 +++ jdk-09/jdk/src/jdk.jartool/share/classes/sun/tools/jar/Main.java 2022-04-10 02:13:01.638960337 +0200 @@ -850,12 +850,18 @@ output(getMsg("out.added.manifest")); } ZipEntry e = new ZipEntry(MANIFEST_DIR); - e.setTime(System.currentTimeMillis()); + if (System.getenv("SOURCE_DATE_EPOCH") != null) + e.setTime(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH"))); + else + e.setTime(System.currentTimeMillis()); e.setSize(0); e.setCrc(0); zos.putNextEntry(e); e = new ZipEntry(MANIFEST_NAME); - e.setTime(System.currentTimeMillis()); + if (System.getenv("SOURCE_DATE_EPOCH") != null) + e.setTime(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH"))); + else + e.setTime(System.currentTimeMillis()); if (flag0) { crc32Manifest(e, manifest); } @@ -1022,7 +1028,10 @@ throws IOException { ZipEntry e = new ZipEntry(INDEX_NAME); - e.setTime(System.currentTimeMillis()); + if (System.getenv("SOURCE_DATE_EPOCH") != null) + e.setTime(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH"))); + else + e.setTime(System.currentTimeMillis()); if (flag0) { CRC32OutputStream os = new CRC32OutputStream(); index.write(os); @@ -1041,7 +1050,10 @@ String name = mi.getKey(); byte[] bytes = mi.getValue(); ZipEntry e = new ZipEntry(name); - e.setTime(System.currentTimeMillis()); + if (System.getenv("SOURCE_DATE_EPOCH") != null) + e.setTime(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH"))); + else + e.setTime(System.currentTimeMillis()); if (flag0) { crc32ModuleInfo(e, bytes); } @@ -1066,7 +1078,10 @@ addMultiRelease(m); } ZipEntry e = new ZipEntry(MANIFEST_NAME); - e.setTime(System.currentTimeMillis()); + if (System.getenv("SOURCE_DATE_EPOCH") != null) + e.setTime(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH"))); + else + e.setTime(System.currentTimeMillis()); if (flag0) { crc32Manifest(e, m); }