builders.scm 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 store)
  27. #:use-module (guix monads)
  28. #:use-module (guix utils)
  29. #:use-module (guix base32)
  30. #:use-module (guix derivations)
  31. #:use-module (gcrypt hash)
  32. #:use-module (guix tests)
  33. #:use-module (guix packages)
  34. #:use-module (gnu packages bootstrap)
  35. #:use-module (ice-9 match)
  36. #:use-module (ice-9 textual-ports)
  37. #:use-module (srfi srfi-1)
  38. #:use-module (srfi srfi-11)
  39. #:use-module (srfi srfi-34)
  40. #:use-module (srfi srfi-64))
  41. ;; Test the higher-level builders.
  42. (define %store
  43. (open-connection-for-tests))
  44. (define url-fetch*
  45. (store-lower url-fetch))
  46. ;; Globally disable grafts because they can trigger early builds.
  47. (%graft? #f)
  48. (test-begin "builders")
  49. (unless (network-reachable?) (test-skip 1))
  50. (test-assert "url-fetch"
  51. (let* ((url '("http://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"
  52. "ftp://ftp.gnu.org/gnu/hello/hello-2.8.tar.gz"))
  53. (hash (nix-base32-string->bytevector
  54. "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))
  55. (drv (url-fetch* %store url 'sha256 hash
  56. #:guile %bootstrap-guile))
  57. (out-path (derivation->output-path drv)))
  58. (and (build-derivations %store (list drv))
  59. (file-exists? out-path)
  60. (valid-path? %store out-path))))
  61. (test-assert "url-fetch, file"
  62. (let* ((file (search-path %load-path "guix.scm"))
  63. (hash (call-with-input-file file port-sha256))
  64. (out (url-fetch* %store file 'sha256 hash)))
  65. (and (file-exists? out)
  66. (valid-path? %store out))))
  67. (test-assert "url-fetch, file URI"
  68. (let* ((file (search-path %load-path "guix.scm"))
  69. (hash (call-with-input-file file port-sha256))
  70. (out (url-fetch* %store
  71. (string-append "file://" (canonicalize-path file))
  72. 'sha256 hash)))
  73. (and (file-exists? out)
  74. (valid-path? %store out))))
  75. (test-assert "gnu-build-system"
  76. (build-system? gnu-build-system))
  77. (define unpack (assoc-ref %standard-phases 'unpack))
  78. (define compressors '(("gzip" . "gz")
  79. ("xz" . "xz")
  80. ("bzip2" . "bz2")
  81. (#f . #f)))
  82. (for-each
  83. (match-lambda
  84. ((comp . ext)
  85. (unless (network-reachable?) (test-skip 1)) ;for bootstrap binaries
  86. (test-equal (string-append "gnu-build-system unpack phase, "
  87. "single file (compression: "
  88. (if comp comp "None") ")")
  89. "expected text"
  90. (let*-values
  91. (((name) "test")
  92. ((compressed-name) (if ext
  93. (string-append name "." ext)
  94. name))
  95. ((file hash) (test-file %store compressed-name "expected text")))
  96. (call-with-temporary-directory
  97. (lambda (dir)
  98. (with-directory-excursion dir
  99. (unpack #:source file)
  100. (call-with-input-file name get-string-all))))))))
  101. compressors)
  102. ;;;
  103. ;;; Test the sanity-check phase of the Python build system.
  104. ;;;
  105. (define* (make-python-dummy name #:key (setup-py-extra "")
  106. (init-py "") (use-setuptools? #t))
  107. (dummy-package (string-append "python-dummy-" name)
  108. (version "0.1")
  109. (build-system python-build-system)
  110. (arguments
  111. `(#:tests? #f
  112. #:use-setuptools? ,use-setuptools?
  113. #:phases
  114. (modify-phases %standard-phases
  115. (replace 'unpack
  116. (lambda _
  117. (mkdir-p "dummy")
  118. (with-output-to-file "dummy/__init__.py"
  119. (lambda _
  120. (display ,init-py)))
  121. (with-output-to-file "setup.py"
  122. (lambda _
  123. (format #t "\
  124. ~a
  125. setup(
  126. name='dummy-~a',
  127. version='0.1',
  128. packages=['dummy'],
  129. ~a
  130. )"
  131. (if ,use-setuptools?
  132. "from setuptools import setup"
  133. "from distutils.core import setup")
  134. ,name ,setup-py-extra))))))))))
  135. (define python-dummy-ok
  136. (make-python-dummy "ok"))
  137. ;; distutil won't install any metadata, so make sure our script does not fail
  138. ;; on a otherwise fine package.
  139. (define python-dummy-no-setuptools
  140. (make-python-dummy
  141. "no-setuptools" #:use-setuptools? #f))
  142. (define python-dummy-fail-requirements
  143. (make-python-dummy "fail-requirements"
  144. #:setup-py-extra "install_requires=['nonexistent'],"))
  145. (define python-dummy-fail-import
  146. (make-python-dummy "fail-import" #:init-py "import nonexistent"))
  147. (define python-dummy-fail-console-script
  148. (make-python-dummy "fail-console-script"
  149. #:setup-py-extra (string-append "entry_points={'console_scripts': "
  150. "['broken = dummy:nonexistent']},")))
  151. (define (check-build-success store p)
  152. (unless store (test-skip 1))
  153. (test-assert (string-append "python-build-system: " (package-name p))
  154. (let* ((drv (package-derivation store p)))
  155. (build-derivations store (list drv)))))
  156. (define (check-build-failure store p)
  157. (unless store (test-skip 1))
  158. (test-assert (string-append "python-build-system: " (package-name p))
  159. (let ((drv (package-derivation store p)))
  160. (guard (c ((store-protocol-error? c)
  161. (pk 'failure c #t))) ;good!
  162. (build-derivations store (list drv))
  163. #f)))) ;bad: it should have failed
  164. (with-external-store store
  165. (for-each (lambda (p) (check-build-success store p))
  166. (list
  167. python-dummy-ok
  168. python-dummy-no-setuptools))
  169. (for-each (lambda (p) (check-build-failure store p))
  170. (list
  171. python-dummy-fail-requirements
  172. python-dummy-fail-import
  173. python-dummy-fail-console-script)))
  174. (test-end "builders")