From af7dd521363ea9b8476b8e92a44782678b3b5a5e Mon Sep 17 00:00:00 2001 From: r0man Date: Sat, 16 Jul 2022 20:24:18 +0200 Subject: gnu: clojure: Update to 1.11.1. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch updates Clojure to 1.11.1. It also adds the 'reset-class-timestamps phase to the Clojure build system. This phase makes sure the timestamp of compiled class files is set to a later point in time than the timestamp of the corresponding Clojure source files. If the timestamps of the class and source files are the same, the Clojure compiler will compile the sources again which can lead to issues. This problem has been discussed here [1]. The suggested solution was to keep/adjust the timestamps of the class files. [1] https://www.mail-archive.com/clojure@googlegroups.com/msg99928.html * gnu/packages/clojure.scm (clojure): Update to 1.11.1 and update all of LIBRARIES accordingly. [arguments]: In 'unpack-library-sources' phase, copy from "core-specs-alpha-src" and "spec-alpha-src" as well. Add phases 'closure-spec-skip-macros', 'clojure-spec-compile', 'maven-classpath-properties', and 'reset-class-timestamps'. * guix/build/clojure-build-system.scm (regular-jar-file?) (reset-class-timestamps): New procedures. (%standard-phases): Add 'reset-class-timestamps' phase. Co-authored-by: Ludovic Courtès --- guix/build/clojure-build-system.scm | 58 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'guix/build') diff --git a/guix/build/clojure-build-system.scm b/guix/build/clojure-build-system.scm index 7d494078ea..cacbefb386 100644 --- a/guix/build/clojure-build-system.scm +++ b/guix/build/clojure-build-system.scm @@ -22,11 +22,15 @@ (define-module (guix build clojure-build-system) ant-build)) #:use-module (guix build clojure-utils) #:use-module (guix build java-utils) + #:use-module (guix build syscalls) #:use-module (guix build utils) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:export (%standard-phases - clojure-build)) + clojure-build + reset-class-timestamps)) ;; Commentary: ;; @@ -108,6 +112,55 @@ (define* (check #:key jar-names))) #t) +(define (regular-jar-file? file stat) + "Predicate returning true if FILE is ending on '.jar' +and STAT indicates it is a regular file." + (and (string-suffix? ".jar" file) + (eq? 'regular (stat:type stat)))) + +;; XXX: The only difference compared to 'strip-jar-timestamps' in +;; ant-build-system.scm is the date. TODO: Adjust and factorize. +(define* (reset-class-timestamps #:key outputs #:allow-other-keys) + "Unpack all jar archives, reset the timestamp of all contained class files, +and repack them. This is necessary to ensure that archives are reproducible." + (define (repack-archive jar) + (format #t "resetting class timestamps and repacking ~a\n" jar) + + ;; Note: .class files need to be strictly newer than source files, + ;; otherwise the Clojure compiler will recompile sources. + (let* ((early-1980 315619200) ; 1980-01-02 UTC + (dir (mkdtemp! "jar-contents.XXXXXX")) + (manifest (string-append dir "/META-INF/MANIFEST.MF"))) + (with-directory-excursion dir + (invoke "jar" "xf" jar)) + (delete-file jar) + (for-each (lambda (file) + (let ((s (lstat file))) + (unless (eq? (stat:type s) 'symlink) + (when (string-match "^(.*)\\.class$" file) + (utime file early-1980 early-1980))))) + (find-files dir #:directories? #t)) + ;; The jar tool will always set the timestamp on the manifest file + ;; and the containing directory to the current time, even when we + ;; reuse an existing manifest file. To avoid this we use "zip" + ;; instead of "jar". It is important that the manifest appears + ;; first. + (with-directory-excursion dir + (let* ((files (find-files "." ".*" #:directories? #t)) + ;; To ensure that the reference scanner can detect all + ;; store references in the jars we disable compression + ;; with the "-0" option. + (command (if (file-exists? manifest) + `("zip" "-0" "-X" ,jar ,manifest ,@files) + `("zip" "-0" "-X" ,jar ,@files)))) + (apply invoke command))) + (utime jar 0 0))) + (for-each (match-lambda + ((output . directory) + (for-each repack-archive + (find-files directory regular-jar-file?)))) + outputs)) + (define-with-docs install "Standard 'install' phase for clojure-build-system." (install-jars "./")) @@ -119,7 +172,8 @@ (define-with-docs %standard-phases (replace 'build build) (replace 'check check) (replace 'install install) - (add-after 'install-license-files 'install-doc install-doc))) + (add-after 'install-license-files 'install-doc install-doc) + (add-after 'reset-gzip-timestamps 'reset-class-timestamps reset-class-timestamps))) (define* (clojure-build #:key inputs -- cgit v1.2.3