ruby-build-system: Error or return #t from all phases.

Previously, if the tests didn't pass, the check phase would evaluate to #f,
but the package would be built sucessfully. This changes all the phases to
raise exceptions if errors are encountered, and return #t otherwise.

This involves using invoke rather than system*, so that exceptions are raised
if the program exits with a status other than 0, and also returning #t at the
end of functions.

* gnu/build/ruby-build-system.scm (unpack): Use invoke rather than system*,
and return #t at the end.
(build, check): Use invoke rather than system*.
(install): Remove the use of "and", and rewrite the error handling to raise an
exception.
(wrap): Return #t.
This commit is contained in:
Christopher Baines 2018-07-14 11:52:14 +01:00
parent ae608622f3
commit 0d354666d3
No known key found for this signature in database
GPG key ID: 5E28A33B0B84F577

View file

@ -52,7 +52,8 @@ directory."
(define* (unpack #:key source #:allow-other-keys) (define* (unpack #:key source #:allow-other-keys)
"Unpack the gem SOURCE and enter the resulting directory." "Unpack the gem SOURCE and enter the resulting directory."
(if (gem-archive? source) (if (gem-archive? source)
(and (zero? (system* "gem" "unpack" source)) (begin
(invoke "gem" "unpack" source)
;; The unpacked gem directory is named the same as the archive, ;; The unpacked gem directory is named the same as the archive,
;; sans the ".gem" extension. It is renamed to simply "gem" in an ;; sans the ".gem" extension. It is renamed to simply "gem" in an
;; effort to keep file names shorter to avoid UNIX-domain socket ;; effort to keep file names shorter to avoid UNIX-domain socket
@ -62,8 +63,8 @@ directory."
(basename source)) (basename source))
1))) 1)))
(rename-file dir "gem") (rename-file dir "gem")
(chdir "gem") (chdir "gem"))
#t)) #t)
;; Use GNU unpack strategy for things that aren't gem archives. ;; Use GNU unpack strategy for things that aren't gem archives.
(gnu:unpack #:source source))) (gnu:unpack #:source source)))
@ -104,7 +105,8 @@ generate the files list."
(write-char (read-char pipe) out)))) (write-char (read-char pipe) out))))
#t) #t)
(lambda () (lambda ()
(close-pipe pipe))))))) (close-pipe pipe)))))
#t))
(define* (build #:key source #:allow-other-keys) (define* (build #:key source #:allow-other-keys)
"Build a new gem using the gemspec from the SOURCE gem." "Build a new gem using the gemspec from the SOURCE gem."
@ -112,13 +114,13 @@ generate the files list."
;; Build a new gem from the current working directory. This also allows any ;; Build a new gem from the current working directory. This also allows any
;; dynamic patching done in previous phases to be present in the installed ;; dynamic patching done in previous phases to be present in the installed
;; gem. ;; gem.
(zero? (system* "gem" "build" (first-gemspec)))) (invoke "gem" "build" (first-gemspec)))
(define* (check #:key tests? test-target #:allow-other-keys) (define* (check #:key tests? test-target #:allow-other-keys)
"Run the gem's test suite rake task TEST-TARGET. Skip the tests if TESTS? "Run the gem's test suite rake task TEST-TARGET. Skip the tests if TESTS?
is #f." is #f."
(if tests? (if tests?
(zero? (system* "rake" test-target)) (invoke "rake" test-target)
#t)) #t))
(define* (install #:key inputs outputs (gem-flags '()) (define* (install #:key inputs outputs (gem-flags '())
@ -137,32 +139,30 @@ GEM-FLAGS are passed to the 'gem' invokation, if present."
0 0
(- (string-length gem-file-basename) 4)))) (- (string-length gem-file-basename) 4))))
(setenv "GEM_VENDOR" vendor-dir) (setenv "GEM_VENDOR" vendor-dir)
(and (let ((install-succeeded?
(zero? (or (zero?
(apply system* "gem" "install" gem-file (apply system* "gem" "install" gem-file
"--local" "--ignore-dependencies" "--vendor" "--local" "--ignore-dependencies" "--vendor"
;; Executables should go into /bin, not ;; Executables should go into /bin, not
;; /lib/ruby/gems. ;; /lib/ruby/gems.
"--bindir" (string-append out "/bin") "--bindir" (string-append out "/bin")
gem-flags)))) gem-flags))
(or install-succeeded?
(begin (begin
(simple-format #t "installation failed\n")
(let ((failed-output-dir (string-append (getcwd) "/out"))) (let ((failed-output-dir (string-append (getcwd) "/out")))
(mkdir failed-output-dir) (mkdir failed-output-dir)
(copy-recursively out failed-output-dir)) (copy-recursively out failed-output-dir))
#f))) (error "installation failed")))
(begin
;; Remove the cached gem file as this is unnecessary and contains ;; Remove the cached gem file as this is unnecessary and contains
;; timestamped files rendering builds not reproducible. ;; timestamped files rendering builds not reproducible.
(let ((cached-gem (string-append vendor-dir "/cache/" gem-file))) (let ((cached-gem (string-append vendor-dir "/cache/" gem-file)))
(log-file-deletion cached-gem) (log-file-deletion cached-gem)
(delete-file cached-gem)) (delete-file cached-gem))
;; For gems with native extensions, several Makefile-related files ;; For gems with native extensions, several Makefile-related files
;; are created that contain timestamps or other elements making ;; are created that contain timestamps or other elements making
;; them not reproducible. They are unnecessary so we remove them. ;; them not reproducible. They are unnecessary so we remove them.
(if (file-exists? (string-append vendor-dir "/ext")) (when (file-exists? (string-append vendor-dir "/ext"))
(begin
(for-each (lambda (file) (for-each (lambda (file)
(log-file-deletion file) (log-file-deletion file)
(delete-file file)) (delete-file file))
@ -172,8 +172,9 @@ GEM-FLAGS are passed to the 'gem' invokation, if present."
(find-files (string-append vendor-dir "/extensions") (find-files (string-append vendor-dir "/extensions")
"gem_make.out") "gem_make.out")
(find-files (string-append vendor-dir "/ext") (find-files (string-append vendor-dir "/ext")
"Makefile"))))) "Makefile"))))
#t))))
#t))
(define* (wrap-ruby-program prog #:key (gem-clear-paths #t) #:rest vars) (define* (wrap-ruby-program prog #:key (gem-clear-paths #t) #:rest vars)
"Make a wrapper for PROG. VARS should look like this: "Make a wrapper for PROG. VARS should look like this:
@ -301,7 +302,8 @@ extended with definitions for VARS."
(let ((files (list-of-files dir))) (let ((files (list-of-files dir)))
(for-each (cut wrap-ruby-program <> var) (for-each (cut wrap-ruby-program <> var)
files))) files)))
bindirs))) bindirs))
#t)
(define (log-file-deletion file) (define (log-file-deletion file)
(display (string-append "deleting '" file "' for reproducibility\n"))) (display (string-append "deleting '" file "' for reproducibility\n")))