From ddd1633f12cd53bbe6a8f2ccfbfa02678365f486 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Thu, 10 Mar 2016 11:50:52 +0100 Subject: [PATCH] Changes to the ant-build-system. Do this in a new build phase after "install": Unpack jar, reset timestamps, repack jar. --- guix/build-system/ant.scm | 1 + guix/build/ant-build-system.scm | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/guix/build-system/ant.scm b/guix/build-system/ant.scm index 5240ff6..ac5546c 100644 --- a/guix/build-system/ant.scm +++ b/guix/build-system/ant.scm @@ -39,6 +39,7 @@ (define %ant-build-system-modules ;; Build-side modules imported by default. `((guix build ant-build-system) + (guix build syscalls) ,@%gnu-build-system-modules)) (define (default-jdk) diff --git a/guix/build/ant-build-system.scm b/guix/build/ant-build-system.scm index 1e3a1ea..7cb620b 100644 --- a/guix/build/ant-build-system.scm +++ b/guix/build/ant-build-system.scm @@ -18,6 +18,7 @@ (define-module (guix build ant-build-system) #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module (guix build syscalls) #:use-module (guix build utils) #:use-module (sxml simple) #:use-module (ice-9 match) @@ -61,14 +62,8 @@ (destdir "${classes.dir}") (classpath (@ (refid "classpath")))))) - ;; Reset the ctime/mtime on all files to ensure that the - ;; jar archive for the same class files is bit-identical. - (target (@ (name "touch")) - (exec (@ (executable "find")) - (arg (@ (line "${classes.dir} -exec touch -d @0 {} ;"))))) - (target (@ (name "jar") - (depends "compile,touch")) + (depends "compile")) (mkdir (@ (dir "${jar.dir}"))) ;; We cannot use the simpler "jar" task here, because ;; there is no way to disable generation of a @@ -109,6 +104,31 @@ INPUTS." #:allow-other-keys) (zero? (apply system* `("ant" ,build-target ,@make-flags)))) +(define* (repack #:key outputs + #:allow-other-keys) + "Unpack all jar archives, reset the timestamp of all contained files, and +repack them. This is necessary to ensure that archives are reproducible." + (define (repack-archive jar) + (format #t "repacking ~a\n" jar) + (let ((dir (mkdtemp! "jar-contents.XXXXXX"))) + (and (with-directory-excursion dir + (zero? (system* "jar" "xf" jar))) + ;; The manifest file contains timestamps + (for-each delete-file (find-files dir "MANIFEST.MF")) + (delete-file jar) + (ftw dir (lambda (file stat flag) + (utime file 0 0) + #t)) + (format #t "~a\n" (string-join (list "jar" "-Mcf" jar "-C" dir "."))) + (zero? (system* "jar" "-Mcf" jar "-C" dir ".")) + (utime jar 0 0) + #t))) + + (every (match-lambda + ((output . directory) + (every repack-archive (find-files directory "\\.jar$")))) + outputs)) + (define* (check #:key target (make-flags '()) (tests? (not target)) (test-target "check") #:allow-other-keys) @@ -126,7 +146,8 @@ INPUTS." (replace 'configure configure) (replace 'build build) (replace 'check check) - (replace 'install install))) + (replace 'install install) + (add-after 'install 'repack repack))) (define* (ant-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args) -- 2.1.0