packages.scm 88 KB

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