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
1 changed files with 55 additions and 53 deletions

View File

@ -52,18 +52,19 @@ 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
;; The unpacked gem directory is named the same as the archive, (invoke "gem" "unpack" source)
;; sans the ".gem" extension. It is renamed to simply "gem" in an ;; The unpacked gem directory is named the same as the archive,
;; effort to keep file names shorter to avoid UNIX-domain socket ;; sans the ".gem" extension. It is renamed to simply "gem" in an
;; file names and shebangs that exceed the system's fixed maximum ;; effort to keep file names shorter to avoid UNIX-domain socket
;; length when running test suites. ;; file names and shebangs that exceed the system's fixed maximum
(let ((dir (match:substring (string-match "^(.*)\\.gem$" ;; length when running test suites.
(basename source)) (let ((dir (match:substring (string-match "^(.*)\\.gem$"
1))) (basename source))
(rename-file dir "gem") 1)))
(chdir "gem") (rename-file dir "gem")
#t)) (chdir "gem"))
#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,43 +139,42 @@ 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 (let ((failed-output-dir (string-append (getcwd) "/out")))
(simple-format #t "installation failed\n") (mkdir failed-output-dir)
(let ((failed-output-dir (string-append (getcwd) "/out"))) (copy-recursively out failed-output-dir))
(mkdir failed-output-dir) (error "installation failed")))
(copy-recursively out failed-output-dir))
#f))) ;; Remove the cached gem file as this is unnecessary and contains
(begin ;; timestamped files rendering builds not reproducible.
;; Remove the cached gem file as this is unnecessary and contains (let ((cached-gem (string-append vendor-dir "/cache/" gem-file)))
;; timestamped files rendering builds not reproducible. (log-file-deletion cached-gem)
(let ((cached-gem (string-append vendor-dir "/cache/" gem-file))) (delete-file cached-gem))
(log-file-deletion 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. (when (file-exists? (string-append vendor-dir "/ext"))
(if (file-exists? (string-append vendor-dir "/ext")) (for-each (lambda (file)
(begin (log-file-deletion file)
(for-each (lambda (file) (delete-file file))
(log-file-deletion file) (append
(delete-file file)) (find-files (string-append vendor-dir "/doc")
(append "page-Makefile.ri")
(find-files (string-append vendor-dir "/doc") (find-files (string-append vendor-dir "/extensions")
"page-Makefile.ri") "gem_make.out")
(find-files (string-append vendor-dir "/extensions") (find-files (string-append vendor-dir "/ext")
"gem_make.out") "Makefile"))))
(find-files (string-append vendor-dir "/ext")
"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")))