build-system/gnu: Always look for license files in the source tree.

Fixes <https://bugs.gnu.org/31103>.

* guix/build/gnu-build-system.scm (install-license-files): Add #:out-of-source?.
[find-source-directory]: New procedure.
Use it to Determine the source directory and look for license files
there.
This commit is contained in:
Ludovic Courtès 2019-03-09 15:08:11 +01:00
parent 5a45765628
commit 278409e7e9
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 40 additions and 8 deletions

View File

@ -735,8 +735,29 @@ which cannot be found~%"
(define* (install-license-files #:key outputs (define* (install-license-files #:key outputs
(license-file-regexp %license-file-regexp) (license-file-regexp %license-file-regexp)
out-of-source?
#:allow-other-keys) #:allow-other-keys)
"Install license files matching LICENSE-FILE-REGEXP to 'share/doc'." "Install license files matching LICENSE-FILE-REGEXP to 'share/doc'."
(define (find-source-directory package)
;; For an out-of-source build, guess the source directory location
;; relative to the current directory. Return #f on failure.
(match (scandir ".."
(lambda (file)
(and (not (member file '("." ".." "build")))
(file-is-directory?
(string-append "../" file)))))
(() ;hmm, no source
#f)
((source) ;only one other file
(string-append "../" source))
((directories ...) ;pick the most likely one
;; This happens for example with libstdc++, which lives within the GCC
;; source tree.
(any (lambda (directory)
(and (string-prefix? package directory)
(string-append "../" directory)))
directories))))
(let* ((regexp (make-regexp license-file-regexp)) (let* ((regexp (make-regexp license-file-regexp))
(out (or (assoc-ref outputs "out") (out (or (assoc-ref outputs "out")
(match outputs (match outputs
@ -744,14 +765,25 @@ which cannot be found~%"
output)))) output))))
(package (strip-store-file-name out)) (package (strip-store-file-name out))
(directory (string-append out "/share/doc/" package)) (directory (string-append out "/share/doc/" package))
(files (scandir "." (lambda (file) (source (if out-of-source?
(regexp-exec regexp file))))) (find-source-directory
(format #t "installing ~a license files~%" (length files)) (package-name->name+version package))
(for-each (lambda (file) "."))
(if (file-is-directory? file) (files (and source
(copy-recursively file directory) (scandir source
(install-file file directory))) (lambda (file)
files) (regexp-exec regexp file))))))
(if files
(begin
(format #t "installing ~a license files from '~a'~%"
(length files) source)
(for-each (lambda (file)
(if (file-is-directory? file)
(copy-recursively file directory)
(install-file file directory)))
(map (cut string-append source "/" <>) files)))
(format (current-error-port)
"failed to find license files~%"))
#t)) #t))
(define %standard-phases (define %standard-phases