packages.scm 84 KB

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