packages.scm 90 KB

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