From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1pGq-0006qR-Dw for guix-patches@gnu.org; Tue, 10 Oct 2017 03:48:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1pGk-0002FT-Jo for guix-patches@gnu.org; Tue, 10 Oct 2017 03:48:08 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:50381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1pGk-0002FN-GF for guix-patches@gnu.org; Tue, 10 Oct 2017 03:48:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e1pGk-0005xm-A6 for guix-patches@gnu.org; Tue, 10 Oct 2017 03:48:02 -0400 Subject: [bug#28773] [PATCH 2/3] ruby-build-system: Add a new wrap phase. Resent-Message-ID: From: Christopher Baines Date: Tue, 10 Oct 2017 08:47:04 +0100 Message-Id: <20171010074705.5676-2-mail@cbaines.net> In-Reply-To: <20171010074705.5676-1-mail@cbaines.net> References: <20171010074705.5676-1-mail@cbaines.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 28773@debbugs.gnu.org Wrap files in bin/ and sbin/ with the location of the gem itself (GEM_HOME) and the location of any other gems in use (GEM_PATH). This ensures that the bin files will run with the right environment when executed. It does however mean that native-inputs will also get wrapped up in any binaries, which is not good, as it increases the size of the closure, and risks this code being used at runtime. * guix/build/ruby-build-system.scm (wrap): New procedure. (%standard-phases): Add the wrap phase. --- guix/build/ruby-build-system.scm | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/guix/build/ruby-build-system.scm b/guix/build/ruby-build-system.scm index af193b9ce..b6f0fc941 100644 --- a/guix/build/ruby-build-system.scm +++ b/guix/build/ruby-build-system.scm @@ -21,6 +21,7 @@ (define-module (guix build ruby-build-system) #:use-module ((guix build gnu-build-system) #:prefix gnu:) #:use-module (guix build utils) + #:use-module (ice-9 ftw) #:use-module (ice-9 match) #:use-module (ice-9 popen) #:use-module (ice-9 regex) @@ -269,6 +270,30 @@ extended with definitions for VARS." (chmod prog-tmp #o755) (rename-file prog-tmp prog)))) +(define* (wrap #:key inputs outputs #:allow-other-keys) + (define (list-of-files dir) + (map (cut string-append dir "/" <>) + (or (scandir dir (lambda (f) + (let ((s (stat (string-append dir "/" f)))) + (eq? 'regular (stat:type s))))) + '()))) + + (define bindirs + (append-map (match-lambda + ((_ . dir) + (list (string-append dir "/bin") + (string-append dir "/sbin")))) + outputs)) + + (let* ((out (assoc-ref outputs "out")) + (var `("GEM_PATH" prefix + (,(getenv "GEM_HOME") ,(getenv "GEM_PATH"))))) + (for-each (lambda (dir) + (let ((files (list-of-files dir))) + (for-each (cut wrap-ruby-program <> var) + files))) + bindirs))) + (define (log-file-deletion file) (display (string-append "deleting '" file "' for reproducibility\n"))) @@ -280,7 +305,8 @@ extended with definitions for VARS." (add-after 'extract-gemspec 'replace-git-ls-files replace-git-ls-files) (replace 'build build) (replace 'check check) - (replace 'install install))) + (replace 'install install) + (add-after 'install 'wrap wrap))) (define* (ruby-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args) -- 2.14.2