packages.scm 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 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-packages)
  19. #:use-module (guix tests)
  20. #:use-module (guix store)
  21. #:use-module (guix monads)
  22. #:use-module (guix grafts)
  23. #:use-module ((guix gexp) #:select (local-file local-file-file))
  24. #:use-module ((guix utils)
  25. ;; Rename the 'location' binding to allow proper syntax
  26. ;; matching when setting the 'location' field of a package.
  27. #:renamer (lambda (name)
  28. (cond ((eq? name 'location) 'make-location)
  29. (else name))))
  30. #:use-module (gcrypt hash)
  31. #:use-module (guix derivations)
  32. #:use-module (guix packages)
  33. #:use-module (guix grafts)
  34. #:use-module (guix search-paths)
  35. #:use-module (guix build-system)
  36. #:use-module (guix build-system trivial)
  37. #:use-module (guix build-system gnu)
  38. #:use-module (guix profiles)
  39. #:use-module (guix scripts package)
  40. #:use-module (gnu packages)
  41. #:use-module (gnu packages base)
  42. #:use-module (gnu packages guile)
  43. #:use-module (gnu packages bootstrap)
  44. #:use-module (gnu packages version-control)
  45. #:use-module (gnu packages xml)
  46. #:use-module (srfi srfi-1)
  47. #:use-module (srfi srfi-26)
  48. #:use-module (srfi srfi-34)
  49. #:use-module (srfi srfi-35)
  50. #:use-module (srfi srfi-64)
  51. #:use-module (rnrs io ports)
  52. #:use-module (ice-9 vlist)
  53. #:use-module (ice-9 regex)
  54. #:use-module (ice-9 match))
  55. ;; Test the high-level packaging layer.
  56. (define %store
  57. (open-connection-for-tests))
  58. ;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
  59. ;; can trigger builds early.)
  60. (%graft? #f)
  61. (test-begin "packages")
  62. (test-assert "printer with location"
  63. (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
  64. (with-output-to-string
  65. (lambda ()
  66. (write
  67. (dummy-package "foo"
  68. (location (make-location "foo.scm" 42 7))))))))
  69. (test-assert "printer without location"
  70. (string-match "^#<package foo@0 [[:xdigit:]]+>$"
  71. (with-output-to-string
  72. (lambda ()
  73. (write
  74. (dummy-package "foo" (location #f)))))))
  75. (test-assert "hidden-package"
  76. (and (hidden-package? (hidden-package (dummy-package "foo")))
  77. (not (hidden-package? (dummy-package "foo")))))
  78. (test-assert "package-superseded"
  79. (let* ((new (dummy-package "bar"))
  80. (old (deprecated-package "foo" new)))
  81. (and (eq? (package-superseded old) new)
  82. (mock ((gnu packages) find-best-packages-by-name (const (list old)))
  83. (specification->package "foo")
  84. (and (eq? new (specification->package "foo"))
  85. (eq? new (specification->package+output "foo")))))))
  86. (test-assert "transaction-upgrade-entry, zero upgrades"
  87. (let* ((old (dummy-package "foo" (version "1")))
  88. (tx (mock ((gnu packages) find-best-packages-by-name
  89. (const '()))
  90. ((@@ (guix scripts package) transaction-upgrade-entry)
  91. (manifest-entry
  92. (inherit (package->manifest-entry old))
  93. (item (string-append (%store-prefix) "/"
  94. (make-string 32 #\e) "-foo-1")))
  95. (manifest-transaction)))))
  96. (manifest-transaction-null? tx)))
  97. (test-assert "transaction-upgrade-entry, one upgrade"
  98. (let* ((old (dummy-package "foo" (version "1")))
  99. (new (dummy-package "foo" (version "2")))
  100. (tx (mock ((gnu packages) find-best-packages-by-name
  101. (const (list new)))
  102. ((@@ (guix scripts package) transaction-upgrade-entry)
  103. (manifest-entry
  104. (inherit (package->manifest-entry old))
  105. (item (string-append (%store-prefix) "/"
  106. (make-string 32 #\e) "-foo-1")))
  107. (manifest-transaction)))))
  108. (and (match (manifest-transaction-install tx)
  109. ((($ <manifest-entry> "foo" "2" "out" item))
  110. (eq? item new)))
  111. (null? (manifest-transaction-remove tx)))))
  112. (test-assert "transaction-upgrade-entry, superseded package"
  113. (let* ((old (dummy-package "foo" (version "1")))
  114. (new (dummy-package "bar" (version "2")))
  115. (dep (deprecated-package "foo" new))
  116. (tx (mock ((gnu packages) find-best-packages-by-name
  117. (const (list dep)))
  118. ((@@ (guix scripts package) transaction-upgrade-entry)
  119. (manifest-entry
  120. (inherit (package->manifest-entry old))
  121. (item (string-append (%store-prefix) "/"
  122. (make-string 32 #\e) "-foo-1")))
  123. (manifest-transaction)))))
  124. (and (match (manifest-transaction-install tx)
  125. ((($ <manifest-entry> "bar" "2" "out" item))
  126. (eq? item new)))
  127. (match (manifest-transaction-remove tx)
  128. (((? manifest-pattern? pattern))
  129. (and (string=? (manifest-pattern-name pattern) "foo")
  130. (string=? (manifest-pattern-version pattern) "1")
  131. (string=? (manifest-pattern-output pattern) "out")))))))
  132. (test-assert "package-field-location"
  133. (let ()
  134. (define (goto port line column)
  135. (unless (and (= (port-column port) (- column 1))
  136. (= (port-line port) (- line 1)))
  137. (unless (eof-object? (get-char port))
  138. (goto port line column))))
  139. (define read-at
  140. (match-lambda
  141. (($ <location> file line column)
  142. (call-with-input-file (search-path %load-path file)
  143. (lambda (port)
  144. (goto port line column)
  145. (read port))))))
  146. ;; Until Guile 2.0.6 included, source properties were added only to pairs.
  147. ;; Thus, check against both VALUE and (FIELD VALUE).
  148. (and (member (read-at (package-field-location %bootstrap-guile 'name))
  149. (let ((name (package-name %bootstrap-guile)))
  150. (list name `(name ,name))))
  151. (member (read-at (package-field-location %bootstrap-guile 'version))
  152. (let ((version (package-version %bootstrap-guile)))
  153. (list version `(version ,version))))
  154. (not (package-field-location %bootstrap-guile 'does-not-exist)))))
  155. ;; Make sure we don't change the file name to an absolute file name.
  156. (test-equal "package-field-location, relative file name"
  157. (location-file (package-location %bootstrap-guile))
  158. (with-fluids ((%file-port-name-canonicalization 'absolute))
  159. (location-file (package-field-location %bootstrap-guile 'version))))
  160. (test-assert "package-transitive-inputs"
  161. (let* ((a (dummy-package "a"))
  162. (b (dummy-package "b"
  163. (propagated-inputs `(("a" ,a)))))
  164. (c (dummy-package "c"
  165. (inputs `(("a" ,a)))))
  166. (d (dummy-package "d"
  167. (propagated-inputs `(("x" "something.drv")))))
  168. (e (dummy-package "e"
  169. (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
  170. (and (null? (package-transitive-inputs a))
  171. (equal? `(("a" ,a)) (package-transitive-inputs b))
  172. (equal? `(("a" ,a)) (package-transitive-inputs c))
  173. (equal? (package-propagated-inputs d)
  174. (package-transitive-inputs d))
  175. (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
  176. ("a" ,a) ("x" "something.drv"))
  177. (pk 'x (package-transitive-inputs e))))))
  178. (test-assert "package-transitive-inputs, no duplicates"
  179. (let* ((a (dummy-package "a"))
  180. (b (dummy-package "b"
  181. (inputs `(("a+" ,a)))
  182. (native-inputs `(("a*" ,a)))
  183. (propagated-inputs `(("a" ,a)))))
  184. (c (dummy-package "c"
  185. (propagated-inputs `(("b" ,b)))))
  186. (d (dummy-package "d"
  187. (inputs `(("a" ,a) ("c" ,c)))))
  188. (e (dummy-package "e"
  189. (inputs `(("b" ,b) ("c" ,c))))))
  190. (and (null? (package-transitive-inputs a))
  191. (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
  192. (package-transitive-inputs b))
  193. (equal? `(("b" ,b) ("a" ,a))
  194. (package-transitive-inputs c))
  195. (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
  196. (package-transitive-inputs d))
  197. (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
  198. (package-transitive-inputs e))))) ;ditto
  199. (test-equal "package-transitive-supported-systems"
  200. '(("x" "y" "z") ;a
  201. ("x" "y") ;b
  202. ("y") ;c
  203. ("y") ;d
  204. ("y")) ;e
  205. ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
  206. ;; doesn't restrict the set of supported systems.
  207. (let* ((a (dummy-package "a"
  208. (build-system trivial-build-system)
  209. (supported-systems '("x" "y" "z"))))
  210. (b (dummy-package "b"
  211. (build-system trivial-build-system)
  212. (supported-systems '("x" "y"))
  213. (inputs `(("a" ,a)))))
  214. (c (dummy-package "c"
  215. (build-system trivial-build-system)
  216. (supported-systems '("y" "z"))
  217. (inputs `(("b" ,b)))))
  218. (d (dummy-package "d"
  219. (build-system trivial-build-system)
  220. (supported-systems '("x" "y" "z"))
  221. (inputs `(("b" ,b) ("c" ,c)))))
  222. (e (dummy-package "e"
  223. (build-system trivial-build-system)
  224. (supported-systems '("x" "y" "z"))
  225. (inputs `(("d" ,d))))))
  226. (list (package-transitive-supported-systems a)
  227. (package-transitive-supported-systems b)
  228. (package-transitive-supported-systems c)
  229. (package-transitive-supported-systems d)
  230. (package-transitive-supported-systems e))))
  231. (test-assert "package-closure"
  232. (let-syntax ((dummy-package/no-implicit
  233. (syntax-rules ()
  234. ((_ name rest ...)
  235. (package
  236. (inherit (dummy-package name rest ...))
  237. (build-system trivial-build-system))))))
  238. (let* ((a (dummy-package/no-implicit "a"))
  239. (b (dummy-package/no-implicit "b"
  240. (propagated-inputs `(("a" ,a)))))
  241. (c (dummy-package/no-implicit "c"
  242. (inputs `(("a" ,a)))))
  243. (d (dummy-package/no-implicit "d"
  244. (native-inputs `(("b" ,b)))))
  245. (e (dummy-package/no-implicit "e"
  246. (inputs `(("c" ,c) ("d" ,d))))))
  247. (lset= eq?
  248. (list a b c d e)
  249. (package-closure (list e))
  250. (package-closure (list e d))
  251. (package-closure (list e c b))))))
  252. (test-equal "origin-actual-file-name"
  253. "foo-1.tar.gz"
  254. (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
  255. (origin-actual-file-name o)))
  256. (test-equal "origin-actual-file-name, file-name"
  257. "foo-1.tar.gz"
  258. (let ((o (dummy-origin
  259. (uri "http://www.example.com/tarball")
  260. (file-name "foo-1.tar.gz"))))
  261. (origin-actual-file-name o)))
  262. (let* ((o (dummy-origin))
  263. (u (dummy-origin))
  264. (i (dummy-origin))
  265. (a (dummy-package "a"))
  266. (b (dummy-package "b"
  267. (inputs `(("a" ,a) ("i" ,i)))))
  268. (c (package (inherit b) (source o)))
  269. (d (dummy-package "d"
  270. (build-system trivial-build-system)
  271. (source u) (inputs `(("c" ,c))))))
  272. (test-assert "package-direct-sources, no source"
  273. (null? (package-direct-sources a)))
  274. (test-equal "package-direct-sources, #f source"
  275. (list i)
  276. (package-direct-sources b))
  277. (test-equal "package-direct-sources, not input source"
  278. (list u)
  279. (package-direct-sources d))
  280. (test-assert "package-direct-sources"
  281. (let ((s (package-direct-sources c)))
  282. (and (= (length (pk 's-sources s)) 2)
  283. (member o s)
  284. (member i s))))
  285. (test-assert "package-transitive-sources"
  286. (let ((s (package-transitive-sources d)))
  287. (and (= (length (pk 'd-sources s)) 3)
  288. (member o s)
  289. (member i s)
  290. (member u s)))))
  291. (test-assert "transitive-input-references"
  292. (let* ((a (dummy-package "a"))
  293. (b (dummy-package "b"))
  294. (c (dummy-package "c"
  295. (inputs `(("a" ,a)))
  296. (propagated-inputs `(("boo" ,b)))))
  297. (d (dummy-package "d"
  298. (inputs `(("c*" ,c)))))
  299. (keys (map (match-lambda
  300. (('assoc-ref 'l key)
  301. key))
  302. (pk 'refs (transitive-input-references
  303. 'l (package-inputs d))))))
  304. (and (= (length keys) 2)
  305. (member "c*" keys)
  306. (member "boo" keys))))
  307. (test-equal "package-transitive-supported-systems, implicit inputs"
  308. %supported-systems
  309. ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
  310. ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
  311. (let ((p (dummy-package "foo"
  312. (build-system gnu-build-system)
  313. (supported-systems
  314. `("does-not-exist" "foobar" ,@%supported-systems)))))
  315. (package-transitive-supported-systems p)))
  316. (test-assert "supported-package?"
  317. (let ((p (dummy-package "foo"
  318. (build-system gnu-build-system)
  319. (supported-systems '("x86_64-linux" "does-not-exist")))))
  320. (and (supported-package? p "x86_64-linux")
  321. (not (supported-package? p "does-not-exist"))
  322. (not (supported-package? p "i686-linux")))))
  323. (test-skip (if (not %store) 8 0))
  324. (test-assert "package-source-derivation, file"
  325. (let* ((file (search-path %load-path "guix.scm"))
  326. (package (package (inherit (dummy-package "p"))
  327. (source file)))
  328. (source (package-source-derivation %store
  329. (package-source package))))
  330. (and (store-path? source)
  331. (valid-path? %store source)
  332. (equal? (call-with-input-file source get-bytevector-all)
  333. (call-with-input-file file get-bytevector-all)))))
  334. (test-assert "package-source-derivation, store path"
  335. (let* ((file (add-to-store %store "guix.scm" #t "sha256"
  336. (search-path %load-path "guix.scm")))
  337. (package (package (inherit (dummy-package "p"))
  338. (source file)))
  339. (source (package-source-derivation %store
  340. (package-source package))))
  341. (string=? file source)))
  342. (test-assert "package-source-derivation, indirect store path"
  343. (let* ((dir (add-to-store %store "guix-build" #t "sha256"
  344. (dirname (search-path %load-path
  345. "guix/build/utils.scm"))))
  346. (package (package (inherit (dummy-package "p"))
  347. (source (string-append dir "/utils.scm"))))
  348. (source (package-source-derivation %store
  349. (package-source package))))
  350. (and (direct-store-path? source)
  351. (string-suffix? "utils.scm" source))))
  352. (test-assert "package-source-derivation, local-file"
  353. (let* ((file (local-file "../guix/base32.scm"))
  354. (package (package (inherit (dummy-package "p"))
  355. (source file)))
  356. (source (package-source-derivation %store
  357. (package-source package))))
  358. (and (store-path? source)
  359. (string-suffix? "base32.scm" source)
  360. (valid-path? %store source)
  361. (equal? (call-with-input-file source get-bytevector-all)
  362. (call-with-input-file
  363. (search-path %load-path "guix/base32.scm")
  364. get-bytevector-all)))))
  365. (unless (network-reachable?) (test-skip 1))
  366. (test-equal "package-source-derivation, snippet"
  367. "OK"
  368. (let* ((source (bootstrap-origin
  369. (origin
  370. (inherit (bootstrap-guile-origin (%current-system)))
  371. (patch-inputs
  372. `(("tar" ,%bootstrap-coreutils&co)
  373. ("xz" ,%bootstrap-coreutils&co)
  374. ("patch" ,%bootstrap-coreutils&co)))
  375. (patch-guile %bootstrap-guile)
  376. (modules '((guix build utils)))
  377. (snippet '(begin
  378. ;; We end up in 'bin', because it's the first
  379. ;; directory, alphabetically. Not a very good
  380. ;; example but hey.
  381. (chmod "." #o777)
  382. (symlink "guile" "guile-rocks")
  383. (copy-recursively "../share/guile/2.0/scripts"
  384. "scripts")
  385. ;; Make sure '.file_list' can be created.
  386. (chmod ".." #o777))))))
  387. (package (package (inherit (dummy-package "with-snippet"))
  388. (source source)
  389. (build-system trivial-build-system)
  390. (inputs
  391. `(("tar" ,(search-bootstrap-binary "tar"
  392. (%current-system)))
  393. ("xz" ,(search-bootstrap-binary "xz"
  394. (%current-system)))))
  395. (arguments
  396. `(#:guile ,%bootstrap-guile
  397. #:modules ((guix build utils))
  398. #:builder
  399. (begin
  400. (use-modules (guix build utils))
  401. (let ((tar (assoc-ref %build-inputs "tar"))
  402. (xz (assoc-ref %build-inputs "xz"))
  403. (source (assoc-ref %build-inputs "source")))
  404. (invoke tar "xvf" source
  405. "--use-compress-program" xz)
  406. (unless (and (string=? "guile" (readlink "bin/guile-rocks"))
  407. (file-exists? "bin/scripts/compile.scm"))
  408. (error "the snippet apparently failed"))
  409. (let ((out (assoc-ref %outputs "out")))
  410. (call-with-output-file out
  411. (lambda (p)
  412. (display "OK" p))))
  413. #t))))))
  414. (drv (package-derivation %store package))
  415. (out (derivation->output-path drv)))
  416. (and (build-derivations %store (list (pk 'snippet-drv drv)))
  417. (call-with-input-file out get-string-all))))
  418. (test-assert "return value"
  419. (let ((drv (package-derivation %store (dummy-package "p"))))
  420. (and (derivation? drv)
  421. (file-exists? (derivation-file-name drv)))))
  422. (test-assert "package-output"
  423. (let* ((package (dummy-package "p"))
  424. (drv (package-derivation %store package)))
  425. (and (derivation? drv)
  426. (string=? (derivation->output-path drv)
  427. (package-output %store package "out")))))
  428. (test-assert "patch not found yields a run-time error"
  429. (guard (c ((condition-has-type? c &message)
  430. (and (string-contains (condition-message c)
  431. "does-not-exist.patch")
  432. (string-contains (condition-message c)
  433. "not found"))))
  434. (let ((p (package
  435. (inherit (dummy-package "p"))
  436. (source (origin
  437. (method (const #f))
  438. (uri "http://whatever")
  439. (patches
  440. (list (search-patch "does-not-exist.patch")))
  441. (sha256
  442. (base32
  443. "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
  444. (package-derivation %store p)
  445. #f)))
  446. (let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
  447. (test-equal "&package-input-error"
  448. (list dummy (current-module))
  449. (guard (c ((package-input-error? c)
  450. (list (package-error-package c)
  451. (package-error-invalid-input c))))
  452. (package-derivation %store dummy))))
  453. (test-assert "reference to non-existent output"
  454. ;; See <http://bugs.gnu.org/19630>.
  455. (parameterize ((%graft? #f))
  456. (let* ((dep (dummy-package "dep"))
  457. (p (dummy-package "p"
  458. (inputs `(("dep" ,dep "non-existent"))))))
  459. (guard (c ((derivation-missing-output-error? c)
  460. (and (string=? (derivation-missing-output c) "non-existent")
  461. (equal? (package-derivation %store dep)
  462. (derivation-error-derivation c)))))
  463. (package-derivation %store p)))))
  464. (test-assert "trivial"
  465. (let* ((p (package (inherit (dummy-package "trivial"))
  466. (build-system trivial-build-system)
  467. (source #f)
  468. (arguments
  469. `(#:guile ,%bootstrap-guile
  470. #:builder
  471. (begin
  472. (mkdir %output)
  473. (call-with-output-file (string-append %output "/test")
  474. (lambda (p)
  475. (display '(hello guix) p)))
  476. #t)))))
  477. (d (package-derivation %store p)))
  478. (and (build-derivations %store (list d))
  479. (let ((p (pk 'drv d (derivation->output-path d))))
  480. (equal? '(hello guix)
  481. (call-with-input-file (string-append p "/test") read))))))
  482. (test-assert "trivial with local file as input"
  483. (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
  484. (p (package (inherit (dummy-package "trivial-with-input-file"))
  485. (build-system trivial-build-system)
  486. (source #f)
  487. (arguments
  488. `(#:guile ,%bootstrap-guile
  489. #:builder (begin
  490. (copy-file (assoc-ref %build-inputs "input")
  491. %output)
  492. #t)))
  493. (inputs `(("input" ,i)))))
  494. (d (package-derivation %store p)))
  495. (and (build-derivations %store (list d))
  496. (let ((p (pk 'drv d (derivation->output-path d))))
  497. (equal? (call-with-input-file p get-bytevector-all)
  498. (call-with-input-file i get-bytevector-all))))))
  499. (test-assert "trivial with source"
  500. (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
  501. (p (package (inherit (dummy-package "trivial-with-source"))
  502. (build-system trivial-build-system)
  503. (source i)
  504. (arguments
  505. `(#:guile ,%bootstrap-guile
  506. #:builder (begin
  507. (copy-file (assoc-ref %build-inputs "source")
  508. %output)
  509. #t)))))
  510. (d (package-derivation %store p)))
  511. (and (build-derivations %store (list d))
  512. (let ((p (derivation->output-path d)))
  513. (equal? (call-with-input-file p get-bytevector-all)
  514. (call-with-input-file i get-bytevector-all))))))
  515. (test-assert "trivial with system-dependent input"
  516. (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
  517. (build-system trivial-build-system)
  518. (source #f)
  519. (arguments
  520. `(#:guile ,%bootstrap-guile
  521. #:modules ((guix build utils))
  522. #:builder
  523. (begin
  524. (use-modules (guix build utils))
  525. (let ((out (assoc-ref %outputs "out"))
  526. (bash (assoc-ref %build-inputs "bash")))
  527. (invoke bash "-c"
  528. (format #f "echo hello > ~a" out))))))
  529. (inputs `(("bash" ,(search-bootstrap-binary "bash"
  530. (%current-system)))))))
  531. (d (package-derivation %store p)))
  532. (and (build-derivations %store (list d))
  533. (let ((p (pk 'drv d (derivation->output-path d))))
  534. (eq? 'hello (call-with-input-file p read))))))
  535. (test-assert "trivial with #:allowed-references"
  536. (let* ((p (package
  537. (inherit (dummy-package "trivial"))
  538. (build-system trivial-build-system)
  539. (arguments
  540. `(#:guile ,%bootstrap-guile
  541. #:allowed-references (,%bootstrap-guile)
  542. #:builder
  543. (begin
  544. (mkdir %output)
  545. ;; The reference to itself isn't allowed so building it
  546. ;; should fail.
  547. (symlink %output (string-append %output "/self"))
  548. #t)))))
  549. (d (package-derivation %store p)))
  550. (guard (c ((store-protocol-error? c) #t))
  551. (build-derivations %store (list d))
  552. #f)))
  553. (test-assert "search paths"
  554. (let* ((p (make-prompt-tag "return-search-paths"))
  555. (s (build-system
  556. (name 'raw)
  557. (description "Raw build system with direct store access")
  558. (lower (lambda* (name #:key source inputs system target
  559. #:allow-other-keys)
  560. (bag
  561. (name name)
  562. (system system) (target target)
  563. (build-inputs inputs)
  564. (build
  565. (lambda* (store name inputs
  566. #:key outputs system search-paths)
  567. search-paths)))))))
  568. (x (list (search-path-specification
  569. (variable "GUILE_LOAD_PATH")
  570. (files '("share/guile/site/2.0")))
  571. (search-path-specification
  572. (variable "GUILE_LOAD_COMPILED_PATH")
  573. (files '("share/guile/site/2.0")))))
  574. (a (package (inherit (dummy-package "guile"))
  575. (build-system s)
  576. (native-search-paths x)))
  577. (b (package (inherit (dummy-package "guile-foo"))
  578. (build-system s)
  579. (inputs `(("guile" ,a)))))
  580. (c (package (inherit (dummy-package "guile-bar"))
  581. (build-system s)
  582. (inputs `(("guile" ,a)
  583. ("guile-foo" ,b))))))
  584. (let-syntax ((collect (syntax-rules ()
  585. ((_ body ...)
  586. (call-with-prompt p
  587. (lambda ()
  588. body ...)
  589. (lambda (k search-paths)
  590. search-paths))))))
  591. (and (null? (collect (package-derivation %store a)))
  592. (equal? x (collect (package-derivation %store b)))
  593. (equal? x (collect (package-derivation %store c)))))))
  594. (test-assert "package-transitive-native-search-paths"
  595. (let* ((sp (lambda (name)
  596. (list (search-path-specification
  597. (variable name)
  598. (files '("foo/bar"))))))
  599. (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
  600. (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
  601. (p2 (dummy-package "p2"
  602. (native-search-paths (sp "PATH2"))
  603. (inputs `(("p0" ,p0)))
  604. (propagated-inputs `(("p1" ,p1)))))
  605. (p3 (dummy-package "p3"
  606. (native-search-paths (sp "PATH3"))
  607. (native-inputs `(("p0" ,p0)))
  608. (propagated-inputs `(("p2" ,p2))))))
  609. (lset= string=?
  610. '("PATH1" "PATH2" "PATH3")
  611. (map search-path-specification-variable
  612. (package-transitive-native-search-paths p3)))))
  613. (test-assert "package-cross-derivation"
  614. (let ((drv (package-cross-derivation %store (dummy-package "p")
  615. "mips64el-linux-gnu")))
  616. (and (derivation? drv)
  617. (file-exists? (derivation-file-name drv)))))
  618. (test-assert "package-cross-derivation, trivial-build-system"
  619. (let ((p (package (inherit (dummy-package "p"))
  620. (build-system trivial-build-system)
  621. (arguments '(#:builder (exit 1))))))
  622. (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
  623. (derivation? drv))))
  624. (test-assert "package-cross-derivation, no cross builder"
  625. (let* ((b (build-system (inherit trivial-build-system)
  626. (lower (const #f))))
  627. (p (package (inherit (dummy-package "p"))
  628. (build-system b))))
  629. (guard (c ((package-cross-build-system-error? c)
  630. (eq? (package-error-package c) p)))
  631. (package-cross-derivation %store p "mips64el-linux-gnu")
  632. #f)))
  633. ;; XXX: The next two tests can trigger builds when the distro defines
  634. ;; replacements on core packages, so they're disable for lack of a better
  635. ;; solution.
  636. ;; (test-equal "package-derivation, direct graft"
  637. ;; (package-derivation %store gnu-make #:graft? #f)
  638. ;; (let ((p (package (inherit coreutils)
  639. ;; (replacement gnu-make))))
  640. ;; (package-derivation %store p #:graft? #t)))
  641. ;; (test-equal "package-cross-derivation, direct graft"
  642. ;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
  643. ;; #:graft? #f)
  644. ;; (let ((p (package (inherit coreutils)
  645. ;; (replacement gnu-make))))
  646. ;; (package-cross-derivation %store p "mips64el-linux-gnu"
  647. ;; #:graft? #t)))
  648. (test-assert "package-grafts, indirect grafts"
  649. (let* ((new (dummy-package "dep"
  650. (arguments '(#:implicit-inputs? #f))))
  651. (dep (package (inherit new) (version "0.0")))
  652. (dep* (package (inherit dep) (replacement new)))
  653. (dummy (dummy-package "dummy"
  654. (arguments '(#:implicit-inputs? #f))
  655. (inputs `(("dep" ,dep*))))))
  656. (equal? (package-grafts %store dummy)
  657. (list (graft
  658. (origin (package-derivation %store dep))
  659. (replacement (package-derivation %store new)))))))
  660. ;; XXX: This test would require building the cross toolchain just to see if it
  661. ;; needs grafting, which is obviously too expensive, and thus disabled.
  662. ;;
  663. ;; (test-assert "package-grafts, indirect grafts, cross"
  664. ;; (let* ((new (dummy-package "dep"
  665. ;; (arguments '(#:implicit-inputs? #f))))
  666. ;; (dep (package (inherit new) (version "0.0")))
  667. ;; (dep* (package (inherit dep) (replacement new)))
  668. ;; (dummy (dummy-package "dummy"
  669. ;; (arguments '(#:implicit-inputs? #f))
  670. ;; (inputs `(("dep" ,dep*)))))
  671. ;; (target "mips64el-linux-gnu"))
  672. ;; ;; XXX: There might be additional grafts, for instance if the distro
  673. ;; ;; defines replacements for core packages like Perl.
  674. ;; (member (graft
  675. ;; (origin (package-cross-derivation %store dep target))
  676. ;; (replacement
  677. ;; (package-cross-derivation %store new target)))
  678. ;; (package-grafts %store dummy #:target target))))
  679. (test-assert "package-grafts, indirect grafts, propagated inputs"
  680. (let* ((new (dummy-package "dep"
  681. (arguments '(#:implicit-inputs? #f))))
  682. (dep (package (inherit new) (version "0.0")))
  683. (dep* (package (inherit dep) (replacement new)))
  684. (prop (dummy-package "propagated"
  685. (propagated-inputs `(("dep" ,dep*)))
  686. (arguments '(#:implicit-inputs? #f))))
  687. (dummy (dummy-package "dummy"
  688. (arguments '(#:implicit-inputs? #f))
  689. (inputs `(("prop" ,prop))))))
  690. (equal? (package-grafts %store dummy)
  691. (list (graft
  692. (origin (package-derivation %store dep))
  693. (replacement (package-derivation %store new)))))))
  694. (test-assert "package-grafts, same replacement twice"
  695. (let* ((new (dummy-package "dep"
  696. (version "1")
  697. (arguments '(#:implicit-inputs? #f))))
  698. (dep (package (inherit new) (version "0") (replacement new)))
  699. (p1 (dummy-package "intermediate1"
  700. (arguments '(#:implicit-inputs? #f))
  701. (inputs `(("dep" ,dep)))))
  702. (p2 (dummy-package "intermediate2"
  703. (arguments '(#:implicit-inputs? #f))
  704. ;; Here we copy DEP to have an equivalent package that is not
  705. ;; 'eq?' to DEP. This is similar to what happens with
  706. ;; 'package-with-explicit-inputs' & co.
  707. (inputs `(("dep" ,(package (inherit dep)))))))
  708. (p3 (dummy-package "final"
  709. (arguments '(#:implicit-inputs? #f))
  710. (inputs `(("p1" ,p1) ("p2" ,p2))))))
  711. (equal? (package-grafts %store p3)
  712. (list (graft
  713. (origin (package-derivation %store
  714. (package (inherit dep)
  715. (replacement #f))))
  716. (replacement (package-derivation %store new)))))))
  717. (test-assert "replacement also grafted"
  718. ;; We build a DAG as below, where dotted arrows represent replacements and
  719. ;; solid arrows represent dependencies:
  720. ;;
  721. ;; P1 ·············> P1R
  722. ;; |\__________________.
  723. ;; v v
  724. ;; P2 ·············> P2R
  725. ;; |
  726. ;; v
  727. ;; P3
  728. ;;
  729. ;; We want to make sure that:
  730. ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
  731. ;; where:
  732. ;; (A,B) is a graft to replace A by B
  733. ;; grafted(DRV,G) denoted DRV with graft G applied
  734. (let* ((p1r (dummy-package "P1"
  735. (build-system trivial-build-system)
  736. (arguments
  737. `(#:guile ,%bootstrap-guile
  738. #:builder (let ((out (assoc-ref %outputs "out")))
  739. (mkdir out)
  740. (call-with-output-file
  741. (string-append out "/replacement")
  742. (const #t)))))))
  743. (p1 (package
  744. (inherit p1r) (name "p1") (replacement p1r)
  745. (arguments
  746. `(#:guile ,%bootstrap-guile
  747. #:builder (begin
  748. (mkdir (assoc-ref %outputs "out"))
  749. #t)))))
  750. (p2r (dummy-package "P2"
  751. (build-system trivial-build-system)
  752. (inputs `(("p1" ,p1)))
  753. (arguments
  754. `(#:guile ,%bootstrap-guile
  755. #:builder (let ((out (assoc-ref %outputs "out")))
  756. (mkdir out)
  757. (chdir out)
  758. (symlink (assoc-ref %build-inputs "p1") "p1")
  759. (call-with-output-file (string-append out "/replacement")
  760. (const #t)))))))
  761. (p2 (package
  762. (inherit p2r) (name "p2") (replacement p2r)
  763. (arguments
  764. `(#:guile ,%bootstrap-guile
  765. #:builder (let ((out (assoc-ref %outputs "out")))
  766. (mkdir out)
  767. (chdir out)
  768. (symlink (assoc-ref %build-inputs "p1")
  769. "p1")
  770. #t)))))
  771. (p3 (dummy-package "p3"
  772. (build-system trivial-build-system)
  773. (inputs `(("p2" ,p2)))
  774. (arguments
  775. `(#:guile ,%bootstrap-guile
  776. #:builder (let ((out (assoc-ref %outputs "out")))
  777. (mkdir out)
  778. (chdir out)
  779. (symlink (assoc-ref %build-inputs "p2")
  780. "p2")
  781. #t))))))
  782. (lset= equal?
  783. (package-grafts %store p3)
  784. (list (graft
  785. (origin (package-derivation %store p1 #:graft? #f))
  786. (replacement (package-derivation %store p1r)))
  787. (graft
  788. (origin (package-derivation %store p2 #:graft? #f))
  789. (replacement
  790. (package-derivation %store p2r #:graft? #t)))))))
  791. ;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
  792. ;;; find out about their run-time dependencies, so this test is no longer
  793. ;;; applicable since it would trigger a full rebuild.
  794. ;;
  795. ;; (test-assert "package-derivation, indirect grafts"
  796. ;; (let* ((new (dummy-package "dep"
  797. ;; (arguments '(#:implicit-inputs? #f))))
  798. ;; (dep (package (inherit new) (version "0.0")))
  799. ;; (dep* (package (inherit dep) (replacement new)))
  800. ;; (dummy (dummy-package "dummy"
  801. ;; (arguments '(#:implicit-inputs? #f))
  802. ;; (inputs `(("dep" ,dep*)))))
  803. ;; (guile (package-derivation %store (canonical-package guile-2.0)
  804. ;; #:graft? #f)))
  805. ;; (equal? (package-derivation %store dummy)
  806. ;; (graft-derivation %store
  807. ;; (package-derivation %store dummy #:graft? #f)
  808. ;; (package-grafts %store dummy)
  809. ;; ;; Use the same Guile as 'package-derivation'.
  810. ;; #:guile guile))))
  811. (test-equal "package->bag"
  812. `("foo86-hurd" #f (,(package-source gnu-make))
  813. (,(canonical-package glibc)) (,(canonical-package coreutils)))
  814. (let ((bag (package->bag gnu-make "foo86-hurd")))
  815. (list (bag-system bag) (bag-target bag)
  816. (assoc-ref (bag-build-inputs bag) "source")
  817. (assoc-ref (bag-build-inputs bag) "libc")
  818. (assoc-ref (bag-build-inputs bag) "coreutils"))))
  819. (test-equal "package->bag, cross-compilation"
  820. `(,(%current-system) "foo86-hurd"
  821. (,(package-source gnu-make))
  822. (,(canonical-package glibc)) (,(canonical-package coreutils)))
  823. (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
  824. (list (bag-system bag) (bag-target bag)
  825. (assoc-ref (bag-build-inputs bag) "source")
  826. (assoc-ref (bag-build-inputs bag) "libc")
  827. (assoc-ref (bag-build-inputs bag) "coreutils"))))
  828. (test-assert "package->bag, propagated inputs"
  829. (let* ((dep (dummy-package "dep"))
  830. (prop (dummy-package "prop"
  831. (propagated-inputs `(("dep" ,dep)))))
  832. (dummy (dummy-package "dummy"
  833. (inputs `(("prop" ,prop)))))
  834. (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
  835. (match (assoc "dep" inputs)
  836. (("dep" package)
  837. (eq? package dep)))))
  838. (test-assert "bag->derivation"
  839. (parameterize ((%graft? #f))
  840. (let ((bag (package->bag gnu-make))
  841. (drv (package-derivation %store gnu-make)))
  842. (parameterize ((%current-system "foox86-hurd")) ;should have no effect
  843. (equal? drv (bag->derivation %store bag))))))
  844. (test-assert "bag->derivation, cross-compilation"
  845. (parameterize ((%graft? #f))
  846. (let* ((target "mips64el-linux-gnu")
  847. (bag (package->bag gnu-make (%current-system) target))
  848. (drv (package-cross-derivation %store gnu-make target)))
  849. (parameterize ((%current-system "foox86-hurd") ;should have no effect
  850. (%current-target-system "foo64-linux-gnu"))
  851. (equal? drv (bag->derivation %store bag))))))
  852. (when (or (not (network-reachable?)) (shebang-too-long?))
  853. (test-skip 1))
  854. (test-assert "GNU Make, bootstrap"
  855. ;; GNU Make is the first program built during bootstrap; we choose it
  856. ;; here so that the test doesn't last for too long.
  857. (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
  858. (and (package? gnu-make)
  859. (or (location? (package-location gnu-make))
  860. (not (package-location gnu-make)))
  861. (let* ((drv (package-derivation %store gnu-make))
  862. (out (derivation->output-path drv)))
  863. (and (build-derivations %store (list drv))
  864. (file-exists? (string-append out "/bin/make")))))))
  865. (test-equal "package-mapping"
  866. 42
  867. (let* ((dep (dummy-package "chbouib"
  868. (native-inputs `(("x" ,grep)))))
  869. (p0 (dummy-package "example"
  870. (inputs `(("foo" ,coreutils)
  871. ("bar" ,grep)
  872. ("baz" ,dep)))))
  873. (transform (lambda (p)
  874. (package (inherit p) (source 42))))
  875. (rewrite (package-mapping transform))
  876. (p1 (rewrite p0)))
  877. (and (eq? p1 (rewrite p0))
  878. (eqv? 42 (package-source p1))
  879. (match (package-inputs p1)
  880. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  881. (and (eq? dep1 (rewrite coreutils)) ;memoization
  882. (eq? dep2 (rewrite grep))
  883. (eq? dep3 (rewrite dep))
  884. (eqv? 42
  885. (package-source dep1) (package-source dep2)
  886. (package-source dep3))
  887. (match (package-native-inputs dep3)
  888. ((("x" dep))
  889. (and (eq? dep (rewrite grep))
  890. (package-source dep))))))))))
  891. (test-assert "package-input-rewriting"
  892. (let* ((dep (dummy-package "chbouib"
  893. (native-inputs `(("x" ,grep)))))
  894. (p0 (dummy-package "example"
  895. (inputs `(("foo" ,coreutils)
  896. ("bar" ,grep)
  897. ("baz" ,dep)))))
  898. (rewrite (package-input-rewriting `((,coreutils . ,sed)
  899. (,grep . ,findutils))
  900. (cut string-append "r-" <>)))
  901. (p1 (rewrite p0))
  902. (p2 (rewrite p0)))
  903. (and (not (eq? p1 p0))
  904. (eq? p1 p2) ;memoization
  905. (string=? "r-example" (package-name p1))
  906. (match (package-inputs p1)
  907. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  908. (and (eq? dep1 sed)
  909. (eq? dep2 findutils)
  910. (string=? (package-name dep3) "r-chbouib")
  911. (eq? dep3 (rewrite dep)) ;memoization
  912. (match (package-native-inputs dep3)
  913. ((("x" dep))
  914. (eq? dep findutils)))))))))
  915. (test-equal "package-patched-vulnerabilities"
  916. '(("CVE-2015-1234")
  917. ("CVE-2016-1234" "CVE-2018-4567")
  918. ())
  919. (let ((p1 (dummy-package "pi"
  920. (source (dummy-origin
  921. (patches (list "/a/b/pi-CVE-2015-1234.patch"))))))
  922. (p2 (dummy-package "pi"
  923. (source (dummy-origin
  924. (patches (list
  925. "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch"))))))
  926. (p3 (dummy-package "pi" (source (dummy-origin)))))
  927. (map package-patched-vulnerabilities
  928. (list p1 p2 p3))))
  929. (test-eq "fold-packages" hello
  930. (fold-packages (lambda (p r)
  931. (if (string=? (package-name p) "hello")
  932. p
  933. r))
  934. #f))
  935. (test-assert "fold-packages, hidden package"
  936. ;; There are two public variables providing "guile@2.0" ('guile-final' in
  937. ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
  938. ;; should show up.
  939. (match (fold-packages (lambda (p r)
  940. (if (and (string=? (package-name p) "guile")
  941. (string-prefix? "2.0"
  942. (package-version p)))
  943. (cons p r)
  944. r))
  945. '())
  946. ((one)
  947. (eq? one guile-2.0))))
  948. (test-assert "fold-available-packages with/without cache"
  949. (let ()
  950. (define no-cache
  951. (fold-available-packages (lambda* (name version result #:rest rest)
  952. (cons (cons* name version rest)
  953. result))
  954. '()))
  955. (define from-cache
  956. (call-with-temporary-directory
  957. (lambda (cache)
  958. (generate-package-cache cache)
  959. (mock ((guix describe) current-profile (const cache))
  960. (mock ((gnu packages) cache-is-authoritative? (const #t))
  961. (fold-available-packages (lambda* (name version result
  962. #:rest rest)
  963. (cons (cons* name version rest)
  964. result))
  965. '()))))))
  966. (and (equal? (delete-duplicates from-cache) from-cache)
  967. (lset= equal? no-cache from-cache))))
  968. (test-assert "find-packages-by-name"
  969. (match (find-packages-by-name "hello")
  970. (((? (cut eq? hello <>))) #t)
  971. (wrong (pk 'find-packages-by-name wrong #f))))
  972. (test-assert "find-packages-by-name with version"
  973. (match (find-packages-by-name "hello" (package-version hello))
  974. (((? (cut eq? hello <>))) #t)
  975. (wrong (pk 'find-packages-by-name wrong #f))))
  976. (test-equal "find-packages-by-name with cache"
  977. (find-packages-by-name "guile")
  978. (call-with-temporary-directory
  979. (lambda (cache)
  980. (generate-package-cache cache)
  981. (mock ((guix describe) current-profile (const cache))
  982. (mock ((gnu packages) cache-is-authoritative? (const #t))
  983. (find-packages-by-name "guile"))))))
  984. (test-equal "find-packages-by-name + version, with cache"
  985. (find-packages-by-name "guile" "2")
  986. (call-with-temporary-directory
  987. (lambda (cache)
  988. (generate-package-cache cache)
  989. (mock ((guix describe) current-profile (const cache))
  990. (mock ((gnu packages) cache-is-authoritative? (const #t))
  991. (find-packages-by-name "guile" "2"))))))
  992. (test-assert "--search-paths with pattern"
  993. ;; Make sure 'guix package --search-paths' correctly reports environment
  994. ;; variables when file patterns are used (in particular, it must follow
  995. ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
  996. ;; libxml2 package specification, which contains such a definition.
  997. (let* ((p1 (package
  998. (name "foo") (version "0") (source #f)
  999. (build-system trivial-build-system)
  1000. (arguments
  1001. `(#:guile ,%bootstrap-guile
  1002. #:modules ((guix build utils))
  1003. #:builder (begin
  1004. (use-modules (guix build utils))
  1005. (let ((out (assoc-ref %outputs "out")))
  1006. (mkdir-p (string-append out "/xml/bar/baz"))
  1007. (call-with-output-file
  1008. (string-append out "/xml/bar/baz/catalog.xml")
  1009. (lambda (port)
  1010. (display "xml? wat?!" port)))
  1011. #t))))
  1012. (synopsis #f) (description #f)
  1013. (home-page #f) (license #f)))
  1014. (p2 (package
  1015. ;; Provide a fake libxml2 to avoid building the real one. This
  1016. ;; is OK because 'guix package' gets search path specifications
  1017. ;; from the same-named package found in the distro.
  1018. (name "libxml2") (version "0.0.0") (source #f)
  1019. (build-system trivial-build-system)
  1020. (arguments
  1021. `(#:guile ,%bootstrap-guile
  1022. #:builder (begin
  1023. (mkdir (assoc-ref %outputs "out"))
  1024. #t)))
  1025. (native-search-paths (package-native-search-paths libxml2))
  1026. (synopsis #f) (description #f)
  1027. (home-page #f) (license #f)))
  1028. (prof (run-with-store %store
  1029. (profile-derivation
  1030. (manifest (map package->manifest-entry
  1031. (list p1 p2)))
  1032. #:hooks '()
  1033. #:locales? #f)
  1034. #:guile-for-build (%guile-for-build))))
  1035. (build-derivations %store (list prof))
  1036. (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
  1037. (regexp-quote (derivation->output-path prof)))
  1038. (with-output-to-string
  1039. (lambda ()
  1040. (guix-package "-p" (derivation->output-path prof)
  1041. "--search-paths"))))))
  1042. (test-assert "--search-paths with single-item search path"
  1043. ;; Make sure 'guix package --search-paths' correctly reports environment
  1044. ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
  1045. ;; separator, meaning that the first match wins.
  1046. (let* ((p1 (dummy-package "foo"
  1047. (build-system trivial-build-system)
  1048. (arguments
  1049. `(#:guile ,%bootstrap-guile
  1050. #:modules ((guix build utils))
  1051. #:builder (begin
  1052. (use-modules (guix build utils))
  1053. (let ((out (assoc-ref %outputs "out")))
  1054. (mkdir-p (string-append out "/etc/ssl/certs"))
  1055. (call-with-output-file
  1056. (string-append
  1057. out "/etc/ssl/certs/ca-certificates.crt")
  1058. (const #t))))))))
  1059. (p2 (package (inherit p1) (name "bar")))
  1060. (p3 (dummy-package "git"
  1061. ;; Provide a fake Git to avoid building the real one.
  1062. (build-system trivial-build-system)
  1063. (arguments
  1064. `(#:guile ,%bootstrap-guile
  1065. #:builder (begin
  1066. (mkdir (assoc-ref %outputs "out"))
  1067. #t)))
  1068. (native-search-paths (package-native-search-paths git))))
  1069. (prof1 (run-with-store %store
  1070. (profile-derivation
  1071. (packages->manifest (list p1 p3))
  1072. #:hooks '()
  1073. #:locales? #f)
  1074. #:guile-for-build (%guile-for-build)))
  1075. (prof2 (run-with-store %store
  1076. (profile-derivation
  1077. (packages->manifest (list p2 p3))
  1078. #:hooks '()
  1079. #:locales? #f)
  1080. #:guile-for-build (%guile-for-build))))
  1081. (build-derivations %store (list prof1 prof2))
  1082. (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
  1083. (regexp-quote (derivation->output-path prof1)))
  1084. (with-output-to-string
  1085. (lambda ()
  1086. (guix-package "-p" (derivation->output-path prof1)
  1087. "-p" (derivation->output-path prof2)
  1088. "--search-paths"))))))
  1089. (test-equal "specification->package when not found"
  1090. 'quit
  1091. (catch 'quit
  1092. (lambda ()
  1093. ;; This should call 'leave', producing an error message.
  1094. (specification->package "this-package-does-not-exist"))
  1095. (lambda (key . args)
  1096. key)))
  1097. (test-equal "find-package-locations"
  1098. (map (lambda (package)
  1099. (cons (package-version package)
  1100. (package-location package)))
  1101. (find-packages-by-name "guile"))
  1102. (find-package-locations "guile"))
  1103. (test-equal "find-package-locations with cache"
  1104. (map (lambda (package)
  1105. (cons (package-version package)
  1106. (package-location package)))
  1107. (find-packages-by-name "guile"))
  1108. (call-with-temporary-directory
  1109. (lambda (cache)
  1110. (generate-package-cache cache)
  1111. (mock ((guix describe) current-profile (const cache))
  1112. (mock ((gnu packages) cache-is-authoritative? (const #t))
  1113. (find-package-locations "guile"))))))
  1114. (test-equal "specification->location"
  1115. (package-location (specification->package "guile@2"))
  1116. (specification->location "guile@2"))
  1117. (test-end "packages")
  1118. ;;; Local Variables:
  1119. ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
  1120. ;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1)
  1121. ;;; End: