packages.scm 78 KB

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