packages.scm 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  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 (test-packages)
  20. #:use-module (guix tests)
  21. #:use-module (guix store)
  22. #:use-module (guix monads)
  23. #:use-module (guix grafts)
  24. #:use-module ((guix gexp) #:select (local-file local-file-file))
  25. #:use-module (guix utils)
  26. #:use-module ((guix diagnostics)
  27. ;; Rename the 'location' binding to allow proper syntax
  28. ;; matching when setting the 'location' field of a package.
  29. #:renamer (lambda (name)
  30. (cond ((eq? name 'location) 'make-location)
  31. (else name))))
  32. #:use-module ((gcrypt hash) #:prefix gcrypt:)
  33. #:use-module (guix derivations)
  34. #:use-module (guix packages)
  35. #:use-module (guix grafts)
  36. #:use-module (guix search-paths)
  37. #:use-module (guix build-system)
  38. #:use-module (guix build-system trivial)
  39. #:use-module (guix build-system gnu)
  40. #:use-module (guix build-system python)
  41. #:use-module (guix memoization)
  42. #:use-module (guix profiles)
  43. #:use-module (guix scripts package)
  44. #:use-module (gnu packages)
  45. #:use-module (gnu packages base)
  46. #:use-module (gnu packages guile)
  47. #:use-module (gnu packages bootstrap)
  48. #:use-module (gnu packages python)
  49. #:use-module (gnu packages version-control)
  50. #:use-module (gnu packages xml)
  51. #:use-module (srfi srfi-1)
  52. #:use-module (srfi srfi-26)
  53. #:use-module (srfi srfi-34)
  54. #:use-module (srfi srfi-35)
  55. #:use-module (srfi srfi-64)
  56. #:use-module (rnrs bytevectors)
  57. #:use-module (rnrs io ports)
  58. #:use-module (ice-9 vlist)
  59. #:use-module (ice-9 regex)
  60. #:use-module (ice-9 match))
  61. ;; Test the high-level packaging layer.
  62. (define %store
  63. (open-connection-for-tests))
  64. ;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
  65. ;; can trigger builds early.)
  66. (%graft? #f)
  67. (test-begin "packages")
  68. (test-assert "printer with location"
  69. (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
  70. (with-output-to-string
  71. (lambda ()
  72. (write
  73. (dummy-package "foo"
  74. (location (make-location "foo.scm" 42 7))))))))
  75. (test-assert "printer without location"
  76. (string-match "^#<package foo@0 [[:xdigit:]]+>$"
  77. (with-output-to-string
  78. (lambda ()
  79. (write
  80. (dummy-package "foo" (location #f)))))))
  81. (test-assert "hidden-package"
  82. (and (hidden-package? (hidden-package (dummy-package "foo")))
  83. (not (hidden-package? (dummy-package "foo")))))
  84. (test-assert "package-superseded"
  85. (let* ((new (dummy-package "bar"))
  86. (old (deprecated-package "foo" new)))
  87. (and (eq? (package-superseded old) new)
  88. (mock ((gnu packages) find-best-packages-by-name (const (list old)))
  89. (specification->package "foo")
  90. (and (eq? new (specification->package "foo"))
  91. (eq? new (specification->package+output "foo")))))))
  92. (test-assert "transaction-upgrade-entry, zero upgrades"
  93. (let* ((old (dummy-package "foo" (version "1")))
  94. (tx (mock ((gnu packages) find-best-packages-by-name
  95. (const '()))
  96. (transaction-upgrade-entry
  97. #f ;no store access needed
  98. (manifest-entry
  99. (inherit (package->manifest-entry old))
  100. (item (string-append (%store-prefix) "/"
  101. (make-string 32 #\e) "-foo-1")))
  102. (manifest-transaction)))))
  103. (manifest-transaction-null? tx)))
  104. (test-assert "transaction-upgrade-entry, zero upgrades, equivalent package"
  105. (let* ((old (dummy-package "foo" (version "1")))
  106. (drv (package-derivation %store old))
  107. (tx (mock ((gnu packages) find-best-packages-by-name
  108. (const (list old)))
  109. (transaction-upgrade-entry
  110. %store
  111. (manifest-entry
  112. (inherit (package->manifest-entry old))
  113. (item (derivation->output-path drv)))
  114. (manifest-transaction)))))
  115. (manifest-transaction-null? tx)))
  116. (test-assert "transaction-upgrade-entry, zero upgrades, propagated inputs"
  117. ;; Properly detect equivalent packages even when they have propagated
  118. ;; inputs. See <https://bugs.gnu.org/35872>.
  119. (let* ((dep (dummy-package "dep" (version "2")))
  120. (old (dummy-package "foo" (version "1")
  121. (propagated-inputs `(("dep" ,dep)))))
  122. (drv (package-derivation %store old))
  123. (tx (mock ((gnu packages) find-best-packages-by-name
  124. (const (list old)))
  125. (transaction-upgrade-entry
  126. %store
  127. (manifest-entry
  128. (inherit (package->manifest-entry old))
  129. (item (derivation->output-path drv))
  130. (dependencies
  131. (list (manifest-entry
  132. (inherit (package->manifest-entry dep))
  133. (item (derivation->output-path
  134. (package-derivation %store dep)))))))
  135. (manifest-transaction)))))
  136. (manifest-transaction-null? tx)))
  137. (test-assert "transaction-upgrade-entry, one upgrade"
  138. (let* ((old (dummy-package "foo" (version "1")))
  139. (new (dummy-package "foo" (version "2")))
  140. (tx (mock ((gnu packages) find-best-packages-by-name
  141. (const (list new)))
  142. (transaction-upgrade-entry
  143. #f ;no store access needed
  144. (manifest-entry
  145. (inherit (package->manifest-entry old))
  146. (item (string-append (%store-prefix) "/"
  147. (make-string 32 #\e) "-foo-1")))
  148. (manifest-transaction)))))
  149. (and (match (manifest-transaction-install tx)
  150. ((($ <manifest-entry> "foo" "2" "out" item))
  151. (eq? item new)))
  152. (null? (manifest-transaction-remove tx)))))
  153. (test-assert "transaction-upgrade-entry, superseded package"
  154. (let* ((old (dummy-package "foo" (version "1")))
  155. (new (dummy-package "bar" (version "2")))
  156. (dep (deprecated-package "foo" new))
  157. (tx (mock ((gnu packages) find-best-packages-by-name
  158. (const (list dep)))
  159. (transaction-upgrade-entry
  160. #f ;no store access needed
  161. (manifest-entry
  162. (inherit (package->manifest-entry old))
  163. (item (string-append (%store-prefix) "/"
  164. (make-string 32 #\e) "-foo-1")))
  165. (manifest-transaction)))))
  166. (and (match (manifest-transaction-install tx)
  167. ((($ <manifest-entry> "bar" "2" "out" item))
  168. (eq? item new)))
  169. (match (manifest-transaction-remove tx)
  170. (((? manifest-pattern? pattern))
  171. (and (string=? (manifest-pattern-name pattern) "foo")
  172. (string=? (manifest-pattern-version pattern) "1")
  173. (string=? (manifest-pattern-output pattern) "out")))))))
  174. (test-equal "transaction-upgrade-entry, transformation options preserved"
  175. (derivation-file-name (package-derivation %store grep))
  176. (let* ((old (dummy-package "emacs" (version "1")))
  177. (props '((transformations . ((with-input . "emacs=grep")))))
  178. (tx (transaction-upgrade-entry
  179. %store
  180. (manifest-entry
  181. (inherit (package->manifest-entry old))
  182. (properties props)
  183. (item (string-append (%store-prefix) "/"
  184. (make-string 32 #\e) "-foo-1")))
  185. (manifest-transaction))))
  186. (match (manifest-transaction-install tx)
  187. (((? manifest-entry? entry))
  188. (and (string=? (manifest-entry-version entry)
  189. (package-version grep))
  190. (string=? (manifest-entry-name entry)
  191. (package-name grep))
  192. (equal? (manifest-entry-properties entry) props)
  193. (derivation-file-name
  194. (package-derivation %store (manifest-entry-item entry))))))))
  195. (test-assert "transaction-upgrade-entry, grafts"
  196. ;; Ensure that, when grafts are enabled, 'transaction-upgrade-entry' doesn't
  197. ;; try to build stuff.
  198. (with-build-handler (const 'failed!)
  199. (parameterize ((%graft? #t))
  200. (let* ((old (dummy-package "foo" (version "1")))
  201. (bar (dummy-package "bar" (version "0")
  202. (replacement old)))
  203. (new (dummy-package "foo" (version "1")
  204. (inputs `(("bar" ,bar)))))
  205. (tx (mock ((gnu packages) find-best-packages-by-name
  206. (const (list new)))
  207. (transaction-upgrade-entry
  208. %store
  209. (manifest-entry
  210. (inherit (package->manifest-entry old))
  211. (item (string-append (%store-prefix) "/"
  212. (make-string 32 #\e) "-foo-1")))
  213. (manifest-transaction)))))
  214. (and (match (manifest-transaction-install tx)
  215. ((($ <manifest-entry> "foo" "1" "out" item))
  216. (eq? item new)))
  217. (null? (manifest-transaction-remove tx)))))))
  218. (test-assert "package-field-location"
  219. (let ()
  220. (define (goto port line column)
  221. (unless (and (= (port-column port) (- column 1))
  222. (= (port-line port) (- line 1)))
  223. (unless (eof-object? (get-char port))
  224. (goto port line column))))
  225. (define read-at
  226. (match-lambda
  227. (($ <location> file line column)
  228. (call-with-input-file (search-path %load-path file)
  229. (lambda (port)
  230. (goto port line column)
  231. (read port))))))
  232. ;; Until Guile 2.0.6 included, source properties were added only to pairs.
  233. ;; Thus, check against both VALUE and (FIELD VALUE).
  234. (and (member (read-at (package-field-location %bootstrap-guile 'name))
  235. (let ((name (package-name %bootstrap-guile)))
  236. (list name `(name ,name))))
  237. (member (read-at (package-field-location %bootstrap-guile 'version))
  238. (let ((version (package-version %bootstrap-guile)))
  239. (list version `(version ,version))))
  240. (not (package-field-location %bootstrap-guile 'does-not-exist)))))
  241. ;; Make sure we don't change the file name to an absolute file name.
  242. (test-equal "package-field-location, relative file name"
  243. (location-file (package-location %bootstrap-guile))
  244. (with-fluids ((%file-port-name-canonicalization 'absolute))
  245. (location-file (package-field-location %bootstrap-guile 'version))))
  246. (test-assert "package-transitive-inputs"
  247. (let* ((a (dummy-package "a"))
  248. (b (dummy-package "b"
  249. (propagated-inputs `(("a" ,a)))))
  250. (c (dummy-package "c"
  251. (inputs `(("a" ,a)))))
  252. (d (dummy-package "d"
  253. (propagated-inputs `(("x" "something.drv")))))
  254. (e (dummy-package "e"
  255. (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
  256. (and (null? (package-transitive-inputs a))
  257. (equal? `(("a" ,a)) (package-transitive-inputs b))
  258. (equal? `(("a" ,a)) (package-transitive-inputs c))
  259. (equal? (package-propagated-inputs d)
  260. (package-transitive-inputs d))
  261. (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
  262. ("a" ,a) ("x" "something.drv"))
  263. (pk 'x (package-transitive-inputs e))))))
  264. (test-assert "package-transitive-inputs, no duplicates"
  265. (let* ((a (dummy-package "a"))
  266. (b (dummy-package "b"
  267. (inputs `(("a+" ,a)))
  268. (native-inputs `(("a*" ,a)))
  269. (propagated-inputs `(("a" ,a)))))
  270. (c (dummy-package "c"
  271. (propagated-inputs `(("b" ,b)))))
  272. (d (dummy-package "d"
  273. (inputs `(("a" ,a) ("c" ,c)))))
  274. (e (dummy-package "e"
  275. (inputs `(("b" ,b) ("c" ,c))))))
  276. (and (null? (package-transitive-inputs a))
  277. (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
  278. (package-transitive-inputs b))
  279. (equal? `(("b" ,b) ("a" ,a))
  280. (package-transitive-inputs c))
  281. (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
  282. (package-transitive-inputs d))
  283. (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
  284. (package-transitive-inputs e))))) ;ditto
  285. (test-equal "package-transitive-supported-systems"
  286. '(("x" "y" "z") ;a
  287. ("x" "y") ;b
  288. ("y") ;c
  289. ("y") ;d
  290. ("y")) ;e
  291. ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
  292. ;; doesn't restrict the set of supported systems.
  293. (let* ((a (dummy-package "a"
  294. (build-system trivial-build-system)
  295. (supported-systems '("x" "y" "z"))))
  296. (b (dummy-package "b"
  297. (build-system trivial-build-system)
  298. (supported-systems '("x" "y"))
  299. (inputs `(("a" ,a)))))
  300. (c (dummy-package "c"
  301. (build-system trivial-build-system)
  302. (supported-systems '("y" "z"))
  303. (inputs `(("b" ,b)))))
  304. (d (dummy-package "d"
  305. (build-system trivial-build-system)
  306. (supported-systems '("x" "y" "z"))
  307. (inputs `(("b" ,b) ("c" ,c)))))
  308. (e (dummy-package "e"
  309. (build-system trivial-build-system)
  310. (supported-systems '("x" "y" "z"))
  311. (inputs `(("d" ,d))))))
  312. (list (package-transitive-supported-systems a)
  313. (package-transitive-supported-systems b)
  314. (package-transitive-supported-systems c)
  315. (package-transitive-supported-systems d)
  316. (package-transitive-supported-systems e))))
  317. (test-assert "package-closure"
  318. (let-syntax ((dummy-package/no-implicit
  319. (syntax-rules ()
  320. ((_ name rest ...)
  321. (package
  322. (inherit (dummy-package name rest ...))
  323. (build-system trivial-build-system))))))
  324. (let* ((a (dummy-package/no-implicit "a"))
  325. (b (dummy-package/no-implicit "b"
  326. (propagated-inputs `(("a" ,a)))))
  327. (c (dummy-package/no-implicit "c"
  328. (inputs `(("a" ,a)))))
  329. (d (dummy-package/no-implicit "d"
  330. (native-inputs `(("b" ,b)))))
  331. (e (dummy-package/no-implicit "e"
  332. (inputs `(("c" ,c) ("d" ,d))))))
  333. (lset= eq?
  334. (list a b c d e)
  335. (package-closure (list e))
  336. (package-closure (list e d))
  337. (package-closure (list e c b))))))
  338. (test-equal "origin-actual-file-name"
  339. "foo-1.tar.gz"
  340. (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
  341. (origin-actual-file-name o)))
  342. (test-equal "origin-actual-file-name, file-name"
  343. "foo-1.tar.gz"
  344. (let ((o (dummy-origin
  345. (uri "http://www.example.com/tarball")
  346. (file-name "foo-1.tar.gz"))))
  347. (origin-actual-file-name o)))
  348. (let* ((o (dummy-origin))
  349. (u (dummy-origin))
  350. (i (dummy-origin))
  351. (a (dummy-package "a"))
  352. (b (dummy-package "b"
  353. (inputs `(("a" ,a) ("i" ,i)))))
  354. (c (package (inherit b) (source o)))
  355. (d (dummy-package "d"
  356. (build-system trivial-build-system)
  357. (source u) (inputs `(("c" ,c))))))
  358. (test-assert "package-direct-sources, no source"
  359. (null? (package-direct-sources a)))
  360. (test-equal "package-direct-sources, #f source"
  361. (list i)
  362. (package-direct-sources b))
  363. (test-equal "package-direct-sources, not input source"
  364. (list u)
  365. (package-direct-sources d))
  366. (test-assert "package-direct-sources"
  367. (let ((s (package-direct-sources c)))
  368. (and (= (length (pk 's-sources s)) 2)
  369. (member o s)
  370. (member i s))))
  371. (test-assert "package-transitive-sources"
  372. (let ((s (package-transitive-sources d)))
  373. (and (= (length (pk 'd-sources s)) 3)
  374. (member o s)
  375. (member i s)
  376. (member u s)))))
  377. (test-assert "transitive-input-references"
  378. (let* ((a (dummy-package "a"))
  379. (b (dummy-package "b"))
  380. (c (dummy-package "c"
  381. (inputs `(("a" ,a)))
  382. (propagated-inputs `(("boo" ,b)))))
  383. (d (dummy-package "d"
  384. (inputs `(("c*" ,c)))))
  385. (keys (map (match-lambda
  386. (('assoc-ref 'l key)
  387. key))
  388. (pk 'refs (transitive-input-references
  389. 'l (package-inputs d))))))
  390. (and (= (length keys) 2)
  391. (member "c*" keys)
  392. (member "boo" keys))))
  393. (test-equal "package-transitive-supported-systems, implicit inputs"
  394. %supported-systems
  395. ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
  396. ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
  397. (let ((p (dummy-package "foo"
  398. (build-system gnu-build-system)
  399. (supported-systems
  400. `("does-not-exist" "foobar" ,@%supported-systems)))))
  401. (parameterize ((%current-system "armhf-linux")) ; a traditionally-bootstrapped architecture
  402. (package-transitive-supported-systems p))))
  403. (test-equal "package-transitive-supported-systems: reduced binary seed, implicit inputs"
  404. '("x86_64-linux" "i686-linux")
  405. ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
  406. ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
  407. (let ((p (dummy-package "foo"
  408. (build-system gnu-build-system)
  409. (supported-systems
  410. `("does-not-exist" "foobar" ,@%supported-systems)))))
  411. (parameterize ((%current-system "x86_64-linux"))
  412. (package-transitive-supported-systems p))))
  413. (test-assert "supported-package?"
  414. (let* ((d (dummy-package "dep"
  415. (build-system trivial-build-system)
  416. (supported-systems '("x86_64-linux"))))
  417. (p (dummy-package "foo"
  418. (build-system gnu-build-system)
  419. (inputs `(("d" ,d)))
  420. (supported-systems '("x86_64-linux" "armhf-linux")))))
  421. (and (supported-package? p "x86_64-linux")
  422. (not (supported-package? p "i686-linux"))
  423. (not (supported-package? p "armhf-linux")))))
  424. (test-assert "supported-package? vs. system-dependent graph"
  425. ;; The inputs of a package can depend on (%current-system). Thus,
  426. ;; 'supported-package?' must make sure that it binds (%current-system)
  427. ;; appropriately before traversing the dependency graph. In the example
  428. ;; below, 'supported-package?' must thus return true for both systems.
  429. (let* ((p0a (dummy-package "foo-arm"
  430. (build-system trivial-build-system)
  431. (supported-systems '("armhf-linux"))))
  432. (p0b (dummy-package "foo-x86_64"
  433. (build-system trivial-build-system)
  434. (supported-systems '("x86_64-linux"))))
  435. (p (dummy-package "bar"
  436. (build-system trivial-build-system)
  437. (inputs
  438. (if (string=? (%current-system) "armhf-linux")
  439. `(("foo" ,p0a))
  440. `(("foo" ,p0b)))))))
  441. (and (supported-package? p "x86_64-linux")
  442. (supported-package? p "armhf-linux"))))
  443. (test-skip (if (not %store) 8 0))
  444. (test-assert "package-source-derivation, file"
  445. (let* ((file (search-path %load-path "guix.scm"))
  446. (package (package (inherit (dummy-package "p"))
  447. (source file)))
  448. (source (package-source-derivation %store
  449. (package-source package))))
  450. (and (store-path? source)
  451. (valid-path? %store source)
  452. (equal? (call-with-input-file source get-bytevector-all)
  453. (call-with-input-file file get-bytevector-all)))))
  454. (test-assert "package-source-derivation, store path"
  455. (let* ((file (add-to-store %store "guix.scm" #t "sha256"
  456. (search-path %load-path "guix.scm")))
  457. (package (package (inherit (dummy-package "p"))
  458. (source file)))
  459. (source (package-source-derivation %store
  460. (package-source package))))
  461. (string=? file source)))
  462. (test-assert "package-source-derivation, indirect store path"
  463. (let* ((dir (add-to-store %store "guix-build" #t "sha256"
  464. (dirname (search-path %load-path
  465. "guix/build/utils.scm"))))
  466. (package (package (inherit (dummy-package "p"))
  467. (source (string-append dir "/utils.scm"))))
  468. (source (package-source-derivation %store
  469. (package-source package))))
  470. (and (direct-store-path? source)
  471. (string-suffix? "utils.scm" source))))
  472. (test-assert "package-source-derivation, local-file"
  473. (let* ((file (local-file "../guix/base32.scm"))
  474. (package (package (inherit (dummy-package "p"))
  475. (source file)))
  476. (source (package-source-derivation %store
  477. (package-source package))))
  478. (and (store-path? source)
  479. (string-suffix? "base32.scm" source)
  480. (valid-path? %store source)
  481. (equal? (call-with-input-file source get-bytevector-all)
  482. (call-with-input-file
  483. (search-path %load-path "guix/base32.scm")
  484. get-bytevector-all)))))
  485. (test-equal "package-source-derivation, origin, sha512"
  486. "hello"
  487. (let* ((bash (search-bootstrap-binary "bash" (%current-system)))
  488. (builder (add-text-to-store %store "my-fixed-builder.sh"
  489. "echo -n hello > $out" '()))
  490. (method (lambda* (url hash-algo hash #:optional name
  491. #:rest rest)
  492. (and (eq? hash-algo 'sha512)
  493. (raw-derivation name bash (list builder)
  494. #:sources (list builder)
  495. #:hash hash
  496. #:hash-algo hash-algo))))
  497. (source (origin
  498. (method method)
  499. (uri "unused://")
  500. (file-name "origin-sha512")
  501. (hash (content-hash
  502. (gcrypt:bytevector-hash (string->utf8 "hello")
  503. (gcrypt:lookup-hash-algorithm
  504. 'sha512))
  505. sha512))))
  506. (drv (package-source-derivation %store source))
  507. (output (derivation->output-path drv)))
  508. (build-derivations %store (list drv))
  509. (call-with-input-file output get-string-all)))
  510. (test-equal "package-source-derivation, origin, sha3-512"
  511. "hello, sha3"
  512. (let* ((bash (search-bootstrap-binary "bash" (%current-system)))
  513. (builder (add-text-to-store %store "my-fixed-builder.sh"
  514. "echo -n hello, sha3 > $out" '()))
  515. (method (lambda* (url hash-algo hash #:optional name
  516. #:rest rest)
  517. (and (eq? hash-algo 'sha3-512)
  518. (raw-derivation name bash (list builder)
  519. #:sources (list builder)
  520. #:hash hash
  521. #:hash-algo hash-algo))))
  522. (source (origin
  523. (method method)
  524. (uri "unused://")
  525. (file-name "origin-sha3")
  526. (hash (content-hash
  527. (gcrypt:bytevector-hash (string->utf8 "hello, sha3")
  528. (gcrypt:lookup-hash-algorithm
  529. 'sha3-512))
  530. sha3-512))))
  531. (drv (package-source-derivation %store source))
  532. (output (derivation->output-path drv)))
  533. (build-derivations %store (list drv))
  534. (call-with-input-file output get-string-all)))
  535. (unless (network-reachable?) (test-skip 1))
  536. (test-equal "package-source-derivation, snippet"
  537. "OK"
  538. (let* ((source (bootstrap-origin
  539. (origin
  540. (inherit (bootstrap-guile-origin (%current-system)))
  541. (patch-inputs
  542. `(("tar" ,%bootstrap-coreutils&co)
  543. ("xz" ,%bootstrap-coreutils&co)
  544. ("patch" ,%bootstrap-coreutils&co)))
  545. (patch-guile %bootstrap-guile)
  546. (modules '((guix build utils)))
  547. (snippet '(begin
  548. ;; We end up in 'bin', because it's the first
  549. ;; directory, alphabetically. Not a very good
  550. ;; example but hey.
  551. (chmod "." #o777)
  552. (symlink "guile" "guile-rocks")
  553. (copy-recursively "../share/guile/2.0/scripts"
  554. "scripts")
  555. ;; Make sure '.file_list' can be created.
  556. (chmod ".." #o777))))))
  557. (package (package (inherit (dummy-package "with-snippet"))
  558. (source source)
  559. (build-system trivial-build-system)
  560. (inputs
  561. `(("tar" ,(search-bootstrap-binary "tar"
  562. (%current-system)))
  563. ("xz" ,(search-bootstrap-binary "xz"
  564. (%current-system)))))
  565. (arguments
  566. `(#:guile ,%bootstrap-guile
  567. #:modules ((guix build utils))
  568. #:builder
  569. (begin
  570. (use-modules (guix build utils))
  571. (let ((tar (assoc-ref %build-inputs "tar"))
  572. (xz (assoc-ref %build-inputs "xz"))
  573. (source (assoc-ref %build-inputs "source")))
  574. (invoke tar "xvf" source
  575. "--use-compress-program" xz)
  576. (unless (and (string=? "guile" (readlink "bin/guile-rocks"))
  577. (file-exists? "bin/scripts/compile.scm"))
  578. (error "the snippet apparently failed"))
  579. (let ((out (assoc-ref %outputs "out")))
  580. (call-with-output-file out
  581. (lambda (p)
  582. (display "OK" p))))
  583. #t))))))
  584. (drv (package-derivation %store package))
  585. (out (derivation->output-path drv)))
  586. (and (build-derivations %store (list (pk 'snippet-drv drv)))
  587. (call-with-input-file out get-string-all))))
  588. (test-assert "return value"
  589. (let ((drv (package-derivation %store (dummy-package "p"))))
  590. (and (derivation? drv)
  591. (file-exists? (derivation-file-name drv)))))
  592. (test-assert "package-output"
  593. (let* ((package (dummy-package "p"))
  594. (drv (package-derivation %store package)))
  595. (and (derivation? drv)
  596. (string=? (derivation->output-path drv)
  597. (package-output %store package "out")))))
  598. (test-equal "patch not found yields a run-time error"
  599. '("~a: patch not found\n" "does-not-exist.patch")
  600. (guard (c ((formatted-message? c)
  601. (cons (formatted-message-string c)
  602. (formatted-message-arguments c))))
  603. (let ((p (package
  604. (inherit (dummy-package "p"))
  605. (source (origin
  606. (method (const #f))
  607. (uri "http://whatever")
  608. (patches
  609. (list (search-patch "does-not-exist.patch")))
  610. (sha256
  611. (base32
  612. "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
  613. (package-derivation %store p)
  614. #f)))
  615. (let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
  616. (test-equal "&package-input-error"
  617. (list dummy (current-module))
  618. (guard (c ((package-input-error? c)
  619. (list (package-error-package c)
  620. (package-error-invalid-input c))))
  621. (package-derivation %store dummy))))
  622. (test-assert "reference to non-existent output"
  623. ;; See <http://bugs.gnu.org/19630>.
  624. (parameterize ((%graft? #f))
  625. (let* ((dep (dummy-package "dep"))
  626. (p (dummy-package "p"
  627. (inputs `(("dep" ,dep "non-existent"))))))
  628. (guard (c ((derivation-missing-output-error? c)
  629. (and (string=? (derivation-missing-output c) "non-existent")
  630. (equal? (package-derivation %store dep)
  631. (derivation-error-derivation c)))))
  632. (package-derivation %store p)))))
  633. (test-assert "trivial"
  634. (let* ((p (package (inherit (dummy-package "trivial"))
  635. (build-system trivial-build-system)
  636. (source #f)
  637. (arguments
  638. `(#:guile ,%bootstrap-guile
  639. #:builder
  640. (begin
  641. (mkdir %output)
  642. (call-with-output-file (string-append %output "/test")
  643. (lambda (p)
  644. (display '(hello guix) p)))
  645. #t)))))
  646. (d (package-derivation %store p)))
  647. (and (build-derivations %store (list d))
  648. (let ((p (pk 'drv d (derivation->output-path d))))
  649. (equal? '(hello guix)
  650. (call-with-input-file (string-append p "/test") read))))))
  651. (test-assert "trivial with local file as input"
  652. (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
  653. (p (package (inherit (dummy-package "trivial-with-input-file"))
  654. (build-system trivial-build-system)
  655. (source #f)
  656. (arguments
  657. `(#:guile ,%bootstrap-guile
  658. #:builder (begin
  659. (copy-file (assoc-ref %build-inputs "input")
  660. %output)
  661. #t)))
  662. (inputs `(("input" ,i)))))
  663. (d (package-derivation %store p)))
  664. (and (build-derivations %store (list d))
  665. (let ((p (pk 'drv d (derivation->output-path d))))
  666. (equal? (call-with-input-file p get-bytevector-all)
  667. (call-with-input-file i get-bytevector-all))))))
  668. (test-assert "trivial with source"
  669. (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
  670. (p (package (inherit (dummy-package "trivial-with-source"))
  671. (build-system trivial-build-system)
  672. (source i)
  673. (arguments
  674. `(#:guile ,%bootstrap-guile
  675. #:builder (begin
  676. (copy-file (assoc-ref %build-inputs "source")
  677. %output)
  678. #t)))))
  679. (d (package-derivation %store p)))
  680. (and (build-derivations %store (list d))
  681. (let ((p (derivation->output-path d)))
  682. (equal? (call-with-input-file p get-bytevector-all)
  683. (call-with-input-file i get-bytevector-all))))))
  684. (test-assert "trivial with system-dependent input"
  685. (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
  686. (build-system trivial-build-system)
  687. (source #f)
  688. (arguments
  689. `(#:guile ,%bootstrap-guile
  690. #:modules ((guix build utils))
  691. #:builder
  692. (begin
  693. (use-modules (guix build utils))
  694. (let ((out (assoc-ref %outputs "out"))
  695. (bash (assoc-ref %build-inputs "bash")))
  696. (invoke bash "-c"
  697. (format #f "echo hello > ~a" out))))))
  698. (inputs `(("bash" ,(search-bootstrap-binary "bash"
  699. (%current-system)))))))
  700. (d (package-derivation %store p)))
  701. (and (build-derivations %store (list d))
  702. (let ((p (pk 'drv d (derivation->output-path d))))
  703. (eq? 'hello (call-with-input-file p read))))))
  704. (test-assert "trivial with #:allowed-references"
  705. (let* ((p (package
  706. (inherit (dummy-package "trivial"))
  707. (build-system trivial-build-system)
  708. (arguments
  709. `(#:guile ,%bootstrap-guile
  710. #:allowed-references (,%bootstrap-guile)
  711. #:builder
  712. (begin
  713. (mkdir %output)
  714. ;; The reference to itself isn't allowed so building it
  715. ;; should fail.
  716. (symlink %output (string-append %output "/self"))
  717. #t)))))
  718. (d (package-derivation %store p)))
  719. (guard (c ((store-protocol-error? c) #t))
  720. (build-derivations %store (list d))
  721. #f)))
  722. (test-assert "search paths"
  723. (let* ((p (make-prompt-tag "return-search-paths"))
  724. (s (build-system
  725. (name 'raw)
  726. (description "Raw build system with direct store access")
  727. (lower (lambda* (name #:key source inputs system target
  728. #:allow-other-keys)
  729. (bag
  730. (name name)
  731. (system system) (target target)
  732. (build-inputs inputs)
  733. (build
  734. (lambda* (store name inputs
  735. #:key outputs system search-paths)
  736. search-paths)))))))
  737. (x (list (search-path-specification
  738. (variable "GUILE_LOAD_PATH")
  739. (files '("share/guile/site/2.0")))
  740. (search-path-specification
  741. (variable "GUILE_LOAD_COMPILED_PATH")
  742. (files '("share/guile/site/2.0")))))
  743. (a (package (inherit (dummy-package "guile"))
  744. (build-system s)
  745. (native-search-paths x)))
  746. (b (package (inherit (dummy-package "guile-foo"))
  747. (build-system s)
  748. (inputs `(("guile" ,a)))))
  749. (c (package (inherit (dummy-package "guile-bar"))
  750. (build-system s)
  751. (inputs `(("guile" ,a)
  752. ("guile-foo" ,b))))))
  753. (let-syntax ((collect (syntax-rules ()
  754. ((_ body ...)
  755. (call-with-prompt p
  756. (lambda ()
  757. body ...)
  758. (lambda (k search-paths)
  759. search-paths))))))
  760. (and (null? (collect (package-derivation %store a)))
  761. (equal? x (collect (package-derivation %store b)))
  762. (equal? x (collect (package-derivation %store c)))))))
  763. (test-assert "package-transitive-native-search-paths"
  764. (let* ((sp (lambda (name)
  765. (list (search-path-specification
  766. (variable name)
  767. (files '("foo/bar"))))))
  768. (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
  769. (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
  770. (p2 (dummy-package "p2"
  771. (native-search-paths (sp "PATH2"))
  772. (inputs `(("p0" ,p0)))
  773. (propagated-inputs `(("p1" ,p1)))))
  774. (p3 (dummy-package "p3"
  775. (native-search-paths (sp "PATH3"))
  776. (native-inputs `(("p0" ,p0)))
  777. (propagated-inputs `(("p2" ,p2))))))
  778. (lset= string=?
  779. '("PATH1" "PATH2" "PATH3")
  780. (map search-path-specification-variable
  781. (package-transitive-native-search-paths p3)))))
  782. (test-assert "package-cross-derivation"
  783. (let ((drv (package-cross-derivation %store (dummy-package "p")
  784. "mips64el-linux-gnu")))
  785. (and (derivation? drv)
  786. (file-exists? (derivation-file-name drv)))))
  787. (test-assert "package-cross-derivation, trivial-build-system"
  788. (let ((p (package (inherit (dummy-package "p"))
  789. (build-system trivial-build-system)
  790. (arguments '(#:builder (exit 1))))))
  791. (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
  792. (derivation? drv))))
  793. (test-assert "package-cross-derivation, no cross builder"
  794. (let* ((b (build-system (inherit trivial-build-system)
  795. (lower (const #f))))
  796. (p (package (inherit (dummy-package "p"))
  797. (build-system b))))
  798. (guard (c ((package-cross-build-system-error? c)
  799. (eq? (package-error-package c) p)))
  800. (package-cross-derivation %store p "mips64el-linux-gnu")
  801. #f)))
  802. ;; XXX: The next two tests can trigger builds when the distro defines
  803. ;; replacements on core packages, so they're disable for lack of a better
  804. ;; solution.
  805. ;; (test-equal "package-derivation, direct graft"
  806. ;; (package-derivation %store gnu-make #:graft? #f)
  807. ;; (let ((p (package (inherit coreutils)
  808. ;; (replacement gnu-make))))
  809. ;; (package-derivation %store p #:graft? #t)))
  810. ;; (test-equal "package-cross-derivation, direct graft"
  811. ;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
  812. ;; #:graft? #f)
  813. ;; (let ((p (package (inherit coreutils)
  814. ;; (replacement gnu-make))))
  815. ;; (package-cross-derivation %store p "mips64el-linux-gnu"
  816. ;; #:graft? #t)))
  817. (test-assert "package-grafts, indirect grafts"
  818. (let* ((new (dummy-package "dep"
  819. (arguments '(#:implicit-inputs? #f))))
  820. (dep (package (inherit new) (version "0.0")))
  821. (dep* (package (inherit dep) (replacement new)))
  822. (dummy (dummy-package "dummy"
  823. (arguments '(#:implicit-inputs? #f))
  824. (inputs `(("dep" ,dep*))))))
  825. (equal? (package-grafts %store dummy)
  826. (list (graft
  827. (origin (package-derivation %store dep))
  828. (replacement (package-derivation %store new)))))))
  829. ;; XXX: This test would require building the cross toolchain just to see if it
  830. ;; needs grafting, which is obviously too expensive, and thus disabled.
  831. ;;
  832. ;; (test-assert "package-grafts, indirect grafts, cross"
  833. ;; (let* ((new (dummy-package "dep"
  834. ;; (arguments '(#:implicit-inputs? #f))))
  835. ;; (dep (package (inherit new) (version "0.0")))
  836. ;; (dep* (package (inherit dep) (replacement new)))
  837. ;; (dummy (dummy-package "dummy"
  838. ;; (arguments '(#:implicit-inputs? #f))
  839. ;; (inputs `(("dep" ,dep*)))))
  840. ;; (target "mips64el-linux-gnu"))
  841. ;; ;; XXX: There might be additional grafts, for instance if the distro
  842. ;; ;; defines replacements for core packages like Perl.
  843. ;; (member (graft
  844. ;; (origin (package-cross-derivation %store dep target))
  845. ;; (replacement
  846. ;; (package-cross-derivation %store new target)))
  847. ;; (package-grafts %store dummy #:target target))))
  848. (test-assert "package-grafts, indirect grafts, propagated inputs"
  849. (let* ((new (dummy-package "dep"
  850. (arguments '(#:implicit-inputs? #f))))
  851. (dep (package (inherit new) (version "0.0")))
  852. (dep* (package (inherit dep) (replacement new)))
  853. (prop (dummy-package "propagated"
  854. (propagated-inputs `(("dep" ,dep*)))
  855. (arguments '(#:implicit-inputs? #f))))
  856. (dummy (dummy-package "dummy"
  857. (arguments '(#:implicit-inputs? #f))
  858. (inputs `(("prop" ,prop))))))
  859. (equal? (package-grafts %store dummy)
  860. (list (graft
  861. (origin (package-derivation %store dep))
  862. (replacement (package-derivation %store new)))))))
  863. (test-assert "package-grafts, same replacement twice"
  864. (let* ((new (dummy-package "dep"
  865. (version "1")
  866. (arguments '(#:implicit-inputs? #f))))
  867. (dep (package (inherit new) (version "0") (replacement new)))
  868. (p1 (dummy-package "intermediate1"
  869. (arguments '(#:implicit-inputs? #f))
  870. (inputs `(("dep" ,dep)))))
  871. (p2 (dummy-package "intermediate2"
  872. (arguments '(#:implicit-inputs? #f))
  873. ;; Here we copy DEP to have an equivalent package that is not
  874. ;; 'eq?' to DEP. This is similar to what happens with
  875. ;; 'package-with-explicit-inputs' & co.
  876. (inputs `(("dep" ,(package (inherit dep)))))))
  877. (p3 (dummy-package "final"
  878. (arguments '(#:implicit-inputs? #f))
  879. (inputs `(("p1" ,p1) ("p2" ,p2))))))
  880. (equal? (package-grafts %store p3)
  881. (list (graft
  882. (origin (package-derivation %store
  883. (package (inherit dep)
  884. (replacement #f))))
  885. (replacement (package-derivation %store new)))))))
  886. (test-assert "package-grafts, dependency on several outputs"
  887. ;; Make sure we get one graft per output; see <https://bugs.gnu.org/41796>.
  888. (letrec* ((p0 (dummy-package "p0"
  889. (version "1.0")
  890. (replacement p0*)
  891. (arguments '(#:implicit-inputs? #f))
  892. (outputs '("out" "lib"))))
  893. (p0* (package (inherit p0) (version "1.1")))
  894. (p1 (dummy-package "p1"
  895. (arguments '(#:implicit-inputs? #f))
  896. (inputs `(("p0" ,p0)
  897. ("p0:lib" ,p0 "lib"))))))
  898. (lset= equal? (pk (package-grafts %store p1))
  899. (list (graft
  900. (origin (package-derivation %store p0))
  901. (origin-output "out")
  902. (replacement (package-derivation %store p0*))
  903. (replacement-output "out"))
  904. (graft
  905. (origin (package-derivation %store p0))
  906. (origin-output "lib")
  907. (replacement (package-derivation %store p0*))
  908. (replacement-output "lib"))))))
  909. (test-assert "replacement also grafted"
  910. ;; We build a DAG as below, where dotted arrows represent replacements and
  911. ;; solid arrows represent dependencies:
  912. ;;
  913. ;; P1 ·············> P1R
  914. ;; |\__________________.
  915. ;; v v
  916. ;; P2 ·············> P2R
  917. ;; |
  918. ;; v
  919. ;; P3
  920. ;;
  921. ;; We want to make sure that:
  922. ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
  923. ;; where:
  924. ;; (A,B) is a graft to replace A by B
  925. ;; grafted(DRV,G) denoted DRV with graft G applied
  926. (let* ((p1r (dummy-package "P1"
  927. (build-system trivial-build-system)
  928. (arguments
  929. `(#:guile ,%bootstrap-guile
  930. #:builder (let ((out (assoc-ref %outputs "out")))
  931. (mkdir out)
  932. (call-with-output-file
  933. (string-append out "/replacement")
  934. (const #t)))))))
  935. (p1 (package
  936. (inherit p1r) (name "p1") (replacement p1r)
  937. (arguments
  938. `(#:guile ,%bootstrap-guile
  939. #:builder (begin
  940. (mkdir (assoc-ref %outputs "out"))
  941. #t)))))
  942. (p2r (dummy-package "P2"
  943. (build-system trivial-build-system)
  944. (inputs `(("p1" ,p1)))
  945. (arguments
  946. `(#:guile ,%bootstrap-guile
  947. #:builder (let ((out (assoc-ref %outputs "out")))
  948. (mkdir out)
  949. (chdir out)
  950. (symlink (assoc-ref %build-inputs "p1") "p1")
  951. (call-with-output-file (string-append out "/replacement")
  952. (const #t)))))))
  953. (p2 (package
  954. (inherit p2r) (name "p2") (replacement p2r)
  955. (arguments
  956. `(#:guile ,%bootstrap-guile
  957. #:builder (let ((out (assoc-ref %outputs "out")))
  958. (mkdir out)
  959. (chdir out)
  960. (symlink (assoc-ref %build-inputs "p1")
  961. "p1")
  962. #t)))))
  963. (p3 (dummy-package "p3"
  964. (build-system trivial-build-system)
  965. (inputs `(("p2" ,p2)))
  966. (arguments
  967. `(#:guile ,%bootstrap-guile
  968. #:builder (let ((out (assoc-ref %outputs "out")))
  969. (mkdir out)
  970. (chdir out)
  971. (symlink (assoc-ref %build-inputs "p2")
  972. "p2")
  973. #t))))))
  974. (lset= equal?
  975. (package-grafts %store p3)
  976. (list (graft
  977. (origin (package-derivation %store p1 #:graft? #f))
  978. (replacement (package-derivation %store p1r)))
  979. (graft
  980. (origin (package-derivation %store p2 #:graft? #f))
  981. (replacement
  982. (package-derivation %store p2r #:graft? #t)))))))
  983. ;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
  984. ;;; find out about their run-time dependencies, so this test is no longer
  985. ;;; applicable since it would trigger a full rebuild.
  986. ;;
  987. ;; (test-assert "package-derivation, indirect grafts"
  988. ;; (let* ((new (dummy-package "dep"
  989. ;; (arguments '(#:implicit-inputs? #f))))
  990. ;; (dep (package (inherit new) (version "0.0")))
  991. ;; (dep* (package (inherit dep) (replacement new)))
  992. ;; (dummy (dummy-package "dummy"
  993. ;; (arguments '(#:implicit-inputs? #f))
  994. ;; (inputs `(("dep" ,dep*)))))
  995. ;; (guile (package-derivation %store (canonical-package guile-2.0)
  996. ;; #:graft? #f)))
  997. ;; (equal? (package-derivation %store dummy)
  998. ;; (graft-derivation %store
  999. ;; (package-derivation %store dummy #:graft? #f)
  1000. ;; (package-grafts %store dummy)
  1001. ;; ;; Use the same Guile as 'package-derivation'.
  1002. ;; #:guile guile))))
  1003. (test-equal "package->bag"
  1004. `("foo86-hurd" #f (,(package-source gnu-make))
  1005. (,(canonical-package glibc)) (,(canonical-package coreutils)))
  1006. (let ((bag (package->bag gnu-make "foo86-hurd")))
  1007. (list (bag-system bag) (bag-target bag)
  1008. (assoc-ref (bag-build-inputs bag) "source")
  1009. (assoc-ref (bag-build-inputs bag) "libc")
  1010. (assoc-ref (bag-build-inputs bag) "coreutils"))))
  1011. (test-assert "package->bag, sensitivity to %current-target-system"
  1012. ;; https://bugs.gnu.org/41713
  1013. (let* ((lower (lambda* (name #:key system target inputs native-inputs
  1014. #:allow-other-keys)
  1015. (and (not target)
  1016. (bag (name name) (system system) (target target)
  1017. (build-inputs native-inputs)
  1018. (host-inputs inputs)
  1019. (build (lambda* (store name inputs
  1020. #:key system target
  1021. #:allow-other-keys)
  1022. (build-expression->derivation
  1023. store "foo" '(mkdir %output))))))))
  1024. (bs (build-system
  1025. (name 'build-system-without-cross-compilation)
  1026. (description "Does not support cross compilation.")
  1027. (lower lower)))
  1028. (dep (dummy-package "dep" (build-system bs)))
  1029. (pkg (dummy-package "example"
  1030. (native-inputs `(("dep" ,dep)))))
  1031. (do-not-build (lambda (continue store lst . _) lst)))
  1032. (equal? (with-build-handler do-not-build
  1033. (parameterize ((%current-target-system "powerpc64le-linux-gnu")
  1034. (%graft? #t))
  1035. (package-cross-derivation %store pkg
  1036. (%current-target-system)
  1037. #:graft? #t)))
  1038. (with-build-handler do-not-build
  1039. (package-cross-derivation %store
  1040. (package (inherit pkg))
  1041. "powerpc64le-linux-gnu"
  1042. #:graft? #t)))))
  1043. (test-equal "package->bag, cross-compilation"
  1044. `(,(%current-system) "foo86-hurd"
  1045. (,(package-source gnu-make))
  1046. (,(canonical-package glibc)) (,(canonical-package coreutils)))
  1047. (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
  1048. (list (bag-system bag) (bag-target bag)
  1049. (assoc-ref (bag-build-inputs bag) "source")
  1050. (assoc-ref (bag-build-inputs bag) "libc")
  1051. (assoc-ref (bag-build-inputs bag) "coreutils"))))
  1052. (test-assert "package->bag, propagated inputs"
  1053. (let* ((dep (dummy-package "dep"))
  1054. (prop (dummy-package "prop"
  1055. (propagated-inputs `(("dep" ,dep)))))
  1056. (dummy (dummy-package "dummy"
  1057. (inputs `(("prop" ,prop)))))
  1058. (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
  1059. (match (assoc "dep" inputs)
  1060. (("dep" package)
  1061. (eq? package dep)))))
  1062. (test-assert "package->bag, sensitivity to %current-system"
  1063. (let* ((dep (dummy-package "dep"
  1064. (propagated-inputs (if (string=? (%current-system)
  1065. "i586-gnu")
  1066. `(("libxml2" ,libxml2))
  1067. '()))))
  1068. (pkg (dummy-package "foo"
  1069. (native-inputs `(("dep" ,dep)))))
  1070. (bag (package->bag pkg (%current-system) "i586-gnu")))
  1071. (equal? (parameterize ((%current-system "x86_64-linux"))
  1072. (bag-transitive-inputs bag))
  1073. (parameterize ((%current-system "i586-gnu"))
  1074. (bag-transitive-inputs bag)))))
  1075. (test-assert "package->bag, sensitivity to %current-target-system"
  1076. (let* ((dep (dummy-package "dep"
  1077. (propagated-inputs (if (%current-target-system)
  1078. `(("libxml2" ,libxml2))
  1079. '()))))
  1080. (pkg (dummy-package "foo"
  1081. (native-inputs `(("dep" ,dep)))))
  1082. (bag (package->bag pkg (%current-system) "foo86-hurd")))
  1083. (equal? (parameterize ((%current-target-system "foo64-gnu"))
  1084. (bag-transitive-inputs bag))
  1085. (parameterize ((%current-target-system #f))
  1086. (bag-transitive-inputs bag)))))
  1087. (test-assert "bag->derivation"
  1088. (parameterize ((%graft? #f))
  1089. (let ((bag (package->bag gnu-make))
  1090. (drv (package-derivation %store gnu-make)))
  1091. (parameterize ((%current-system "foox86-hurd")) ;should have no effect
  1092. (equal? drv (bag->derivation %store bag))))))
  1093. (test-assert "bag->derivation, cross-compilation"
  1094. (parameterize ((%graft? #f))
  1095. (let* ((target "mips64el-linux-gnu")
  1096. (bag (package->bag gnu-make (%current-system) target))
  1097. (drv (package-cross-derivation %store gnu-make target)))
  1098. (parameterize ((%current-system "foox86-hurd") ;should have no effect
  1099. (%current-target-system "foo64-linux-gnu"))
  1100. (equal? drv (bag->derivation %store bag))))))
  1101. (when (or (not (network-reachable?)) (shebang-too-long?))
  1102. (test-skip 1))
  1103. (test-assert "GNU Make, bootstrap"
  1104. ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the
  1105. ;; test doesn't last for too long.
  1106. (let ((gnu-make gnu-make-for-tests))
  1107. (and (package? gnu-make)
  1108. (or (location? (package-location gnu-make))
  1109. (not (package-location gnu-make)))
  1110. (let* ((drv (package-derivation %store gnu-make))
  1111. (out (derivation->output-path drv)))
  1112. (and (build-derivations %store (list drv))
  1113. (file-exists? (string-append out "/bin/make")))))))
  1114. (test-equal "package-mapping"
  1115. 42
  1116. (let* ((dep (dummy-package "chbouib"
  1117. (native-inputs `(("x" ,grep)))))
  1118. (p0 (dummy-package "example"
  1119. (source 77)
  1120. (inputs `(("foo" ,coreutils)
  1121. ("bar" ,grep)
  1122. ("baz" ,dep)))))
  1123. (transform (lambda (p)
  1124. (package (inherit p) (source 42))))
  1125. (rewrite (package-mapping transform))
  1126. (p1 (rewrite p0))
  1127. (bag0 (package->bag p0))
  1128. (bag1 (package->bag p1)))
  1129. (and (eq? p1 (rewrite p0))
  1130. (eqv? 42 (package-source p1))
  1131. ;; Implicit inputs should be left unchanged (skip "source", "foo",
  1132. ;; "bar", and "baz" in this comparison).
  1133. (equal? (drop (bag-direct-inputs bag0) 4)
  1134. (drop (bag-direct-inputs bag1) 4))
  1135. (match (package-inputs p1)
  1136. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  1137. (and (eq? dep1 (rewrite coreutils)) ;memoization
  1138. (eq? dep2 (rewrite grep))
  1139. (eq? dep3 (rewrite dep))
  1140. (eqv? 42
  1141. (package-source dep1) (package-source dep2)
  1142. (package-source dep3))
  1143. (match (package-native-inputs dep3)
  1144. ((("x" dep))
  1145. (and (eq? dep (rewrite grep))
  1146. (package-source dep))))))))))
  1147. (test-equal "package-mapping, deep"
  1148. '(42)
  1149. (let* ((p0 (dummy-package "example"
  1150. (inputs `(("foo" ,coreutils)
  1151. ("bar" ,grep)))))
  1152. (transform (lambda (p)
  1153. (package (inherit p) (source 42))))
  1154. (rewrite (package-mapping transform #:deep? #t))
  1155. (p1 (rewrite p0))
  1156. (bag (package->bag p1)))
  1157. (and (eq? p1 (rewrite p0))
  1158. (match (bag-direct-inputs bag)
  1159. ((("source" 42) ("foo" dep1) ("bar" dep2) rest ..1)
  1160. (and (eq? dep1 (rewrite coreutils)) ;memoization
  1161. (eq? dep2 (rewrite grep))
  1162. (= 42 (package-source dep1))
  1163. (= 42 (package-source dep2))
  1164. ;; Check that implicit inputs of P0 also got rewritten.
  1165. (delete-duplicates
  1166. (map (match-lambda
  1167. ((_ package . _)
  1168. (package-source package)))
  1169. rest))))))))
  1170. (test-assert "package-input-rewriting"
  1171. (let* ((dep (dummy-package "chbouib"
  1172. (native-inputs `(("x" ,grep)))))
  1173. (p0 (dummy-package "example"
  1174. (inputs `(("foo" ,coreutils)
  1175. ("bar" ,grep)
  1176. ("baz" ,dep)))))
  1177. (rewrite (package-input-rewriting `((,coreutils . ,sed)
  1178. (,grep . ,findutils))
  1179. (cut string-append "r-" <>)
  1180. #:deep? #f))
  1181. (p1 (rewrite p0))
  1182. (p2 (rewrite p0)))
  1183. (and (not (eq? p1 p0))
  1184. (eq? p1 p2) ;memoization
  1185. (string=? "r-example" (package-name p1))
  1186. (match (package-inputs p1)
  1187. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  1188. (and (eq? dep1 sed)
  1189. (eq? dep2 findutils)
  1190. (string=? (package-name dep3) "r-chbouib")
  1191. (eq? dep3 (rewrite dep)) ;memoization
  1192. (match (package-native-inputs dep3)
  1193. ((("x" dep))
  1194. (eq? dep findutils))))))
  1195. ;; Make sure implicit inputs were left unchanged.
  1196. (equal? (drop (bag-direct-inputs (package->bag p1)) 3)
  1197. (drop (bag-direct-inputs (package->bag p0)) 3)))))
  1198. (test-eq "package-input-rewriting, deep"
  1199. (derivation-file-name (package-derivation %store sed))
  1200. (let* ((p0 (dummy-package "chbouib"
  1201. (build-system python-build-system)
  1202. (arguments `(#:python ,python))))
  1203. (rewrite (package-input-rewriting `((,python . ,sed))))
  1204. (p1 (rewrite p0)))
  1205. (match (bag-direct-inputs (package->bag p1))
  1206. ((("python" python) _ ...)
  1207. (derivation-file-name (package-derivation %store python))))))
  1208. (test-assert "package-input-rewriting/spec"
  1209. (let* ((dep (dummy-package "chbouib"
  1210. (native-inputs `(("x" ,grep)))))
  1211. (p0 (dummy-package "example"
  1212. (inputs `(("foo" ,coreutils)
  1213. ("bar" ,grep)
  1214. ("baz" ,dep)))))
  1215. (rewrite (package-input-rewriting/spec
  1216. `(("coreutils" . ,(const sed))
  1217. ("grep" . ,(const findutils)))
  1218. #:deep? #f))
  1219. (p1 (rewrite p0))
  1220. (p2 (rewrite p0)))
  1221. (and (not (eq? p1 p0))
  1222. (eq? p1 p2) ;memoization
  1223. (string=? "example" (package-name p1))
  1224. (match (package-inputs p1)
  1225. ((("foo" dep1) ("bar" dep2) ("baz" dep3))
  1226. (and (string=? (package-full-name dep1)
  1227. (package-full-name sed))
  1228. (string=? (package-full-name dep2)
  1229. (package-full-name findutils))
  1230. (string=? (package-name dep3) "chbouib")
  1231. (eq? dep3 (rewrite dep)) ;memoization
  1232. (match (package-native-inputs dep3)
  1233. ((("x" dep))
  1234. (string=? (package-full-name dep)
  1235. (package-full-name findutils)))))))
  1236. ;; Make sure implicit inputs were left unchanged.
  1237. (equal? (drop (bag-direct-inputs (package->bag p1)) 3)
  1238. (drop (bag-direct-inputs (package->bag p0)) 3)))))
  1239. (test-assert "package-input-rewriting/spec, partial match"
  1240. (let* ((dep (dummy-package "chbouib"
  1241. (version "1")
  1242. (native-inputs `(("x" ,grep)))))
  1243. (p0 (dummy-package "example"
  1244. (inputs `(("foo" ,coreutils)
  1245. ("bar" ,dep)))))
  1246. (rewrite (package-input-rewriting/spec
  1247. `(("chbouib@123" . ,(const sed)) ;not matched
  1248. ("grep" . ,(const findutils)))
  1249. #:deep? #f))
  1250. (p1 (rewrite p0)))
  1251. (and (not (eq? p1 p0))
  1252. (string=? "example" (package-name p1))
  1253. (match (package-inputs p1)
  1254. ((("foo" dep1) ("bar" dep2))
  1255. (and (string=? (package-full-name dep1)
  1256. (package-full-name coreutils))
  1257. (eq? dep2 (rewrite dep)) ;memoization
  1258. (match (package-native-inputs dep2)
  1259. ((("x" dep))
  1260. (string=? (package-full-name dep)
  1261. (package-full-name findutils))))))))))
  1262. (test-assert "package-input-rewriting/spec, deep"
  1263. (let* ((dep (dummy-package "chbouib"))
  1264. (p0 (dummy-package "example"
  1265. (build-system gnu-build-system)
  1266. (inputs `(("dep" ,dep)))))
  1267. (rewrite (package-input-rewriting/spec
  1268. `(("tar" . ,(const sed))
  1269. ("gzip" . ,(const findutils)))))
  1270. (p1 (rewrite p0))
  1271. (p2 (rewrite p0)))
  1272. (and (not (eq? p1 p0))
  1273. (eq? p1 p2) ;memoization
  1274. (string=? "example" (package-name p1))
  1275. (match (package-inputs p1)
  1276. ((("dep" dep1))
  1277. (and (string=? (package-full-name dep1)
  1278. (package-full-name dep))
  1279. (eq? dep1 (rewrite dep))))) ;memoization
  1280. ;; Make sure implicit inputs were replaced.
  1281. (match (bag-direct-inputs (package->bag p1))
  1282. ((("dep" dep1) ("tar" tar) ("gzip" gzip) _ ...)
  1283. (and (eq? dep1 (rewrite dep))
  1284. (string=? (package-full-name tar)
  1285. (package-full-name sed))
  1286. (string=? (package-full-name gzip)
  1287. (package-full-name findutils))))))))
  1288. (test-assert "package-input-rewriting/spec, no duplicates"
  1289. ;; Ensure that deep input rewriting does not forget implicit inputs. Doing
  1290. ;; so could lead to duplicates in a package's inputs: in the example below,
  1291. ;; P0's transitive inputs would contain one rewritten "python" and one
  1292. ;; original "python". These two "python" packages are thus not 'eq?' but
  1293. ;; they lower to the same derivation. See <https://bugs.gnu.org/42156>,
  1294. ;; which can be reproduced by passing #:deep? #f.
  1295. (let* ((dep0 (dummy-package "dep0"
  1296. (build-system trivial-build-system)
  1297. (propagated-inputs `(("python" ,python)))))
  1298. (p0 (dummy-package "chbouib"
  1299. (build-system python-build-system)
  1300. (arguments `(#:python ,python))
  1301. (inputs `(("dep0" ,dep0)))))
  1302. (rewrite (package-input-rewriting/spec '() #:deep? #t))
  1303. (p1 (rewrite p0))
  1304. (bag1 (package->bag p1))
  1305. (pythons (filter-map (match-lambda
  1306. (("python" python) python)
  1307. (_ #f))
  1308. (bag-transitive-inputs bag1))))
  1309. (match (delete-duplicates pythons eq?)
  1310. ((p) (eq? p (rewrite python))))))
  1311. (test-equal "package-input-rewriting/spec, graft"
  1312. (derivation-file-name (package-derivation %store sed))
  1313. ;; Make sure replacements are rewritten.
  1314. (let* ((dep0 (dummy-package "dep"
  1315. (version "1")
  1316. (build-system trivial-build-system)
  1317. (inputs `(("coreutils" ,coreutils)))))
  1318. (dep1 (dummy-package "dep"
  1319. (version "0")
  1320. (build-system trivial-build-system)
  1321. (replacement dep0)))
  1322. (p0 (dummy-package "p"
  1323. (build-system trivial-build-system)
  1324. (inputs `(("dep" ,dep1)))))
  1325. (rewrite (package-input-rewriting/spec
  1326. `(("coreutils" . ,(const sed)))))
  1327. (p1 (rewrite p0)))
  1328. (match (package-inputs p1)
  1329. ((("dep" dep))
  1330. (match (package-inputs (package-replacement dep))
  1331. ((("coreutils" coreutils))
  1332. ;; COREUTILS is not 'eq?' to SED, so the most reliable way to check
  1333. ;; for equality is to lower to a derivation.
  1334. (derivation-file-name
  1335. (package-derivation %store coreutils))))))))
  1336. (test-assert "package-with-c-toolchain"
  1337. (let* ((dep (dummy-package "chbouib"
  1338. (build-system gnu-build-system)
  1339. (native-inputs `(("x" ,grep)))))
  1340. (p0 (dummy-package "thingie"
  1341. (build-system gnu-build-system)
  1342. (inputs `(("foo" ,grep)
  1343. ("bar" ,dep)))))
  1344. (tc (dummy-package "my-toolchain"))
  1345. (p1 (package-with-c-toolchain p0 `(("toolchain" ,tc)))))
  1346. (define toolchain-packages
  1347. '("gcc" "binutils" "glibc" "ld-wrapper"))
  1348. (match (bag-build-inputs (package->bag p1))
  1349. ((("foo" foo) ("bar" bar) (_ (= package-name packages) . _) ...)
  1350. (and (not (any (cut member <> packages) toolchain-packages))
  1351. (member "my-toolchain" packages)
  1352. (eq? foo grep)
  1353. (eq? bar dep))))))
  1354. (test-assert "package-input-rewriting/spec, identity"
  1355. ;; Make sure that 'package-input-rewriting/spec' doesn't gratuitously
  1356. ;; introduce variants. In this case, the LIBFFI propagated input should not
  1357. ;; be duplicated when passing GOBJECT through REWRITE.
  1358. ;; See <https://issues.guix.gnu.org/43890>.
  1359. (let* ((libffi (dummy-package "libffi"
  1360. (build-system trivial-build-system)))
  1361. (glib (dummy-package "glib"
  1362. (build-system trivial-build-system)
  1363. (propagated-inputs `(("libffi" ,libffi)))))
  1364. (gobject (dummy-package "gobject-introspection"
  1365. (build-system trivial-build-system)
  1366. (inputs `(("glib" ,glib)))
  1367. (propagated-inputs `(("libffi" ,libffi)))))
  1368. (rewrite (package-input-rewriting/spec
  1369. `(("glib" . ,identity)))))
  1370. (and (= (length (package-transitive-inputs gobject))
  1371. (length (package-transitive-inputs (rewrite gobject))))
  1372. (string=? (derivation-file-name
  1373. (package-derivation %store (rewrite gobject)))
  1374. (derivation-file-name
  1375. (package-derivation %store gobject))))))
  1376. (test-assert "package-input-rewriting, identity"
  1377. ;; Similar to the test above, but with 'package-input-rewriting'.
  1378. ;; See <https://issues.guix.gnu.org/43890>.
  1379. (let* ((libffi (dummy-package "libffi"
  1380. (build-system trivial-build-system)))
  1381. (glib (dummy-package "glib"
  1382. (build-system trivial-build-system)
  1383. (propagated-inputs `(("libffi" ,libffi)))))
  1384. (gobject (dummy-package "gobject-introspection"
  1385. (build-system trivial-build-system)
  1386. (inputs `(("glib" ,glib)))
  1387. (propagated-inputs `(("libffi" ,libffi)))))
  1388. (rewrite (package-input-rewriting `((,glib . ,glib)))))
  1389. (and (= (length (package-transitive-inputs gobject))
  1390. (length (package-transitive-inputs (rewrite gobject))))
  1391. (string=? (derivation-file-name
  1392. (package-derivation %store (rewrite gobject)))
  1393. (derivation-file-name
  1394. (package-derivation %store gobject))))))
  1395. (test-equal "package-patched-vulnerabilities"
  1396. '(("CVE-2015-1234")
  1397. ("CVE-2016-1234" "CVE-2018-4567")
  1398. ())
  1399. (let ((p1 (dummy-package "pi"
  1400. (source (dummy-origin
  1401. (patches (list "/a/b/pi-CVE-2015-1234.patch"))))))
  1402. (p2 (dummy-package "pi"
  1403. (source (dummy-origin
  1404. (patches (list
  1405. "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch"))))))
  1406. (p3 (dummy-package "pi" (source (dummy-origin)))))
  1407. (map package-patched-vulnerabilities
  1408. (list p1 p2 p3))))
  1409. (test-eq "fold-packages" hello
  1410. (fold-packages (lambda (p r)
  1411. (if (string=? (package-name p) "hello")
  1412. p
  1413. r))
  1414. #f))
  1415. (test-assert "fold-packages, hidden package"
  1416. ;; There are two public variables providing "guile@2.0" ('guile-final' in
  1417. ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
  1418. ;; should show up.
  1419. (match (fold-packages (lambda (p r)
  1420. (if (and (string=? (package-name p) "guile")
  1421. (string-prefix? "2.0"
  1422. (package-version p)))
  1423. (cons p r)
  1424. r))
  1425. '())
  1426. ((one)
  1427. (eq? one guile-2.0))))
  1428. (test-assert "fold-available-packages with/without cache"
  1429. (let ()
  1430. (define no-cache
  1431. (fold-available-packages (lambda* (name version result #:rest rest)
  1432. (cons (cons* name version rest)
  1433. result))
  1434. '()))
  1435. (define from-cache
  1436. (call-with-temporary-directory
  1437. (lambda (cache)
  1438. (generate-package-cache cache)
  1439. (mock ((guix describe) current-profile (const cache))
  1440. (mock ((gnu packages) cache-is-authoritative? (const #t))
  1441. (fold-available-packages (lambda* (name version result
  1442. #:rest rest)
  1443. (cons (cons* name version rest)
  1444. result))
  1445. '()))))))
  1446. (define (find-duplicates l)
  1447. (match l
  1448. (() '())
  1449. ((head . tail)
  1450. (if (member head tail)
  1451. (cons head (find-duplicates tail))
  1452. (find-duplicates tail)))))
  1453. (pk (find-duplicates from-cache))
  1454. (and (equal? (delete-duplicates from-cache) from-cache)
  1455. (lset= equal? no-cache from-cache))))
  1456. (test-assert "find-packages-by-name"
  1457. (match (find-packages-by-name "hello")
  1458. (((? (cut eq? hello <>))) #t)
  1459. (wrong (pk 'find-packages-by-name wrong #f))))
  1460. (test-assert "find-packages-by-name with version"
  1461. (match (find-packages-by-name "hello" (package-version hello))
  1462. (((? (cut eq? hello <>))) #t)
  1463. (wrong (pk 'find-packages-by-name wrong #f))))
  1464. (test-equal "find-packages-by-name with cache"
  1465. (find-packages-by-name "guile")
  1466. (call-with-temporary-directory
  1467. (lambda (cache)
  1468. (generate-package-cache cache)
  1469. (mock ((guix describe) current-profile (const cache))
  1470. (mock ((gnu packages) cache-is-authoritative? (const #t))
  1471. (find-packages-by-name "guile"))))))
  1472. (test-equal "find-packages-by-name + version, with cache"
  1473. (find-packages-by-name "guile" "2")
  1474. (call-with-temporary-directory
  1475. (lambda (cache)
  1476. (generate-package-cache cache)
  1477. (mock ((guix describe) current-profile (const cache))
  1478. (mock ((gnu packages) cache-is-authoritative? (const #t))
  1479. (find-packages-by-name "guile" "2"))))))
  1480. (test-assert "--search-paths with pattern"
  1481. ;; Make sure 'guix package --search-paths' correctly reports environment
  1482. ;; variables when file patterns are used (in particular, it must follow
  1483. ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
  1484. ;; libxml2 package specification, which contains such a definition.
  1485. (let* ((p1 (package
  1486. (name "foo") (version "0") (source #f)
  1487. (build-system trivial-build-system)
  1488. (arguments
  1489. `(#:guile ,%bootstrap-guile
  1490. #:modules ((guix build utils))
  1491. #:builder (begin
  1492. (use-modules (guix build utils))
  1493. (let ((out (assoc-ref %outputs "out")))
  1494. (mkdir-p (string-append out "/xml/bar/baz"))
  1495. (call-with-output-file
  1496. (string-append out "/xml/bar/baz/catalog.xml")
  1497. (lambda (port)
  1498. (display "xml? wat?!" port)))
  1499. #t))))
  1500. (synopsis #f) (description #f)
  1501. (home-page #f) (license #f)))
  1502. (p2 (package
  1503. ;; Provide a fake libxml2 to avoid building the real one. This
  1504. ;; is OK because 'guix package' gets search path specifications
  1505. ;; from the same-named package found in the distro.
  1506. (name "libxml2") (version "0.0.0") (source #f)
  1507. (build-system trivial-build-system)
  1508. (arguments
  1509. `(#:guile ,%bootstrap-guile
  1510. #:builder (begin
  1511. (mkdir (assoc-ref %outputs "out"))
  1512. #t)))
  1513. (native-search-paths (package-native-search-paths libxml2))
  1514. (synopsis #f) (description #f)
  1515. (home-page #f) (license #f)))
  1516. (prof (run-with-store %store
  1517. (profile-derivation
  1518. (manifest (map package->manifest-entry
  1519. (list p1 p2)))
  1520. #:hooks '()
  1521. #:locales? #f)
  1522. #:guile-for-build (%guile-for-build))))
  1523. (build-derivations %store (list prof))
  1524. (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
  1525. (regexp-quote (derivation->output-path prof)))
  1526. (with-output-to-string
  1527. (lambda ()
  1528. (guix-package "-p" (derivation->output-path prof)
  1529. "--search-paths"))))))
  1530. (test-assert "--search-paths with single-item search path"
  1531. ;; Make sure 'guix package --search-paths' correctly reports environment
  1532. ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
  1533. ;; separator, meaning that the first match wins.
  1534. (let* ((p1 (dummy-package "foo"
  1535. (build-system trivial-build-system)
  1536. (arguments
  1537. `(#:guile ,%bootstrap-guile
  1538. #:modules ((guix build utils))
  1539. #:builder (begin
  1540. (use-modules (guix build utils))
  1541. (let ((out (assoc-ref %outputs "out")))
  1542. (mkdir-p (string-append out "/etc/ssl/certs"))
  1543. (call-with-output-file
  1544. (string-append
  1545. out "/etc/ssl/certs/ca-certificates.crt")
  1546. (const #t))))))))
  1547. (p2 (package (inherit p1) (name "bar")))
  1548. (p3 (dummy-package "git"
  1549. ;; Provide a fake Git to avoid building the real one.
  1550. (build-system trivial-build-system)
  1551. (arguments
  1552. `(#:guile ,%bootstrap-guile
  1553. #:builder (begin
  1554. (mkdir (assoc-ref %outputs "out"))
  1555. #t)))
  1556. (native-search-paths (package-native-search-paths git))))
  1557. (prof1 (run-with-store %store
  1558. (profile-derivation
  1559. (packages->manifest (list p1 p3))
  1560. #:hooks '()
  1561. #:locales? #f)
  1562. #:guile-for-build (%guile-for-build)))
  1563. (prof2 (run-with-store %store
  1564. (profile-derivation
  1565. (packages->manifest (list p2 p3))
  1566. #:hooks '()
  1567. #:locales? #f)
  1568. #:guile-for-build (%guile-for-build))))
  1569. (build-derivations %store (list prof1 prof2))
  1570. (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
  1571. (regexp-quote (derivation->output-path prof1)))
  1572. (with-output-to-string
  1573. (lambda ()
  1574. (guix-package "-p" (derivation->output-path prof1)
  1575. "-p" (derivation->output-path prof2)
  1576. "--search-paths"))))))
  1577. (test-equal "specification->package when not found"
  1578. 'quit
  1579. (catch 'quit
  1580. (lambda ()
  1581. ;; This should call 'leave', producing an error message.
  1582. (specification->package "this-package-does-not-exist"))
  1583. (lambda (key . args)
  1584. key)))
  1585. (test-equal "specification->package+output"
  1586. `((,coreutils "out") (,coreutils "debug"))
  1587. (list (call-with-values (lambda ()
  1588. (specification->package+output "coreutils"))
  1589. list)
  1590. (call-with-values (lambda ()
  1591. (specification->package+output "coreutils:debug"))
  1592. list)))
  1593. (test-equal "specification->package+output invalid output"
  1594. 'error
  1595. (catch 'quit
  1596. (lambda ()
  1597. (specification->package+output "coreutils:does-not-exist"))
  1598. (lambda _
  1599. 'error)))
  1600. (test-equal "specification->package+output no default output"
  1601. `(,coreutils #f)
  1602. (call-with-values
  1603. (lambda ()
  1604. (specification->package+output "coreutils" #f))
  1605. list))
  1606. (test-equal "specification->package+output invalid output, no default"
  1607. 'error
  1608. (catch 'quit
  1609. (lambda ()
  1610. (specification->package+output "coreutils:does-not-exist" #f))
  1611. (lambda _
  1612. 'error)))
  1613. (test-equal "find-package-locations"
  1614. (map (lambda (package)
  1615. (cons (package-version package)
  1616. (package-location package)))
  1617. (find-packages-by-name "guile"))
  1618. (find-package-locations "guile"))
  1619. (test-equal "find-package-locations with cache"
  1620. (map (lambda (package)
  1621. (cons (package-version package)
  1622. (package-location package)))
  1623. (find-packages-by-name "guile"))
  1624. (call-with-temporary-directory
  1625. (lambda (cache)
  1626. (generate-package-cache cache)
  1627. (mock ((guix describe) current-profile (const cache))
  1628. (mock ((gnu packages) cache-is-authoritative? (const #t))
  1629. (find-package-locations "guile"))))))
  1630. (test-equal "specification->location"
  1631. (package-location (specification->package "guile@2"))
  1632. (specification->location "guile@2"))
  1633. (test-end "packages")
  1634. ;;; Local Variables:
  1635. ;;; eval: (put 'dummy-package 'scheme-indent-function 1)
  1636. ;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1)
  1637. ;;; End: