scripts-build.scm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017, 2019, 2020 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 derivations)
  22. #:use-module (guix packages)
  23. #:use-module (guix git-download)
  24. #:use-module (guix scripts build)
  25. #:use-module (guix ui)
  26. #:use-module (guix utils)
  27. #:use-module (guix git)
  28. #:use-module (gnu packages)
  29. #:use-module (gnu packages base)
  30. #:use-module (gnu packages busybox)
  31. #:use-module (ice-9 match)
  32. #:use-module (srfi srfi-64))
  33. (test-begin "scripts-build")
  34. (test-assert "options->transformation, no transformations"
  35. (let ((p (dummy-package "foo"))
  36. (t (options->transformation '())))
  37. (with-store store
  38. (eq? (t store p) p))))
  39. (test-assert "options->transformation, with-source"
  40. ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm' source should
  41. ;; be applicable.
  42. (let* ((p (dummy-package "guix.scm"))
  43. (s (search-path %load-path "guix.scm"))
  44. (t (options->transformation `((with-source . ,s)))))
  45. (with-store store
  46. (let ((new (t store p)))
  47. (and (not (eq? new p))
  48. (string=? (package-source new)
  49. (add-to-store store "guix.scm" #t
  50. "sha256" s)))))))
  51. (test-assert "options->transformation, with-source, replacement"
  52. ;; Same, but this time the original package has a 'replacement' field. We
  53. ;; expect that replacement to be set to #f in the new package.
  54. (let* ((p (dummy-package "guix.scm" (replacement coreutils)))
  55. (s (search-path %load-path "guix.scm"))
  56. (t (options->transformation `((with-source . ,s)))))
  57. (with-store store
  58. (let ((new (t store p)))
  59. (and (not (eq? new p))
  60. (string=? (package-source new)
  61. (add-to-store store "guix.scm" #t "sha256" s))
  62. (not (package-replacement new)))))))
  63. (test-assert "options->transformation, with-source, with version"
  64. ;; Our pseudo-package is called 'guix.scm' so the 'guix.scm-2.0' source
  65. ;; should be applicable, and its version should be extracted.
  66. (let ((p (dummy-package "foo"))
  67. (s (search-path %load-path "guix.scm")))
  68. (call-with-temporary-directory
  69. (lambda (directory)
  70. (let* ((f (string-append directory "/foo-42.0.tar.gz"))
  71. (t (options->transformation `((with-source . ,f)))))
  72. (copy-file s f)
  73. (with-store store
  74. (let ((new (t store p)))
  75. (and (not (eq? new p))
  76. (string=? (package-name new) (package-name p))
  77. (string=? (package-version new) "42.0")
  78. (string=? (package-source new)
  79. (add-to-store store (basename f) #t
  80. "sha256" f))))))))))
  81. (test-assert "options->transformation, with-source, no matches"
  82. ;; When a transformation in not applicable, a warning must be raised.
  83. (let* ((p (dummy-package "foobar"))
  84. (s (search-path %load-path "guix.scm"))
  85. (t (options->transformation `((with-source . ,s)))))
  86. (with-store store
  87. (let* ((port (open-output-string))
  88. (new (parameterize ((guix-warning-port port))
  89. (t store p))))
  90. (and (eq? new p)
  91. (string-contains (get-output-string port)
  92. "had no effect"))))))
  93. (test-assert "options->transformation, with-source, PKG=URI"
  94. (let* ((p (dummy-package "foo"))
  95. (s (search-path %load-path "guix.scm"))
  96. (f (string-append "foo=" s))
  97. (t (options->transformation `((with-source . ,f)))))
  98. (with-store store
  99. (let ((new (t store p)))
  100. (and (not (eq? new p))
  101. (string=? (package-name new) (package-name p))
  102. (string=? (package-version new)
  103. (package-version p))
  104. (string=? (package-source new)
  105. (add-to-store store (basename s) #t
  106. "sha256" s)))))))
  107. (test-assert "options->transformation, with-source, PKG@VER=URI"
  108. (let* ((p (dummy-package "foo"))
  109. (s (search-path %load-path "guix.scm"))
  110. (f (string-append "foo@42.0=" s))
  111. (t (options->transformation `((with-source . ,f)))))
  112. (with-store store
  113. (let ((new (t store p)))
  114. (and (not (eq? new p))
  115. (string=? (package-name new) (package-name p))
  116. (string=? (package-version new) "42.0")
  117. (string=? (package-source new)
  118. (add-to-store store (basename s) #t
  119. "sha256" s)))))))
  120. (test-assert "options->transformation, with-input"
  121. (let* ((p (dummy-package "guix.scm"
  122. (inputs `(("foo" ,(specification->package "coreutils"))
  123. ("bar" ,(specification->package "grep"))
  124. ("baz" ,(dummy-package "chbouib"
  125. (native-inputs `(("x" ,grep)))))))))
  126. (t (options->transformation '((with-input . "coreutils=busybox")
  127. (with-input . "grep=findutils")))))
  128. (with-store store
  129. (let ((new (t store p)))
  130. (and (not (eq? new p))
  131. (match (package-inputs new)
  132. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  133. (and (string=? (package-full-name dep1)
  134. (package-full-name busybox))
  135. (string=? (package-full-name dep2)
  136. (package-full-name findutils))
  137. (string=? (package-name dep3) "chbouib")
  138. (match (package-native-inputs dep3)
  139. ((("x" dep))
  140. (string=? (package-full-name dep)
  141. (package-full-name findutils))))))))))))
  142. (test-assert "options->transformation, with-graft"
  143. (let* ((p (dummy-package "guix.scm"
  144. (inputs `(("foo" ,grep)
  145. ("bar" ,(dummy-package "chbouib"
  146. (native-inputs `(("x" ,grep)))))))))
  147. (t (options->transformation '((with-graft . "grep=findutils")))))
  148. (with-store store
  149. (let ((new (t store p)))
  150. (and (not (eq? new p))
  151. (match (package-inputs new)
  152. ((("foo" dep1) ("bar" dep2))
  153. (and (string=? (package-full-name dep1)
  154. (package-full-name grep))
  155. (string=? (package-full-name (package-replacement dep1))
  156. (package-full-name findutils))
  157. (string=? (package-name dep2) "chbouib")
  158. (match (package-native-inputs dep2)
  159. ((("x" dep))
  160. (with-store store
  161. (string=? (derivation-file-name
  162. (package-derivation store findutils))
  163. (derivation-file-name
  164. (package-derivation store dep))))))))))))))
  165. (test-equal "options->transformation, with-branch"
  166. (git-checkout (url "https://example.org")
  167. (branch "devel")
  168. (recursive? #t))
  169. (let* ((p (dummy-package "guix.scm"
  170. (inputs `(("foo" ,grep)
  171. ("bar" ,(dummy-package "chbouib"
  172. (source (origin
  173. (method git-fetch)
  174. (uri (git-reference
  175. (url "https://example.org")
  176. (commit "cabba9e")))
  177. (sha256 #f)))))))))
  178. (t (options->transformation '((with-branch . "chbouib=devel")))))
  179. (with-store store
  180. (let ((new (t store p)))
  181. (and (not (eq? new p))
  182. (match (package-inputs new)
  183. ((("foo" dep1) ("bar" dep2))
  184. (and (string=? (package-full-name dep1)
  185. (package-full-name grep))
  186. (string=? (package-name dep2) "chbouib")
  187. (package-source dep2)))))))))
  188. (test-equal "options->transformation, with-commit"
  189. (git-checkout (url "https://example.org")
  190. (commit "abcdef")
  191. (recursive? #t))
  192. (let* ((p (dummy-package "guix.scm"
  193. (inputs `(("foo" ,grep)
  194. ("bar" ,(dummy-package "chbouib"
  195. (source (origin
  196. (method git-fetch)
  197. (uri (git-reference
  198. (url "https://example.org")
  199. (commit "cabba9e")))
  200. (sha256 #f)))))))))
  201. (t (options->transformation '((with-commit . "chbouib=abcdef")))))
  202. (with-store store
  203. (let ((new (t store p)))
  204. (and (not (eq? new p))
  205. (match (package-inputs new)
  206. ((("foo" dep1) ("bar" dep2))
  207. (and (string=? (package-full-name dep1)
  208. (package-full-name grep))
  209. (string=? (package-name dep2) "chbouib")
  210. (package-source dep2)))))))))
  211. (test-equal "options->transformation, with-git-url"
  212. (let ((source (git-checkout (url "https://example.org")
  213. (recursive? #t))))
  214. (list source source))
  215. (let* ((p (dummy-package "guix.scm"
  216. (inputs `(("foo" ,grep)
  217. ("bar" ,(dummy-package "chbouib"
  218. (native-inputs `(("x" ,grep)))))))))
  219. (t (options->transformation '((with-git-url . "grep=https://example.org")))))
  220. (with-store store
  221. (let ((new (t store p)))
  222. (and (not (eq? new p))
  223. (match (package-inputs new)
  224. ((("foo" dep1) ("bar" dep2))
  225. (and (string=? (package-full-name dep1)
  226. (package-full-name grep))
  227. (string=? (package-name dep2) "chbouib")
  228. (match (package-native-inputs dep2)
  229. ((("x" dep3))
  230. (map package-source (list dep1 dep3))))))))))))
  231. (test-equal "options->transformation, with-git-url + with-branch"
  232. ;; Combine the two options and make sure the 'with-branch' transformation
  233. ;; comes after the 'with-git-url' transformation.
  234. (let ((source (git-checkout (url "https://example.org")
  235. (branch "BRANCH")
  236. (recursive? #t))))
  237. (list source source))
  238. (let* ((p (dummy-package "guix.scm"
  239. (inputs `(("foo" ,grep)
  240. ("bar" ,(dummy-package "chbouib"
  241. (native-inputs `(("x" ,grep)))))))))
  242. (t (options->transformation
  243. (reverse '((with-git-url
  244. . "grep=https://example.org")
  245. (with-branch . "grep=BRANCH"))))))
  246. (with-store store
  247. (let ((new (t store p)))
  248. (and (not (eq? new p))
  249. (match (package-inputs new)
  250. ((("foo" dep1) ("bar" dep2))
  251. (and (string=? (package-name dep1) "grep")
  252. (string=? (package-name dep2) "chbouib")
  253. (match (package-native-inputs dep2)
  254. ((("x" dep3))
  255. (map package-source (list dep1 dep3))))))))))))
  256. (test-assert "options->transformation, without-tests"
  257. (let* ((dep (dummy-package "dep"))
  258. (p (dummy-package "foo"
  259. (inputs `(("dep" ,dep)))))
  260. (t (options->transformation '((without-tests . "dep")
  261. (without-tests . "tar")))))
  262. (with-store store
  263. (let ((new (t store p)))
  264. (match (bag-direct-inputs (package->bag new))
  265. ((("dep" dep) ("tar" tar) _ ...)
  266. ;; TODO: Check whether TAR has #:tests? #f when transformations
  267. ;; apply to implicit inputs.
  268. (equal? (package-arguments dep)
  269. '(#:tests? #f))))))))
  270. (test-end)