scripts-build.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-scripts-build)
  19. #:use-module (guix tests)
  20. #:use-module (guix store)
  21. #:use-module (guix packages)
  22. #:use-module (guix git-download)
  23. #:use-module (guix scripts build)
  24. #:use-module (guix ui)
  25. #:use-module (guix utils)
  26. #:use-module (guix git)
  27. #:use-module (gnu packages)
  28. #:use-module (gnu packages base)
  29. #:use-module (gnu packages busybox)
  30. #:use-module (ice-9 match)
  31. #:use-module (srfi srfi-64))
  32. (test-begin "scripts-build")
  33. (test-assert "options->transformation, no transformations"
  34. (let ((p (dummy-package "foo"))
  35. (t (options->transformation '())))
  36. (with-store store
  37. (eq? (t store p) p))))
  38. (test-assert "options->transformation, with-source"
  39. ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm' source should
  40. ;; be applicable.
  41. (let* ((p (dummy-package "guix.scm"))
  42. (s (search-path %load-path "guix.scm"))
  43. (t (options->transformation `((with-source . ,s)))))
  44. (with-store store
  45. (let ((new (t store p)))
  46. (and (not (eq? new p))
  47. (string=? (package-source new)
  48. (add-to-store store "guix.scm" #t
  49. "sha256" s)))))))
  50. (test-assert "options->transformation, with-source, replacement"
  51. ;; Same, but this time the original package has a 'replacement' field. We
  52. ;; expect that replacement to be set to #f in the new package.
  53. (let* ((p (dummy-package "guix.scm" (replacement coreutils)))
  54. (s (search-path %load-path "guix.scm"))
  55. (t (options->transformation `((with-source . ,s)))))
  56. (with-store store
  57. (let ((new (t store p)))
  58. (and (not (eq? new p))
  59. (string=? (package-source new)
  60. (add-to-store store "guix.scm" #t "sha256" s))
  61. (not (package-replacement new)))))))
  62. (test-assert "options->transformation, with-source, with version"
  63. ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source
  64. ;; should be applicable, and its version should be extracted.
  65. (let ((p (dummy-package "foo"))
  66. (s (search-path %load-path "guix.scm")))
  67. (call-with-temporary-directory
  68. (lambda (directory)
  69. (let* ((f (string-append directory "/foo-42.0.tar.gz"))
  70. (t (options->transformation `((with-source . ,f)))))
  71. (copy-file s f)
  72. (with-store store
  73. (let ((new (t store p)))
  74. (and (not (eq? new p))
  75. (string=? (package-name new) (package-name p))
  76. (string=? (package-version new) "42.0")
  77. (string=? (package-source new)
  78. (add-to-store store (basename f) #t
  79. "sha256" f))))))))))
  80. (test-assert "options->transformation, with-source, no matches"
  81. ;; When a transformation in not applicable, a warning must be raised.
  82. (let* ((p (dummy-package "foobar"))
  83. (s (search-path %load-path "guix.scm"))
  84. (t (options->transformation `((with-source . ,s)))))
  85. (with-store store
  86. (let* ((port (open-output-string))
  87. (new (parameterize ((guix-warning-port port))
  88. (t store p))))
  89. (and (eq? new p)
  90. (string-contains (get-output-string port)
  91. "had no effect"))))))
  92. (test-assert "options->transformation, with-source, PKG=URI"
  93. (let* ((p (dummy-package "foo"))
  94. (s (search-path %load-path "guix.scm"))
  95. (f (string-append "foo=" s))
  96. (t (options->transformation `((with-source . ,f)))))
  97. (with-store store
  98. (let ((new (t store p)))
  99. (and (not (eq? new p))
  100. (string=? (package-name new) (package-name p))
  101. (string=? (package-version new)
  102. (package-version p))
  103. (string=? (package-source new)
  104. (add-to-store store (basename s) #t
  105. "sha256" s)))))))
  106. (test-assert "options->transformation, with-source, PKG@VER=URI"
  107. (let* ((p (dummy-package "foo"))
  108. (s (search-path %load-path "guix.scm"))
  109. (f (string-append "foo@42.0=" s))
  110. (t (options->transformation `((with-source . ,f)))))
  111. (with-store store
  112. (let ((new (t store p)))
  113. (and (not (eq? new p))
  114. (string=? (package-name new) (package-name p))
  115. (string=? (package-version new) "42.0")
  116. (string=? (package-source new)
  117. (add-to-store store (basename s) #t
  118. "sha256" s)))))))
  119. (test-assert "options->transformation, with-input"
  120. (let* ((p (dummy-package "guix.scm"
  121. (inputs `(("foo" ,(specification->package "coreutils"))
  122. ("bar" ,(specification->package "grep"))
  123. ("baz" ,(dummy-package "chbouib"
  124. (native-inputs `(("x" ,grep)))))))))
  125. (t (options->transformation '((with-input . "coreutils=busybox")
  126. (with-input . "grep=findutils")))))
  127. (with-store store
  128. (let ((new (t store p)))
  129. (and (not (eq? new p))
  130. (match (package-inputs new)
  131. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  132. (and (string=? (package-full-name dep1)
  133. (package-full-name busybox))
  134. (string=? (package-full-name dep2)
  135. (package-full-name findutils))
  136. (string=? (package-name dep3) "chbouib")
  137. (match (package-native-inputs dep3)
  138. ((("x" dep))
  139. (string=? (package-full-name dep)
  140. (package-full-name findutils))))))))))))
  141. (test-assert "options->transformation, with-graft"
  142. (let* ((p (dummy-package "guix.scm"
  143. (inputs `(("foo" ,grep)
  144. ("bar" ,(dummy-package "chbouib"
  145. (native-inputs `(("x" ,grep)))))))))
  146. (t (options->transformation '((with-graft . "grep=findutils")))))
  147. (with-store store
  148. (let ((new (t store p)))
  149. (and (not (eq? new p))
  150. (match (package-inputs new)
  151. ((("foo" dep1) ("bar" dep2))
  152. (and (string=? (package-full-name dep1)
  153. (package-full-name grep))
  154. (eq? (package-replacement dep1) findutils)
  155. (string=? (package-name dep2) "chbouib")
  156. (match (package-native-inputs dep2)
  157. ((("x" dep))
  158. (eq? (package-replacement dep) findutils)))))))))))
  159. (test-equal "options->transformation, with-branch"
  160. (git-checkout (url "https://example.org")
  161. (branch "devel")
  162. (recursive? #t))
  163. (let* ((p (dummy-package "guix.scm"
  164. (inputs `(("foo" ,grep)
  165. ("bar" ,(dummy-package "chbouib"
  166. (source (origin
  167. (method git-fetch)
  168. (uri (git-reference
  169. (url "https://example.org")
  170. (commit "cabba9e")))
  171. (sha256 #f)))))))))
  172. (t (options->transformation '((with-branch . "chbouib=devel")))))
  173. (with-store store
  174. (let ((new (t store p)))
  175. (and (not (eq? new p))
  176. (match (package-inputs new)
  177. ((("foo" dep1) ("bar" dep2))
  178. (and (string=? (package-full-name dep1)
  179. (package-full-name grep))
  180. (string=? (package-name dep2) "chbouib")
  181. (package-source dep2)))))))))
  182. (test-equal "options->transformation, with-commit"
  183. (git-checkout (url "https://example.org")
  184. (commit "abcdef")
  185. (recursive? #t))
  186. (let* ((p (dummy-package "guix.scm"
  187. (inputs `(("foo" ,grep)
  188. ("bar" ,(dummy-package "chbouib"
  189. (source (origin
  190. (method git-fetch)
  191. (uri (git-reference
  192. (url "https://example.org")
  193. (commit "cabba9e")))
  194. (sha256 #f)))))))))
  195. (t (options->transformation '((with-commit . "chbouib=abcdef")))))
  196. (with-store store
  197. (let ((new (t store p)))
  198. (and (not (eq? new p))
  199. (match (package-inputs new)
  200. ((("foo" dep1) ("bar" dep2))
  201. (and (string=? (package-full-name dep1)
  202. (package-full-name grep))
  203. (string=? (package-name dep2) "chbouib")
  204. (package-source dep2)))))))))
  205. (test-equal "options->transformation, with-git-url"
  206. (let ((source (git-checkout (url "https://example.org")
  207. (recursive? #t))))
  208. (list source source))
  209. (let* ((p (dummy-package "guix.scm"
  210. (inputs `(("foo" ,grep)
  211. ("bar" ,(dummy-package "chbouib"
  212. (native-inputs `(("x" ,grep)))))))))
  213. (t (options->transformation '((with-git-url . "grep=https://example.org")))))
  214. (with-store store
  215. (let ((new (t store p)))
  216. (and (not (eq? new p))
  217. (match (package-inputs new)
  218. ((("foo" dep1) ("bar" dep2))
  219. (and (string=? (package-full-name dep1)
  220. (package-full-name grep))
  221. (string=? (package-name dep2) "chbouib")
  222. (match (package-native-inputs dep2)
  223. ((("x" dep3))
  224. (map package-source (list dep1 dep3))))))))))))
  225. (test-equal "options->transformation, with-git-url + with-branch"
  226. ;; Combine the two options and make sure the 'with-branch' transformation
  227. ;; comes after the 'with-git-url' transformation.
  228. (let ((source (git-checkout (url "https://example.org")
  229. (branch "BRANCH")
  230. (recursive? #t))))
  231. (list source source))
  232. (let* ((p (dummy-package "guix.scm"
  233. (inputs `(("foo" ,grep)
  234. ("bar" ,(dummy-package "chbouib"
  235. (native-inputs `(("x" ,grep)))))))))
  236. (t (options->transformation
  237. (reverse '((with-git-url
  238. . "grep=https://example.org")
  239. (with-branch . "grep=BRANCH"))))))
  240. (with-store store
  241. (let ((new (t store p)))
  242. (and (not (eq? new p))
  243. (match (package-inputs new)
  244. ((("foo" dep1) ("bar" dep2))
  245. (and (string=? (package-name dep1) "grep")
  246. (string=? (package-name dep2) "chbouib")
  247. (match (package-native-inputs dep2)
  248. ((("x" dep3))
  249. (map package-source (list dep1 dep3))))))))))))
  250. (test-end)