Patchwork [1/3] guix: ruby-build-system: Build compiled gems reproducibly.

login
register
mail settings
Submitter Ben Woodcroft
Date Aug. 10, 2016, 3:33 a.m.
Message ID <20160810033325.3880-2-donttrustben@gmail.com>
Download mbox | patch
Permalink /patch/14460/
State New
Headers show

Comments

Ben Woodcroft - Aug. 10, 2016, 3:33 a.m.
* guix/build/ruby-build-system.scm (log-file-deletion): New procedure.
(install): Remove files containing non-reproducible elements.  Print when each
file is deleted.
---
 guix/build/ruby-build-system.scm | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)
Ricardo Wurmus - Aug. 18, 2016, 10:06 a.m.
Ben Woodcroft <donttrustben@gmail.com> writes:

> * guix/build/ruby-build-system.scm (log-file-deletion): New procedure.
> (install): Remove files containing non-reproducible elements.  Print when each
> file is deleted.

Thank you, this looks good to me.  Good job on making even more Ruby
gems build reproducibly!

~~ Ricardo
Ben Woodcroft - Aug. 30, 2016, 1:08 a.m.
On 18/08/16 20:06, Ricardo Wurmus wrote:
> Ben Woodcroft <donttrustben@gmail.com> writes:
>
>> * guix/build/ruby-build-system.scm (log-file-deletion): New procedure.
>> (install): Remove files containing non-reproducible elements.  Print when each
>> file is deleted.
> Thank you, this looks good to me.  Good job on making even more Ruby
> gems build reproducibly!

Great, thanks Ricardo. I just pushed this series.

ben

Patch

diff --git a/guix/build/ruby-build-system.scm b/guix/build/ruby-build-system.scm
index 79ac380..95793f7 100644
--- a/guix/build/ruby-build-system.scm
+++ b/guix/build/ruby-build-system.scm
@@ -120,18 +120,44 @@  GEM-FLAGS are passed to the 'gem' invokation, if present."
                            1))
          (out (assoc-ref outputs "out"))
          (gem-home (string-append out "/lib/ruby/gems/" ruby-version ".0"))
-         (gem-name (first-matching-file "\\.gem$")))
+         (gem-file (first-matching-file "\\.gem$"))
+         (gem-file-basename (basename gem-file))
+         (gem-name (substring gem-file-basename
+                              0
+                              (- (string-length gem-file-basename) 4)))
+         (gem-directory (string-append gem-home "/gems/" gem-name)))
     (setenv "GEM_HOME" gem-home)
     (mkdir-p gem-home)
-    (and (apply system* "gem" "install" gem-name
+    (and (apply system* "gem" "install" gem-file
                 "--local" "--ignore-dependencies"
                 ;; Executables should go into /bin, not /lib/ruby/gems.
                 "--bindir" (string-append out "/bin")
                 gem-flags)
-         ;; Remove the cached gem file as this is unnecessary and contains
-         ;; timestamped files rendering builds not reproducible.
-         (begin (delete-file (string-append gem-home "/cache/" gem-name))
-                #t))))
+         (begin
+           ;; Remove the cached gem file as this is unnecessary and contains
+           ;; timestamped files rendering builds not reproducible.
+           (let ((cached-gem (string-append gem-home "/cache/" gem-file)))
+             (log-file-deletion cached-gem)
+             (delete-file cached-gem))
+           ;; For gems with native extensions, several Makefile-related files
+           ;; are created that contain timestamps or other elements making
+           ;; them not reproducible.  They are unnecessary so we remove them.
+           (if (file-exists? (string-append gem-directory "/ext"))
+               (begin
+                 (for-each (lambda (file)
+                             (log-file-deletion file)
+                             (delete-file file))
+                           (append
+                            (find-files (string-append gem-home "/doc")
+                                        "page-Makefile.ri")
+                            (find-files (string-append gem-home "/extensions")
+                                        "gem_make.out")
+                            (find-files (string-append gem-directory "/ext")
+                                        "Makefile")))))
+           #t))))
+
+(define (log-file-deletion file)
+  (display (string-append "deleting '" file "' for reproducibility\n")))
 
 (define %standard-phases
   (modify-phases gnu:%standard-phases