aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-02-28 10:42:09 +0100
committerLudovic Courtès <ludo@gnu.org>2014-02-28 10:42:09 +0100
commit3ca00bb51e3ff906a700b6925e0ce81558c8c469 (patch)
tree95be6924ae936a6c63ddf28dcd5c2044ec2eade2
parent284c004613e704d39e55516305b5c0307509604f (diff)
downloadpatches-3ca00bb51e3ff906a700b6925e0ce81558c8c469.tar
patches-3ca00bb51e3ff906a700b6925e0ce81558c8c469.tar.gz
packages: Support 'patches' and 'snippets' for sources that are directories.
* guix/packages.scm (patch-and-repack)[numeric-extension?, tarxz-name]: New procedures. [builder]: Adjust to deal with SOURCE when it's a directory. <body>: Use 'tarxz-name'. Always add (guix build utils) to IMPORTED-MODULES.
-rw-r--r--guix/packages.scm67
1 files changed, 48 insertions, 19 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index d345900f79..f2119bebce 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -315,6 +315,20 @@ IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
(dash (string-index sans #\-)))
(string-drop sans (+ 1 dash))))
+ (define (numeric-extension? file-name)
+ ;; Return true if FILE-NAME ends with digits.
+ (string-every char-set:hex-digit (file-extension file-name)))
+
+ (define (tarxz-name file-name)
+ ;; Return a '.tar.xz' file name based on FILE-NAME.
+ (let ((base (if (numeric-extension? file-name)
+ original-file-name
+ (file-sans-extension file-name))))
+ (string-append base
+ (if (equal? (file-extension base) "tar")
+ ".xz"
+ ".tar.xz"))))
+
(define patch-inputs
(map (lambda (number patch)
(list (string-append "patch" (number->string number))
@@ -327,7 +341,8 @@ IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
(define builder
`(begin
(use-modules (ice-9 ftw)
- (srfi srfi-1))
+ (srfi srfi-1)
+ (guix build utils))
(let ((out (assoc-ref %outputs "out"))
(xz (assoc-ref %build-inputs "xz"))
@@ -342,14 +357,28 @@ IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
(format (current-error-port) "applying '~a'...~%" patch*)
(zero? (system* patch "--batch" ,@flags "--input" patch*))))
+ (define (first-file directory)
+ ;; Return the name of the first file in DIRECTORY.
+ (car (scandir directory
+ (lambda (name)
+ (not (member name '("." "..")))))))
+
(setenv "PATH" (string-append xz "/bin" ":"
decomp "/bin"))
- (and (zero? (system* tar "xvf" source))
- (let ((directory (car (scandir "."
- (lambda (name)
- (not
- (member name
- '("." ".."))))))))
+
+ ;; SOURCE may be either a directory or a tarball.
+ (and (if (file-is-directory? source)
+ (let* ((store (or (getenv "NIX_STORE")
+ "/nix/store"))
+ (len (+ 1 (string-length store)))
+ (base (string-drop source len))
+ (dash (string-index base #\-))
+ (directory (string-drop base (+ 1 dash))))
+ (mkdir directory)
+ (copy-recursively source directory)
+ #t)
+ (zero? (system* tar "xvf" source)))
+ (let ((directory (first-file ".")))
(format (current-error-port)
"source is under '~a'~%" directory)
(chdir directory)
@@ -375,23 +404,23 @@ IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
(zero? (system* tar "cvfa" out directory))))))))
- (let ((name (string-append (file-sans-extension original-file-name)
- ".xz"))
- (inputs (filter-map (match-lambda
- ((name (? package? p))
- (and (member name (cons decompression-type
- '("tar" "xz" "patch")))
- (list name
- (package-derivation store p
- system)))))
- (or inputs (%standard-patch-inputs)))))
+ (let ((name (tarxz-name original-file-name))
+ (inputs (filter-map (match-lambda
+ ((name (? package? p))
+ (and (member name (cons decompression-type
+ '("tar" "xz" "patch")))
+ (list name
+ (package-derivation store p
+ system)))))
+ (or inputs (%standard-patch-inputs))))
+ (modules (delete-duplicates (cons '(guix build utils) modules))))
- (build-expression->derivation store name builder
+ (build-expression->derivation store name builder
#:inputs `(("source" ,source)
,@inputs
,@patch-inputs)
#:system system
- #:modules imported-modules
+ #:modules modules
#:guile-for-build guile-for-build)))
(define* (package-source-derivation store source