builders.scm 6.6 KB

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