packages.scm 78 KB

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