builders.scm 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (tests builders)
  20. #:use-module (guix download)
  21. #:use-module (guix build-system)
  22. #:use-module (guix build-system gnu)
  23. #:use-module (guix build gnu-build-system)
  24. #:use-module (guix build utils)
  25. #:use-module (guix build-system python)
  26. #:use-module (guix grafts)
  27. #:use-module (guix store)
  28. #:use-module (guix monads)
  29. #:use-module (guix utils)
  30. #:use-module (guix base32)
  31. #:use-module (guix derivations)
  32. #:use-module (gcrypt hash)
  33. #:use-module (guix tests)
  34. #:use-module (guix packages)
  35. #:use-module (gnu packages bootstrap)
  36. #:use-module (ice-9 match)
  37. #:use-module (ice-9 textual-ports)
  38. #:use-module (srfi srfi-1)
  39. #:use-module (srfi srfi-11)
  40. #:use-module (srfi srfi-34)
  41. #:use-module (srfi srfi-64))
  42. ;; Test the higher-level builders.
  43. (define %store
  44. (open-connection-for-tests))
  45. (define url-fetch*
  46. (store-lower url-fetch))
  47. ;; Globally disable grafts because they can trigger early builds.
  48. (%graft? #f)
  49. (test-begin "builders")
  50. (unless (network-reachable?) (test-skip 1))
  51. (test-assert "url-fetch"
  52. (let* ((url '("http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"
  53. "ftp://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"))
  54. (hash (nix-base32-string->bytevector
  55. "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))
  56. (drv (url-fetch* %store url 'sha256 hash
  57. #:guile %bootstrap-guile))
  58. (out-path (derivation->output-path drv)))
  59. (and (build-derivations %store (list drv))
  60. (file-exists? out-path)
  61. (valid-path? %store out-path))))
  62. (test-assert "url-fetch, file"
  63. (let* ((file (search-path %load-path "guix.scm"))
  64. (hash (call-with-input-file file port-sha256))
  65. (out (url-fetch* %store file 'sha256 hash)))
  66. (and (file-exists? out)
  67. (valid-path? %store out))))
  68. (test-assert "url-fetch, file URI"
  69. (let* ((file (search-path %load-path "guix.scm"))
  70. (hash (call-with-input-file file port-sha256))
  71. (out (url-fetch* %store
  72. (string-append "file://" (canonicalize-path file))
  73. 'sha256 hash)))
  74. (and (file-exists? out)
  75. (valid-path? %store out))))
  76. (test-assert "gnu-build-system"
  77. (build-system? gnu-build-system))
  78. (define unpack (assoc-ref %standard-phases 'unpack))
  79. (define compressors '(("gzip" . "gz")
  80. ("xz" . "xz")
  81. ("bzip2" . "bz2")
  82. (#f . #f)))
  83. (for-each
  84. (match-lambda
  85. ((comp . ext)
  86. (unless (network-reachable?) (test-skip 1)) ;for bootstrap binaries
  87. (test-equal (string-append "gnu-build-system unpack phase, "
  88. "single file (compression: "
  89. (if comp comp "None") ")")
  90. "expected text"
  91. (let*-values
  92. (((name) "test")
  93. ((compressed-name) (if ext
  94. (string-append name "." ext)
  95. name))
  96. ((file hash) (test-file %store compressed-name "expected text")))
  97. (call-with-temporary-directory
  98. (lambda (dir)
  99. (with-directory-excursion dir
  100. (unpack #:source file)
  101. (call-with-input-file name get-string-all))))))))
  102. compressors)
  103. ;;;
  104. ;;; Test the sanity-check phase of the Python build system.
  105. ;;;
  106. (define* (make-python-dummy name #:key (setup-py-extra "")
  107. (init-py "") (use-setuptools? #t))
  108. (dummy-package (string-append "python-dummy-" name)
  109. (version "0.1")
  110. (build-system python-build-system)
  111. (arguments
  112. `(#:tests? #f
  113. #:use-setuptools? ,use-setuptools?
  114. #:phases
  115. (modify-phases %standard-phases
  116. (replace 'unpack
  117. (lambda _
  118. (mkdir-p "dummy")
  119. (with-output-to-file "dummy/__init__.py"
  120. (lambda _
  121. (display ,init-py)))
  122. (with-output-to-file "setup.py"
  123. (lambda _
  124. (format #t "\
  125. ~a
  126. setup(
  127. name='dummy-~a',
  128. version='0.1',
  129. packages=['dummy'],
  130. ~a
  131. )"
  132. (if ,use-setuptools?
  133. "from setuptools import setup"
  134. "from distutils.core import setup")
  135. ,name ,setup-py-extra))))))))))
  136. (define python-dummy-ok
  137. (make-python-dummy "ok"))
  138. ;; distutil won't install any metadata, so make sure our script does not fail
  139. ;; on a otherwise fine package.
  140. (define python-dummy-no-setuptools
  141. (make-python-dummy
  142. "no-setuptools" #:use-setuptools? #f))
  143. (define python-dummy-fail-requirements
  144. (make-python-dummy "fail-requirements"
  145. #:setup-py-extra "install_requires=['nonexistent'],"))
  146. (define python-dummy-fail-import
  147. (make-python-dummy "fail-import" #:init-py "import nonexistent"))
  148. (define python-dummy-fail-console-script
  149. (make-python-dummy "fail-console-script"
  150. #:setup-py-extra (string-append "entry_points={'console_scripts': "
  151. "['broken = dummy:nonexistent']},")))
  152. (define (check-build-success store p)
  153. (unless store (test-skip 1))
  154. (test-assert (string-append "python-build-system: " (package-name p))
  155. (let* ((drv (package-derivation store p)))
  156. (build-derivations store (list drv)))))
  157. (define (check-build-failure store p)
  158. (unless store (test-skip 1))
  159. (test-assert (string-append "python-build-system: " (package-name p))
  160. (let ((drv (package-derivation store p)))
  161. (guard (c ((store-protocol-error? c)
  162. (pk 'failure c #t))) ;good!
  163. (build-derivations store (list drv))
  164. #f)))) ;bad: it should have failed
  165. (with-external-store store
  166. (for-each (lambda (p) (check-build-success store p))
  167. (list
  168. python-dummy-ok
  169. python-dummy-no-setuptools))
  170. (for-each (lambda (p) (check-build-failure store p))
  171. (list
  172. python-dummy-fail-requirements
  173. python-dummy-fail-import
  174. python-dummy-fail-console-script)))
  175. (test-end "builders")