packages.scm 89 KB

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