gexp.scm 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014-2022 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  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-gexp)
  20. #:use-module (guix store)
  21. #:use-module (guix monads)
  22. #:use-module (guix gexp)
  23. #:use-module (guix grafts)
  24. #:use-module (guix derivations)
  25. #:use-module (guix packages)
  26. #:use-module (guix build-system trivial)
  27. #:use-module (guix tests)
  28. #:use-module ((guix build utils) #:select (with-directory-excursion))
  29. #:use-module ((guix utils) #:select (call-with-temporary-directory))
  30. #:use-module ((guix ui) #:select (load*))
  31. #:use-module (gnu packages)
  32. #:use-module (gnu packages base)
  33. #:use-module (gnu packages bootstrap)
  34. #:use-module ((guix diagnostics) #:select (guix-warning-port))
  35. #:use-module (srfi srfi-1)
  36. #:use-module (srfi srfi-34)
  37. #:use-module (srfi srfi-64)
  38. #:use-module (rnrs io ports)
  39. #:use-module (ice-9 match)
  40. #:use-module (ice-9 regex)
  41. #:use-module (ice-9 popen)
  42. #:use-module (ice-9 ftw))
  43. ;; Test the (guix gexp) module.
  44. (define %store
  45. (open-connection-for-tests))
  46. ;; Globally disable grafts because they can trigger early builds.
  47. (%graft? #f)
  48. ;; For white-box testing.
  49. (define (gexp-inputs x)
  50. ((@@ (guix gexp) gexp-inputs) x))
  51. (define (gexp-outputs x)
  52. ((@@ (guix gexp) gexp-outputs) x))
  53. (define (gexp->sexp . x)
  54. (apply (@@ (guix gexp) gexp->sexp) x))
  55. (define* (gexp->sexp* exp #:optional target)
  56. (run-with-store %store (gexp->sexp exp (%current-system) target)
  57. #:guile-for-build (%guile-for-build)))
  58. (define (gexp-input->tuple input)
  59. (list (gexp-input-thing input) (gexp-input-output input)
  60. (gexp-input-native? input)))
  61. (define %extension-package
  62. ;; Example of a package to use when testing 'with-extensions'.
  63. (dummy-package "extension"
  64. (build-system trivial-build-system)
  65. (arguments
  66. `(#:guile ,%bootstrap-guile
  67. #:modules ((guix build utils))
  68. #:builder
  69. (begin
  70. (use-modules (guix build utils))
  71. (let* ((out (string-append (assoc-ref %outputs "out")
  72. "/share/guile/site/"
  73. (effective-version))))
  74. (mkdir-p out)
  75. (call-with-output-file (string-append out "/hg2g.scm")
  76. (lambda (port)
  77. (define defmod 'define-module) ;fool Geiser
  78. (write `(,defmod (hg2g)
  79. #:export (the-answer))
  80. port)
  81. (write '(define the-answer 42) port)))))))))
  82. (test-begin "gexp")
  83. (test-equal "no references"
  84. '(display "hello gexp->approximate-sexp!")
  85. (gexp->approximate-sexp #~(display "hello gexp->approximate-sexp!")))
  86. (test-equal "unquoted gexp"
  87. '(display "hello")
  88. (let ((inside #~"hello"))
  89. (gexp->approximate-sexp #~(display #$inside))))
  90. (test-equal "unquoted gexp (native)"
  91. '(display "hello")
  92. (let ((inside #~"hello"))
  93. (gexp->approximate-sexp #~(display #+inside))))
  94. (test-equal "spliced gexp"
  95. '(display '(fresh vegetables))
  96. (let ((inside #~(fresh vegetables)))
  97. (gexp->approximate-sexp #~(display '(#$@inside)))))
  98. (test-equal "unspliced gexp, approximated"
  99. ;; (*approximate*) is really an implementation detail
  100. '(display '(*approximate*))
  101. (let ((inside (file-append coreutils "/bin/hello")))
  102. (gexp->approximate-sexp #~(display '(#$@inside)))))
  103. (test-equal "unquoted gexp, approximated"
  104. '(display '(*approximate*))
  105. (let ((inside (file-append coreutils "/bin/hello")))
  106. (gexp->approximate-sexp #~(display '#$inside))))
  107. (test-equal "no refs"
  108. '(display "hello!")
  109. (let ((exp (gexp (display "hello!"))))
  110. (and (gexp? exp)
  111. (null? (gexp-inputs exp))
  112. (gexp->sexp* exp))))
  113. (test-equal "sexp->gexp"
  114. '(a b (c d) e)
  115. (let ((exp (sexp->gexp '(a b (c d) e))))
  116. (and (gexp? exp)
  117. (null? (gexp-inputs exp))
  118. (gexp->sexp* exp))))
  119. (test-equal "unquote"
  120. '(display `(foo ,(+ 2 3)))
  121. (let ((exp (gexp (display `(foo ,(+ 2 3))))))
  122. (and (gexp? exp)
  123. (null? (gexp-inputs exp))
  124. (gexp->sexp* exp))))
  125. (test-assert "one input package"
  126. (let ((exp (gexp (display (ungexp coreutils)))))
  127. (and (gexp? exp)
  128. (match (gexp-inputs exp)
  129. ((input)
  130. (eq? (gexp-input-thing input) coreutils)))
  131. (equal? `(display ,(derivation->output-path
  132. (package-derivation %store coreutils)))
  133. (gexp->sexp* exp)))))
  134. (test-assert "one input package, dotted list"
  135. (let ((exp (gexp (coreutils . (ungexp coreutils)))))
  136. (and (gexp? exp)
  137. (match (gexp-inputs exp)
  138. ((input)
  139. (eq? (gexp-input-thing input) coreutils)))
  140. (equal? `(coreutils . ,(derivation->output-path
  141. (package-derivation %store coreutils)))
  142. (gexp->sexp* exp)))))
  143. (test-assert "one input origin"
  144. (let ((exp (gexp (display (ungexp (package-source coreutils))))))
  145. (and (gexp? exp)
  146. (match (gexp-inputs exp)
  147. ((input)
  148. (and (eq? (gexp-input-thing input) (package-source coreutils))
  149. (string=? (gexp-input-output input) "out"))))
  150. (equal? `(display ,(derivation->output-path
  151. (package-source-derivation
  152. %store (package-source coreutils))))
  153. (gexp->sexp* exp)))))
  154. (test-assert "one local file"
  155. (let* ((file (search-path %load-path "guix.scm"))
  156. (local (local-file file))
  157. (exp (gexp (display (ungexp local))))
  158. (intd (add-to-store %store (basename file) #f
  159. "sha256" file)))
  160. (and (gexp? exp)
  161. (match (gexp-inputs exp)
  162. ((input)
  163. (and (eq? (gexp-input-thing input) local)
  164. (string=? (gexp-input-output input) "out"))))
  165. (equal? `(display ,intd) (gexp->sexp* exp)))))
  166. (test-assert "one local file, symlink"
  167. (let ((file (search-path %load-path "guix.scm"))
  168. (link (tmpnam)))
  169. (dynamic-wind
  170. (const #t)
  171. (lambda ()
  172. (symlink (canonicalize-path file) link)
  173. (let* ((local (local-file link "my-file" #:recursive? #f))
  174. (exp (gexp (display (ungexp local))))
  175. (intd (add-to-store %store "my-file" #f
  176. "sha256" file)))
  177. (and (gexp? exp)
  178. (match (gexp-inputs exp)
  179. ((input)
  180. (and (eq? (gexp-input-thing input) local)
  181. (string=? (gexp-input-output input) "out"))))
  182. (equal? `(display ,intd) (gexp->sexp* exp)))))
  183. (lambda ()
  184. (false-if-exception (delete-file link))))))
  185. (test-equal "local-file, relative file name"
  186. (canonicalize-path (search-path %load-path "guix/base32.scm"))
  187. (let ((directory (dirname (search-path %load-path
  188. "guix/build-system/gnu.scm"))))
  189. (with-directory-excursion directory
  190. (let ((file (local-file "../guix/base32.scm")))
  191. (local-file-absolute-file-name file)))))
  192. (test-equal "local-file, non-literal relative file name"
  193. (canonicalize-path (search-path %load-path "guix/base32.scm"))
  194. (let ((directory (dirname (search-path %load-path
  195. "guix/build-system/gnu.scm"))))
  196. (with-directory-excursion directory
  197. (let ((file (local-file (string-copy "../base32.scm"))))
  198. (local-file-absolute-file-name file)))))
  199. (test-assert "local-file, relative file name, within gexp"
  200. (let* ((file (search-path %load-path "guix/base32.scm"))
  201. (interned (add-to-store %store "base32.scm" #f "sha256" file)))
  202. (equal? `(the file is ,interned)
  203. (gexp->sexp*
  204. #~(the file is #$(local-file "../guix/base32.scm"))))))
  205. (test-assert "local-file, relative file name, within gexp, compiled"
  206. ;; In Guile 3.0.8, everything read by the #~ and #$ read hash extensions
  207. ;; would lack source location info, which in turn would lead
  208. ;; (current-source-directory), called by 'local-file', to return #f, thereby
  209. ;; breaking 'local-file' resolution. See
  210. ;; <https://issues.guix.gnu.org/54003>.
  211. (let ((file (tmpnam)))
  212. (call-with-output-file file
  213. (lambda (port)
  214. (display (string-append "#~(this file is #$(local-file \""
  215. (basename file) "\" \"t.scm\"))")
  216. port)))
  217. (let* ((interned (add-to-store %store "t.scm" #f "sha256" file))
  218. (module (make-fresh-user-module)))
  219. (module-use! module (resolve-interface '(guix gexp)))
  220. (equal? `(this file is ,interned)
  221. (gexp->sexp* (load* file module))))))
  222. (test-assertm "local-file, #:select?"
  223. (mlet* %store-monad ((select? -> (lambda (file stat)
  224. (member (basename file)
  225. '("guix.scm" "tests"
  226. "gexp.scm"))))
  227. (file -> (local-file ".." "directory"
  228. #:recursive? #t
  229. #:select? select?))
  230. (dir (lower-object file)))
  231. (return (and (store-path? dir)
  232. (equal? (scandir dir)
  233. '("." ".." "guix.scm" "tests"))
  234. (equal? (scandir (string-append dir "/tests"))
  235. '("." ".." "gexp.scm"))))))
  236. (test-assert "one plain file"
  237. (let* ((file (plain-file "hi" "Hello, world!"))
  238. (exp (gexp (display (ungexp file))))
  239. (expected (add-text-to-store %store "hi" "Hello, world!")))
  240. (and (gexp? exp)
  241. (match (gexp-inputs exp)
  242. ((input)
  243. (and (eq? (gexp-input-thing input) file)
  244. (string=? (gexp-input-output input) "out"))))
  245. (equal? `(display ,expected) (gexp->sexp* exp)))))
  246. (test-assert "same input twice"
  247. (let ((exp (gexp (begin
  248. (display (ungexp coreutils))
  249. (display (ungexp coreutils))))))
  250. (and (gexp? exp)
  251. (match (gexp-inputs exp)
  252. ((input)
  253. (and (eq? (gexp-input-thing input) coreutils)
  254. (string=? (gexp-input-output input) "out"))))
  255. (let ((e `(display ,(derivation->output-path
  256. (package-derivation %store coreutils)))))
  257. (equal? `(begin ,e ,e) (gexp->sexp* exp))))))
  258. (test-assert "two input packages, one derivation, one file"
  259. (let* ((drv (build-expression->derivation
  260. %store "foo" 'bar
  261. #:guile-for-build (package-derivation %store %bootstrap-guile)))
  262. (txt (add-text-to-store %store "foo" "Hello, world!"))
  263. (exp (gexp (begin
  264. (display (ungexp coreutils))
  265. (display (ungexp %bootstrap-guile))
  266. (display (ungexp drv))
  267. (display (ungexp txt))))))
  268. (define (match-input thing)
  269. (lambda (input)
  270. (eq? (gexp-input-thing input) thing)))
  271. (and (gexp? exp)
  272. (= 4 (length (gexp-inputs exp)))
  273. (every (lambda (input)
  274. (find (match-input input) (gexp-inputs exp)))
  275. (list drv coreutils %bootstrap-guile txt))
  276. (let ((e0 `(display ,(derivation->output-path
  277. (package-derivation %store coreutils))))
  278. (e1 `(display ,(derivation->output-path
  279. (package-derivation %store %bootstrap-guile))))
  280. (e2 `(display ,(derivation->output-path drv)))
  281. (e3 `(display ,txt)))
  282. (equal? `(begin ,e0 ,e1 ,e2 ,e3) (gexp->sexp* exp))))))
  283. (test-assert "file-append"
  284. (let* ((drv (package-derivation %store %bootstrap-guile))
  285. (fa (file-append %bootstrap-guile "/bin/guile"))
  286. (exp #~(here we go #$fa)))
  287. (and (match (gexp->sexp* exp)
  288. (('here 'we 'go (? string? result))
  289. (string=? result
  290. (string-append (derivation->output-path drv)
  291. "/bin/guile"))))
  292. (match (gexp-inputs exp)
  293. ((input)
  294. (and (eq? (gexp-input-thing input) fa)
  295. (string=? (gexp-input-output input) "out")))))))
  296. (test-assert "file-append, output"
  297. (let* ((drv (package-derivation %store glibc))
  298. (fa (file-append glibc "/lib" "/debug"))
  299. (exp #~(foo #$fa:debug)))
  300. (and (match (gexp->sexp* exp)
  301. (('foo (? string? result))
  302. (string=? result
  303. (string-append (derivation->output-path drv "debug")
  304. "/lib/debug"))))
  305. (match (gexp-inputs exp)
  306. ((input)
  307. (and (eq? (gexp-input-thing input) fa)
  308. (string=? (gexp-input-output input) "debug")))))))
  309. (test-assert "file-append, nested"
  310. (let* ((drv (package-derivation %store glibc))
  311. (dir (file-append glibc "/bin"))
  312. (slash (file-append dir "/"))
  313. (file (file-append slash "getent"))
  314. (exp #~(foo #$file)))
  315. (and (match (gexp->sexp* exp)
  316. (('foo (? string? result))
  317. (string=? result
  318. (string-append (derivation->output-path drv)
  319. "/bin/getent"))))
  320. (match (gexp-inputs exp)
  321. ((input)
  322. (eq? (gexp-input-thing input) file))))))
  323. (test-assert "file-append, raw store item"
  324. (let* ((obj (plain-file "example.txt" "Hello!"))
  325. (a (file-append obj "/a"))
  326. (b (file-append a "/b"))
  327. (c (file-append b "/c"))
  328. (exp #~(list #$c))
  329. (item (run-with-store %store (lower-object obj)))
  330. (lexp (run-with-store %store (lower-gexp exp))))
  331. (and (equal? (lowered-gexp-sexp lexp)
  332. `(list ,(string-append item "/a/b/c")))
  333. (equal? (lowered-gexp-sources lexp)
  334. (list item))
  335. (null? (lowered-gexp-inputs lexp)))))
  336. (test-assertm "with-parameters for %current-system"
  337. (mlet* %store-monad ((system -> (match (%current-system)
  338. ("aarch64-linux" "x86_64-linux")
  339. (_ "aarch64-linux")))
  340. (drv (package->derivation coreutils system))
  341. (obj -> (with-parameters ((%current-system system))
  342. coreutils))
  343. (result (lower-object obj)))
  344. (return (string=? (derivation-file-name drv)
  345. (derivation-file-name result)))))
  346. (test-assertm "with-parameters for %current-target-system"
  347. (mlet* %store-monad ((target -> "riscv64-linux-gnu")
  348. (drv (package->cross-derivation coreutils target))
  349. (obj -> (with-parameters
  350. ((%current-target-system target))
  351. coreutils))
  352. (result (lower-object obj)))
  353. (return (string=? (derivation-file-name drv)
  354. (derivation-file-name result)))))
  355. (test-assert "with-parameters + file-append"
  356. (let* ((system (match (%current-system)
  357. ("aarch64-linux" "x86_64-linux")
  358. (_ "aarch64-linux")))
  359. (drv (package-derivation %store coreutils system))
  360. (param (make-parameter 7))
  361. (exp #~(here we go #$(with-parameters ((%current-system system)
  362. (param 42))
  363. (if (= (param) 42)
  364. (file-append coreutils "/bin/touch")
  365. %bootstrap-guile)))))
  366. (match (gexp->sexp* exp)
  367. (('here 'we 'go (? string? result))
  368. (string=? result
  369. (string-append (derivation->output-path drv)
  370. "/bin/touch"))))))
  371. (test-equal "let-system"
  372. (list `(begin ,(%current-system) #t) '(system-binding)
  373. 'low '() '())
  374. (let* ((exp #~(begin
  375. #$(let-system system system)
  376. #t))
  377. (low (run-with-store %store (lower-gexp exp))))
  378. (list (lowered-gexp-sexp low)
  379. (match (gexp-inputs exp)
  380. ((input)
  381. (and (eq? (struct-vtable (gexp-input-thing input))
  382. (@@ (guix gexp) <system-binding>))
  383. (string=? (gexp-input-output input) "out")
  384. '(system-binding)))
  385. (x x))
  386. 'low
  387. (lowered-gexp-inputs low)
  388. (lowered-gexp-sources low))))
  389. (test-equal "let-system, target"
  390. (list `(list ,(%current-system) #f)
  391. `(list ,(%current-system) "aarch64-linux-gnu"))
  392. (let ((exp #~(list #$@(let-system (system target)
  393. (list system target)))))
  394. (list (gexp->sexp* exp)
  395. (gexp->sexp* exp "aarch64-linux-gnu"))))
  396. (test-equal "let-system, ungexp-native, target"
  397. `(here it is: ,(%current-system) #f)
  398. (let ((exp #~(here it is: #+@(let-system (system target)
  399. (list system target)))))
  400. (gexp->sexp* exp "aarch64-linux-gnu")))
  401. (test-equal "let-system, nested"
  402. (list `(system* ,(string-append "qemu-system-" (%current-system))
  403. "-m" "256")
  404. '(system-binding))
  405. (let ((exp #~(system*
  406. #+(let-system (system target)
  407. (file-append (@@ (gnu packages virtualization)
  408. qemu)
  409. "/bin/qemu-system-"
  410. system))
  411. "-m" "256")))
  412. (list (match (gexp->sexp* exp)
  413. (('system* command rest ...)
  414. `(system* ,(and (string-prefix? (%store-prefix) command)
  415. (basename command))
  416. ,@rest))
  417. (x x))
  418. (match (gexp-inputs exp)
  419. ((input)
  420. (and (eq? (struct-vtable (gexp-input-thing input))
  421. (@@ (guix gexp) <system-binding>))
  422. (string=? (gexp-input-output input) "out")
  423. (gexp-input-native? input)
  424. '(system-binding)))
  425. (x x)))))
  426. (test-assert "let-system in file-append"
  427. (let ((mixed (file-append (let-system (system target)
  428. (if (not target) grep sed))
  429. "/bin"))
  430. (grep (file-append grep "/bin"))
  431. (sed (file-append sed "/bin")))
  432. (and (equal? (gexp->sexp* #~(list #$mixed))
  433. (gexp->sexp* #~(list #$grep)))
  434. (equal? (gexp->sexp* #~(list #$mixed) "powerpc64le-linux-gnu")
  435. (gexp->sexp* #~(list #$sed) "powerpc64le-linux-gnu")))))
  436. (test-assert "ungexp + ungexp-native"
  437. (let* ((exp (gexp (list (ungexp-native %bootstrap-guile)
  438. (ungexp coreutils)
  439. (ungexp-native glibc)
  440. (ungexp binutils))))
  441. (target "mips64el-linux")
  442. (guile (derivation->output-path
  443. (package-derivation %store %bootstrap-guile)))
  444. (cu (derivation->output-path
  445. (package-cross-derivation %store coreutils target)))
  446. (libc (derivation->output-path
  447. (package-derivation %store glibc)))
  448. (bu (derivation->output-path
  449. (package-cross-derivation %store binutils target))))
  450. (and (lset= equal?
  451. `((,%bootstrap-guile "out" #t)
  452. (,coreutils "out" #f)
  453. (,glibc "out" #t)
  454. (,binutils "out" #f))
  455. (map gexp-input->tuple (gexp-inputs exp)))
  456. (equal? `(list ,guile ,cu ,libc ,bu)
  457. (gexp->sexp* exp target)))))
  458. (test-equal "ungexp + ungexp-native, nested"
  459. `((,%bootstrap-guile "out" #f) (,coreutils "out" #t))
  460. (let* ((exp (gexp (list (ungexp-native (gexp (ungexp coreutils)))
  461. (ungexp %bootstrap-guile)))))
  462. (map gexp-input->tuple (gexp-inputs exp))))
  463. (test-equal "ungexp + ungexp-native, nested, special mixture"
  464. `((,coreutils "out" #t))
  465. (let* ((foo (gexp (foo (ungexp-native coreutils))))
  466. (exp (gexp (bar (ungexp foo)))))
  467. (map gexp-input->tuple (gexp-inputs exp))))
  468. (test-assert "input list"
  469. (let ((exp (gexp (display
  470. '(ungexp (list %bootstrap-guile coreutils)))))
  471. (guile (derivation->output-path
  472. (package-derivation %store %bootstrap-guile)))
  473. (cu (derivation->output-path
  474. (package-derivation %store coreutils))))
  475. (and (lset= equal?
  476. `((,%bootstrap-guile "out" #f) (,coreutils "out" #f))
  477. (map gexp-input->tuple (gexp-inputs exp)))
  478. (equal? `(display '(,guile ,cu))
  479. (gexp->sexp* exp)))))
  480. (test-assert "input list + ungexp-native"
  481. (let* ((target "mips64el-linux")
  482. (exp (gexp (display
  483. (cons '(ungexp-native (list %bootstrap-guile coreutils))
  484. '(ungexp (list glibc binutils))))))
  485. (guile (derivation->output-path
  486. (package-derivation %store %bootstrap-guile)))
  487. (cu (derivation->output-path
  488. (package-derivation %store coreutils)))
  489. (xlibc (derivation->output-path
  490. (package-cross-derivation %store glibc target)))
  491. (xbu (derivation->output-path
  492. (package-cross-derivation %store binutils target))))
  493. (and (lset= equal?
  494. `((,%bootstrap-guile "out" #t) (,coreutils "out" #t)
  495. (,glibc "out" #f) (,binutils "out" #f))
  496. (map gexp-input->tuple (gexp-inputs exp)))
  497. (equal? `(display (cons '(,guile ,cu) '(,xlibc ,xbu)))
  498. (gexp->sexp* exp target)))))
  499. (test-assert "input list splicing"
  500. (let* ((inputs (list (gexp-input glibc "debug") %bootstrap-guile))
  501. (outputs (list (derivation->output-path
  502. (package-derivation %store glibc)
  503. "debug")
  504. (derivation->output-path
  505. (package-derivation %store %bootstrap-guile))))
  506. (exp (gexp (list (ungexp-splicing (cons (+ 2 3) inputs))))))
  507. (and (lset= equal?
  508. `((,glibc "debug" #f) (,%bootstrap-guile "out" #f))
  509. (map gexp-input->tuple (gexp-inputs exp)))
  510. (equal? (gexp->sexp* exp)
  511. `(list ,@(cons 5 outputs))))))
  512. (test-assert "input list splicing + ungexp-native-splicing"
  513. (let* ((inputs (list (gexp-input glibc "debug" #:native? #t)
  514. %bootstrap-guile))
  515. (exp (gexp (list (ungexp-native-splicing (cons (+ 2 3) inputs))))))
  516. (and (lset= equal?
  517. `((,glibc "debug" #t) (,%bootstrap-guile "out" #t))
  518. (map gexp-input->tuple (gexp-inputs exp)))
  519. (equal? (gexp->sexp* exp) ;native
  520. (gexp->sexp* exp "mips64el-linux")))))
  521. (test-assert "gexp list splicing + ungexp-splicing"
  522. (let* ((inner (gexp (ungexp-native glibc)))
  523. (exp (gexp (list (ungexp-splicing (list inner))))))
  524. (and (equal? `((,glibc "out" #t))
  525. (map gexp-input->tuple (gexp-inputs exp)))
  526. (equal? (gexp->sexp* exp) ;native
  527. (gexp->sexp* exp "mips64el-linux")))))
  528. (test-equal "output list"
  529. 2
  530. (let ((exp (gexp (begin (mkdir (ungexp output))
  531. (mkdir (ungexp output "bar"))))))
  532. (length (gexp-outputs exp)))) ;XXX: <output-ref> is private
  533. (test-assert "output list, combined gexps"
  534. (let* ((exp0 (gexp (mkdir (ungexp output))))
  535. (exp1 (gexp (mkdir (ungexp output "foo"))))
  536. (exp2 (gexp (begin (display "hi!") (ungexp exp0) (ungexp exp1)))))
  537. (and (lset= equal?
  538. (append (gexp-outputs exp0) (gexp-outputs exp1))
  539. (gexp-outputs exp2))
  540. (= 2 (length (gexp-outputs exp2))))))
  541. (test-equal "output list, combined gexps, duplicate output"
  542. 1
  543. (let* ((exp0 (gexp (mkdir (ungexp output))))
  544. (exp1 (gexp (begin (mkdir (ungexp output)) (ungexp exp0))))
  545. (exp2 (gexp (begin (mkdir (ungexp output)) (ungexp exp1)))))
  546. (length (gexp-outputs exp2))))
  547. (test-assert "output list + ungexp-splicing list, combined gexps"
  548. (let* ((exp0 (gexp (mkdir (ungexp output))))
  549. (exp1 (gexp (mkdir (ungexp output "foo"))))
  550. (exp2 (gexp (begin (display "hi!")
  551. (ungexp-splicing (list exp0 exp1))))))
  552. (and (lset= equal?
  553. (append (gexp-outputs exp0) (gexp-outputs exp1))
  554. (gexp-outputs exp2))
  555. (= 2 (length (gexp-outputs exp2))))))
  556. (test-assertm "gexp->file"
  557. (mlet* %store-monad ((exp -> (gexp (display (ungexp %bootstrap-guile))))
  558. (guile (package-file %bootstrap-guile))
  559. (sexp (gexp->sexp exp (%current-system) #f))
  560. (drv (gexp->file "foo" exp))
  561. (out -> (derivation->output-path drv))
  562. (done (built-derivations (list drv)))
  563. (refs (references* out)))
  564. (return (and (equal? sexp (call-with-input-file out read))
  565. (equal? (list guile) refs)))))
  566. (test-assertm "gexp->file + file-append"
  567. (mlet* %store-monad ((exp -> #~#$(file-append %bootstrap-guile
  568. "/bin/guile"))
  569. (guile (package-file %bootstrap-guile))
  570. (drv (gexp->file "foo" exp))
  571. (out -> (derivation->output-path drv))
  572. (done (built-derivations (list drv)))
  573. (refs (references* out)))
  574. (return (and (equal? (string-append guile "/bin/guile")
  575. (call-with-input-file out read))
  576. (equal? (list guile) refs)))))
  577. (test-assertm "gexp->file + #:splice?"
  578. (mlet* %store-monad ((exp -> (list
  579. #~(define foo 'bar)
  580. #~(define guile #$%bootstrap-guile)))
  581. (guile (package-file %bootstrap-guile))
  582. (drv (gexp->file "splice" exp #:splice? #t))
  583. (out -> (derivation->output-path drv))
  584. (done (built-derivations (list drv)))
  585. (refs (references* out)))
  586. (pk 'splice out)
  587. (return (and (equal? `((define foo 'bar)
  588. (define guile ,guile)
  589. ,(call-with-input-string "" read))
  590. (call-with-input-file out
  591. (lambda (port)
  592. (list (read port) (read port) (read port)))))
  593. (equal? (list guile) refs)))))
  594. (test-assertm "gexp->derivation"
  595. (mlet* %store-monad ((file (text-file "foo" "Hello, world!"))
  596. (exp -> (gexp
  597. (begin
  598. (mkdir (ungexp output))
  599. (chdir (ungexp output))
  600. (symlink
  601. (string-append (ungexp %bootstrap-guile)
  602. "/bin/guile")
  603. "foo")
  604. (symlink (ungexp file)
  605. (ungexp output "2nd")))))
  606. (drv (gexp->derivation "foo" exp))
  607. (out -> (derivation->output-path drv))
  608. (out2 -> (derivation->output-path drv "2nd"))
  609. (done (built-derivations (list drv)))
  610. (refs (references* out))
  611. (refs2 (references* out2))
  612. (guile (package-file %bootstrap-guile "bin/guile")))
  613. (return (and (string=? (readlink (string-append out "/foo")) guile)
  614. (string=? (readlink out2) file)
  615. (equal? refs (list (dirname (dirname guile))))
  616. (equal? refs2 (list file))
  617. (null? (derivation-properties drv))))))
  618. (test-assertm "gexp->derivation properties"
  619. (mlet %store-monad ((drv (gexp->derivation "foo"
  620. #~(mkdir #$output)
  621. #:properties '((type . test)))))
  622. (return (equal? '((type . test))
  623. (derivation-properties drv)))))
  624. (test-assertm "gexp->derivation vs. grafts"
  625. (mlet* %store-monad ((graft? (set-grafting #f))
  626. (p0 -> (dummy-package "dummy"
  627. (arguments
  628. '(#:implicit-inputs? #f))))
  629. (r -> (package (inherit p0) (name "DuMMY")))
  630. (p1 -> (package (inherit p0) (replacement r)))
  631. (exp0 -> (gexp (frob (ungexp p0) (ungexp output))))
  632. (exp1 -> (gexp (frob (ungexp p1) (ungexp output))))
  633. (void (set-guile-for-build %bootstrap-guile))
  634. (drv0 (gexp->derivation "t" exp0 #:graft? #t))
  635. (drv1 (gexp->derivation "t" exp1 #:graft? #t))
  636. (drv1* (gexp->derivation "t" exp1 #:graft? #f))
  637. (_ (set-grafting graft?)))
  638. (return (and (not (string=? (derivation->output-path drv0)
  639. (derivation->output-path drv1)))
  640. (string=? (derivation->output-path drv0)
  641. (derivation->output-path drv1*))))))
  642. (test-assertm "gexp->derivation, composed gexps"
  643. (mlet* %store-monad ((exp0 -> (gexp (begin
  644. (mkdir (ungexp output))
  645. (chdir (ungexp output)))))
  646. (exp1 -> (gexp (symlink
  647. (string-append (ungexp %bootstrap-guile)
  648. "/bin/guile")
  649. "foo")))
  650. (exp -> (gexp (begin (ungexp exp0) (ungexp exp1))))
  651. (drv (gexp->derivation "foo" exp))
  652. (out -> (derivation->output-path drv))
  653. (done (built-derivations (list drv)))
  654. (guile (package-file %bootstrap-guile "bin/guile")))
  655. (return (string=? (readlink (string-append out "/foo"))
  656. guile))))
  657. (test-assertm "gexp->derivation, default system"
  658. ;; The default system should be the one at '>>=' time, not the one at
  659. ;; invocation time. See <http://bugs.gnu.org/18002>.
  660. (let ((system (%current-system))
  661. (mdrv (parameterize ((%current-system "foobar64-linux"))
  662. (gexp->derivation "foo"
  663. (gexp
  664. (mkdir (ungexp output)))))))
  665. (mlet %store-monad ((drv mdrv))
  666. (return (string=? system (derivation-system drv))))))
  667. (test-assertm "gexp->derivation, local-file"
  668. (mlet* %store-monad ((file -> (search-path %load-path "guix.scm"))
  669. (intd (interned-file file #:recursive? #f))
  670. (local -> (local-file file))
  671. (exp -> (gexp (begin
  672. (stat (ungexp local))
  673. (symlink (ungexp local)
  674. (ungexp output)))))
  675. (drv (gexp->derivation "local-file" exp)))
  676. (mbegin %store-monad
  677. (built-derivations (list drv))
  678. (return (string=? (readlink (derivation->output-path drv))
  679. intd)))))
  680. (test-assertm "gexp->derivation, cross-compilation"
  681. (mlet* %store-monad ((target -> "mips64el-linux")
  682. (exp -> (gexp (list (ungexp coreutils)
  683. (ungexp output))))
  684. (xdrv (gexp->derivation "foo" exp
  685. #:target target))
  686. (refs (references*
  687. (derivation-file-name xdrv)))
  688. (xcu (package->cross-derivation coreutils
  689. target))
  690. (cu (package->derivation coreutils)))
  691. (return (and (member (derivation-file-name xcu) refs)
  692. (not (member (derivation-file-name cu) refs))))))
  693. (test-assertm "gexp->derivation, ungexp-native"
  694. (mlet* %store-monad ((target -> "mips64el-linux")
  695. (exp -> (gexp (list (ungexp-native coreutils)
  696. (ungexp output))))
  697. (xdrv (gexp->derivation "foo" exp
  698. #:target target))
  699. (drv (gexp->derivation "foo" exp)))
  700. (return (string=? (derivation-file-name drv)
  701. (derivation-file-name xdrv)))))
  702. (test-assertm "gexp->derivation, ungexp + ungexp-native"
  703. (mlet* %store-monad ((target -> "mips64el-linux")
  704. (exp -> (gexp (list (ungexp-native coreutils)
  705. (ungexp glibc)
  706. (ungexp output))))
  707. (xdrv (gexp->derivation "foo" exp
  708. #:target target))
  709. (refs (references*
  710. (derivation-file-name xdrv)))
  711. (xglibc (package->cross-derivation glibc target))
  712. (cu (package->derivation coreutils)))
  713. (return (and (member (derivation-file-name cu) refs)
  714. (member (derivation-file-name xglibc) refs)))))
  715. (test-assertm "gexp->derivation, ungexp-native + composed gexps"
  716. (mlet* %store-monad ((target -> "mips64el-linux")
  717. (exp0 -> (gexp (list 1 2
  718. (ungexp coreutils))))
  719. (exp -> (gexp (list 0 (ungexp-native exp0))))
  720. (xdrv (gexp->derivation "foo" exp
  721. #:target target))
  722. (drv (gexp->derivation "foo" exp)))
  723. (return (string=? (derivation-file-name drv)
  724. (derivation-file-name xdrv)))))
  725. (test-assertm "gexp->derivation, store copy"
  726. (let ((build-one #~(call-with-output-file #$output
  727. (lambda (port)
  728. (display "This is the one." port))))
  729. (build-two (lambda (one)
  730. #~(begin
  731. (mkdir #$output)
  732. (symlink #$one (string-append #$output "/one"))
  733. (call-with-output-file (string-append #$output "/two")
  734. (lambda (port)
  735. (display "This is the second one." port))))))
  736. (build-drv #~(begin
  737. (use-modules (guix build store-copy)
  738. (guix build utils)
  739. (srfi srfi-1))
  740. (define (canonical-file? file)
  741. ;; Copied from (guix tests).
  742. (let ((st (lstat file)))
  743. (or (not (string-prefix? (%store-directory) file))
  744. (eq? 'symlink (stat:type st))
  745. (and (= 1 (stat:mtime st))
  746. (zero? (logand #o222 (stat:mode st)))))))
  747. (mkdir #$output)
  748. (populate-store '("graph") #$output
  749. #:deduplicate? #f)
  750. ;; Check whether 'populate-store' canonicalizes
  751. ;; permissions and timestamps.
  752. (unless (every canonical-file? (find-files #$output))
  753. (error "not canonical!" #$output)))))
  754. (mlet* %store-monad ((one (gexp->derivation "one" build-one))
  755. (two (gexp->derivation "two" (build-two one)))
  756. (drv (gexp->derivation "store-copy" build-drv
  757. #:references-graphs
  758. `(("graph" ,two))
  759. #:modules
  760. '((guix build store-copy)
  761. (guix progress)
  762. (guix records)
  763. (guix sets)
  764. (guix build utils))))
  765. (ok? (built-derivations (list drv)))
  766. (out -> (derivation->output-path drv)))
  767. (let ((one (derivation->output-path one))
  768. (two (derivation->output-path two)))
  769. (return (and ok?
  770. (file-exists? (string-append out "/" one))
  771. (file-exists? (string-append out "/" two))
  772. (file-exists? (string-append out "/" two "/two"))
  773. (string=? (readlink (string-append out "/" two "/one"))
  774. one)))))))
  775. (test-assertm "imported-files"
  776. (mlet* %store-monad
  777. ((files -> `(("x" . ,(search-path %load-path "ice-9/q.scm"))
  778. ("a/b/c" . ,(search-path %load-path
  779. "guix/derivations.scm"))
  780. ("p/q" . ,(search-path %load-path "guix.scm"))
  781. ("p/z" . ,(search-path %load-path "guix/store.scm"))))
  782. (dir (imported-files files)))
  783. (mbegin %store-monad
  784. (return
  785. (every (match-lambda
  786. ((path . source)
  787. (equal? (call-with-input-file (string-append dir "/" path)
  788. get-bytevector-all)
  789. (call-with-input-file source
  790. get-bytevector-all))))
  791. files)))))
  792. (test-assertm "imported-files with file-like objects"
  793. (mlet* %store-monad ((plain -> (plain-file "foo" "bar!"))
  794. (q-scm -> (search-path %load-path "ice-9/q.scm"))
  795. (files -> `(("a/b/c" . ,q-scm)
  796. ("p/q" . ,plain)))
  797. (drv (imported-files files)))
  798. (mbegin %store-monad
  799. (built-derivations (list (pk 'drv drv)))
  800. (mlet %store-monad ((dir -> (derivation->output-path drv))
  801. (plain* (text-file "foo" "bar!"))
  802. (q-scm* (interned-file q-scm "c")))
  803. (return
  804. (and (file=? (string-append dir "/a/b/c") q-scm* stat)
  805. (file=? (string-append dir "/p/q") plain* stat)))))))
  806. (test-equal "gexp-modules & ungexp"
  807. '((bar) (foo))
  808. ((@@ (guix gexp) gexp-modules)
  809. #~(foo #$(with-imported-modules '((foo)) #~+)
  810. #+(with-imported-modules '((bar)) #~-))))
  811. (test-equal "gexp-modules & ungexp-splicing"
  812. '((foo) (bar))
  813. ((@@ (guix gexp) gexp-modules)
  814. #~(foo #$@(list (with-imported-modules '((foo)) #~+)
  815. (with-imported-modules '((bar)) #~-)))))
  816. (test-assert "gexp-modules deletes duplicates" ;<https://bugs.gnu.org/32966>
  817. (let ((make-file (lambda ()
  818. ;; Use 'eval' to make sure we get an object that's not
  819. ;; 'eq?' nor 'equal?' due to the closures it embeds.
  820. (eval '(scheme-file "bar.scm" #~(define-module (bar)))
  821. (current-module)))))
  822. (define result
  823. ((@@ (guix gexp) gexp-modules)
  824. (with-imported-modules `(((bar) => ,(make-file))
  825. ((bar) => ,(make-file))
  826. (foo) (foo))
  827. #~+)))
  828. (match result
  829. (((('bar) '=> (? scheme-file?)) ('foo)) #t))))
  830. (test-equal "gexp-modules and literal Scheme object"
  831. '()
  832. (gexp-modules #t))
  833. (test-assert "gexp-modules, warning"
  834. (string-match "tests/gexp.scm:[0-9]+:[0-9]+: warning: \
  835. importing.* \\(guix config\\) from the host"
  836. (call-with-output-string
  837. (lambda (port)
  838. (parameterize ((guix-warning-port port))
  839. (let* ((x (with-imported-modules '((guix config))
  840. #~(+ 1 2 3)))
  841. (y #~(+ 39 #$x)))
  842. (gexp-modules y)))))))
  843. (test-assertm "gexp->derivation #:modules"
  844. (mlet* %store-monad
  845. ((build -> #~(begin
  846. (use-modules (guix build utils))
  847. (mkdir-p (string-append #$output "/guile/guix/nix"))
  848. #t))
  849. (drv (gexp->derivation "test-with-modules" build
  850. #:modules '((guix build utils)))))
  851. (mbegin %store-monad
  852. (built-derivations (list drv))
  853. (let* ((p (derivation->output-path drv))
  854. (s (stat (string-append p "/guile/guix/nix"))))
  855. (return (eq? (stat:type s) 'directory))))))
  856. (test-assertm "gexp->derivation & with-imported-modules"
  857. ;; Same test as above, but using 'with-imported-modules'.
  858. (mlet* %store-monad
  859. ((build -> (with-imported-modules '((guix build utils))
  860. #~(begin
  861. (use-modules (guix build utils))
  862. (mkdir-p (string-append #$output "/guile/guix/nix"))
  863. #t)))
  864. (drv (gexp->derivation "test-with-modules" build)))
  865. (mbegin %store-monad
  866. (built-derivations (list drv))
  867. (let* ((p (derivation->output-path drv))
  868. (s (stat (string-append p "/guile/guix/nix"))))
  869. (return (eq? (stat:type s) 'directory))))))
  870. (test-assertm "gexp->derivation & nested with-imported-modules"
  871. (mlet* %store-monad
  872. ((build1 -> (with-imported-modules '((guix build utils))
  873. #~(begin
  874. (use-modules (guix build utils))
  875. (mkdir-p (string-append #$output "/guile/guix/nix"))
  876. #t)))
  877. (build2 -> (with-imported-modules '((guix build bournish))
  878. #~(begin
  879. (use-modules (guix build bournish)
  880. (system base compile))
  881. #+build1
  882. (call-with-output-file (string-append #$output "/b")
  883. (lambda (port)
  884. (write
  885. (read-and-compile (open-input-string "cd /foo")
  886. #:from %bournish-language
  887. #:to 'scheme)
  888. port))))))
  889. (drv (gexp->derivation "test-with-modules" build2)))
  890. (mbegin %store-monad
  891. (built-derivations (list drv))
  892. (let* ((p (derivation->output-path drv))
  893. (s (stat (string-append p "/guile/guix/nix")))
  894. (b (string-append p "/b")))
  895. (return (and (eq? (stat:type s) 'directory)
  896. (equal? '(chdir "/foo")
  897. (call-with-input-file b read))))))))
  898. (test-assertm "gexp->derivation & with-imported-module & computed module"
  899. (mlet* %store-monad
  900. ((module -> (scheme-file "x" #~(;; splice!
  901. (define-module (foo bar)
  902. #:export (the-answer))
  903. (define the-answer 42))
  904. #:splice? #t))
  905. (build -> (with-imported-modules `(((foo bar) => ,module)
  906. (guix build utils))
  907. #~(begin
  908. (use-modules (guix build utils)
  909. (foo bar))
  910. mkdir-p
  911. (call-with-output-file #$output
  912. (lambda (port)
  913. (write the-answer port))))))
  914. (drv (gexp->derivation "thing" build))
  915. (out -> (derivation->output-path drv)))
  916. (mbegin %store-monad
  917. (built-derivations (list drv))
  918. (return (= 42 (call-with-input-file out read))))))
  919. (test-equal "gexp-extensions & ungexp"
  920. (list sed grep)
  921. ((@@ (guix gexp) gexp-extensions)
  922. #~(foo #$(with-extensions (list grep) #~+)
  923. #+(with-extensions (list sed) #~-))))
  924. (test-equal "gexp-extensions & ungexp-splicing"
  925. (list grep sed)
  926. ((@@ (guix gexp) gexp-extensions)
  927. #~(foo #$@(list (with-extensions (list grep) #~+)
  928. (with-imported-modules '((foo))
  929. (with-extensions (list sed) #~-))))))
  930. (test-equal "gexp-extensions and literal Scheme object"
  931. '()
  932. ((@@ (guix gexp) gexp-extensions) #t))
  933. (test-assertm "gexp->derivation & with-extensions"
  934. ;; Create a fake Guile extension and make sure it is accessible both to the
  935. ;; imported modules and to the derivation build script.
  936. (mlet* %store-monad
  937. ((extension -> %extension-package)
  938. (module -> (scheme-file "x" #~( ;; splice!
  939. (define-module (foo)
  940. #:use-module (hg2g)
  941. #:export (multiply))
  942. (define (multiply x)
  943. (* the-answer x)))
  944. #:splice? #t))
  945. (build -> (with-extensions (list extension)
  946. (with-imported-modules `((guix build utils)
  947. ((foo) => ,module))
  948. #~(begin
  949. (use-modules (guix build utils)
  950. (hg2g) (foo))
  951. (call-with-output-file #$output
  952. (lambda (port)
  953. (write (list the-answer (multiply 2))
  954. port)))))))
  955. (drv (gexp->derivation "thingie" build
  956. ;; %BOOTSTRAP-GUILE is 2.0.
  957. #:effective-version "2.0"))
  958. (out -> (derivation->output-path drv)))
  959. (mbegin %store-monad
  960. (built-derivations (list drv))
  961. (return (equal? '(42 84) (call-with-input-file out read))))))
  962. (test-assertm "lower-gexp"
  963. (mlet* %store-monad
  964. ((extension -> %extension-package)
  965. (extension-drv (package->derivation %extension-package))
  966. (coreutils-drv (package->derivation coreutils))
  967. (exp -> (with-extensions (list extension)
  968. (with-imported-modules `((guix build utils))
  969. #~(begin
  970. (use-modules (guix build utils)
  971. (hg2g))
  972. #$coreutils:debug
  973. mkdir-p
  974. the-answer))))
  975. (lexp (lower-gexp exp
  976. #:effective-version "2.0")))
  977. (define (matching-input drv output)
  978. (lambda (input)
  979. (and (eq? (derivation-input-derivation input) drv)
  980. (equal? (derivation-input-sub-derivations input)
  981. (list output)))))
  982. (mbegin %store-monad
  983. (return (and (find (matching-input extension-drv "out")
  984. (lowered-gexp-inputs (pk 'lexp lexp)))
  985. (find (matching-input coreutils-drv "debug")
  986. (lowered-gexp-inputs lexp))
  987. (member (string-append
  988. (derivation->output-path extension-drv)
  989. "/share/guile/site/2.0")
  990. (lowered-gexp-load-path lexp))
  991. (= 2 (length (lowered-gexp-load-path lexp)))
  992. (member (string-append
  993. (derivation->output-path extension-drv)
  994. "/lib/guile/2.0/site-ccache")
  995. (lowered-gexp-load-compiled-path lexp))
  996. (= 2 (length (lowered-gexp-load-compiled-path lexp)))
  997. (eq? (derivation-input-derivation (lowered-gexp-guile lexp))
  998. (%guile-for-build)))))))
  999. (test-assertm "lower-gexp, raw-derivation-file"
  1000. (mlet* %store-monad ((thing -> (program-file "prog" #~(display "hi!")))
  1001. (exp -> #~(list #$(raw-derivation-file thing)))
  1002. (drv (lower-object thing))
  1003. (lexp (lower-gexp exp #:effective-version "2.0")))
  1004. (return (and (equal? `(list ,(derivation-file-name drv))
  1005. (lowered-gexp-sexp lexp))
  1006. (equal? (list (derivation-file-name drv))
  1007. (lowered-gexp-sources lexp))
  1008. (null? (lowered-gexp-inputs lexp))))))
  1009. (test-eq "lower-gexp, non-self-quoting input"
  1010. +
  1011. (guard (c ((gexp-input-error? c)
  1012. (gexp-error-invalid-input c)))
  1013. (run-with-store %store
  1014. (lower-gexp #~(foo #$+)))))
  1015. (test-equal "lower-gexp, character literal"
  1016. '(#\+)
  1017. (lowered-gexp-sexp
  1018. (run-with-store %store
  1019. (lower-gexp #~(#\+)))))
  1020. (test-assertm "gexp->derivation #:references-graphs"
  1021. (mlet* %store-monad
  1022. ((one (text-file "one" (random-text)))
  1023. (two (gexp->derivation "two"
  1024. #~(symlink #$one #$output:chbouib)))
  1025. (build -> (with-imported-modules '((guix build store-copy)
  1026. (guix progress)
  1027. (guix records)
  1028. (guix sets)
  1029. (guix build utils))
  1030. #~(begin
  1031. (use-modules (guix build store-copy))
  1032. (with-output-to-file #$output
  1033. (lambda ()
  1034. (write (map store-info-item
  1035. (call-with-input-file "guile"
  1036. read-reference-graph)))))
  1037. (with-output-to-file #$output:one
  1038. (lambda ()
  1039. (write (map store-info-item
  1040. (call-with-input-file "one"
  1041. read-reference-graph)))))
  1042. (with-output-to-file #$output:two
  1043. (lambda ()
  1044. (write (map store-info-item
  1045. (call-with-input-file "two"
  1046. read-reference-graph))))))))
  1047. (drv (gexp->derivation "ref-graphs" build
  1048. #:references-graphs `(("one" ,one)
  1049. ("two" ,two "chbouib")
  1050. ("guile" ,%bootstrap-guile))))
  1051. (ok? (built-derivations (list drv)))
  1052. (guile-drv (package->derivation %bootstrap-guile))
  1053. (bash (interned-file (search-bootstrap-binary "bash"
  1054. (%current-system))
  1055. "bash" #:recursive? #t))
  1056. (g-one -> (derivation->output-path drv "one"))
  1057. (g-two -> (derivation->output-path drv "two"))
  1058. (g-guile -> (derivation->output-path drv)))
  1059. (return (and ok?
  1060. (equal? (call-with-input-file g-one read) (list one))
  1061. (lset= string=?
  1062. (call-with-input-file g-two read)
  1063. (list one (derivation->output-path two "chbouib")))
  1064. ;; Note: %BOOTSTRAP-GUILE depends on the bootstrap Bash.
  1065. (lset= string=?
  1066. (call-with-input-file g-guile read)
  1067. (list (derivation->output-path guile-drv) bash))))))
  1068. (test-assertm "gexp->derivation #:references-graphs cross-compilation"
  1069. ;; The objects passed in #:references-graphs implicitly refer to
  1070. ;; cross-compiled derivations. Make sure this is the case.
  1071. (mlet* %store-monad ((drv1 (lower-object coreutils (%current-system)
  1072. #:target "i586-pc-gnu"))
  1073. (drv2 (lower-object coreutils (%current-system)
  1074. #:target #f))
  1075. (drv3 (gexp->derivation "three"
  1076. #~(symlink #$coreutils #$output)
  1077. #:target "i586-pc-gnu"
  1078. #:references-graphs
  1079. `(("coreutils" ,coreutils))))
  1080. (refs (references* (derivation-file-name drv3))))
  1081. (return (and (member (derivation-file-name drv1) refs)
  1082. (not (member (derivation-file-name drv2) refs))))))
  1083. (test-assertm "gexp->derivation #:allowed-references"
  1084. (mlet %store-monad ((drv (gexp->derivation "allowed-refs"
  1085. #~(begin
  1086. (mkdir #$output)
  1087. (chdir #$output)
  1088. (symlink #$output "self")
  1089. (symlink #$%bootstrap-guile
  1090. "guile"))
  1091. #:allowed-references
  1092. (list "out" %bootstrap-guile))))
  1093. (built-derivations (list drv))))
  1094. (test-assertm "gexp->derivation #:allowed-references, specific output"
  1095. (mlet* %store-monad ((in (gexp->derivation "thing"
  1096. #~(begin
  1097. (mkdir #$output:ok)
  1098. (mkdir #$output:not-ok))))
  1099. (drv (gexp->derivation "allowed-refs"
  1100. #~(begin
  1101. (pk #$in:not-ok)
  1102. (mkdir #$output)
  1103. (chdir #$output)
  1104. (symlink #$output "self")
  1105. (symlink #$in:ok "ok"))
  1106. #:allowed-references
  1107. (list "out"
  1108. (gexp-input in "ok")))))
  1109. (built-derivations (list drv))))
  1110. (test-assert "gexp->derivation #:allowed-references, disallowed"
  1111. (let ((drv (run-with-store %store
  1112. (gexp->derivation "allowed-refs"
  1113. #~(begin
  1114. (mkdir #$output)
  1115. (chdir #$output)
  1116. (symlink #$%bootstrap-guile "guile"))
  1117. #:allowed-references '()))))
  1118. (guard (c ((store-protocol-error? c) #t))
  1119. (build-derivations %store (list drv))
  1120. #f)))
  1121. (test-assertm "gexp->derivation #:disallowed-references, allowed"
  1122. (mlet %store-monad ((drv (gexp->derivation "disallowed-refs"
  1123. #~(begin
  1124. (mkdir #$output)
  1125. (chdir #$output)
  1126. (symlink #$output "self")
  1127. (symlink #$%bootstrap-guile
  1128. "guile"))
  1129. #:disallowed-references '())))
  1130. (built-derivations (list drv))))
  1131. (test-assert "gexp->derivation #:disallowed-references"
  1132. (let ((drv (run-with-store %store
  1133. (gexp->derivation "disallowed-refs"
  1134. #~(begin
  1135. (mkdir #$output)
  1136. (chdir #$output)
  1137. (symlink #$%bootstrap-guile "guile"))
  1138. #:disallowed-references (list %bootstrap-guile)))))
  1139. (guard (c ((store-protocol-error? c) #t))
  1140. (build-derivations %store (list drv))
  1141. #f)))
  1142. (define shebang
  1143. (string-append "#!" (derivation->output-path (%guile-for-build))
  1144. "/bin/guile --no-auto-compile"))
  1145. ;; If we're going to hit the silly shebang limit (128 chars on Linux-based
  1146. ;; systems), then skip the following test.
  1147. (test-skip (if (> (string-length shebang) 127) 2 0))
  1148. (test-assertm "gexp->script"
  1149. (mlet* %store-monad ((n -> (random (expt 2 50)))
  1150. (exp -> (gexp
  1151. (system*
  1152. (string-append (ungexp %bootstrap-guile)
  1153. "/bin/guile")
  1154. "-c" (object->string
  1155. '(display (expt (ungexp n) 2))))))
  1156. (drv (gexp->script "guile-thing" exp
  1157. #:guile %bootstrap-guile))
  1158. (out -> (derivation->output-path drv))
  1159. (done (built-derivations (list drv))))
  1160. (let* ((pipe (open-input-pipe out))
  1161. (str (get-string-all pipe)))
  1162. (return (and (zero? (close-pipe pipe))
  1163. (= (expt n 2) (string->number str)))))))
  1164. (test-assert "gexp->script #:module-path"
  1165. (call-with-temporary-directory
  1166. (lambda (directory)
  1167. (define str
  1168. "Fake (guix base32) module!")
  1169. (mkdir (string-append directory "/guix"))
  1170. (call-with-output-file (string-append directory "/guix/base32.scm")
  1171. (lambda (port)
  1172. (write `(begin (define-module (guix base32))
  1173. (define-public %fake! ,str))
  1174. port)))
  1175. (run-with-store %store
  1176. (mlet* %store-monad ((exp -> (with-imported-modules '((guix base32))
  1177. (gexp (begin
  1178. (use-modules (guix base32))
  1179. (write (list %load-path
  1180. %fake!))))))
  1181. (drv (gexp->script "guile-thing" exp
  1182. #:guile %bootstrap-guile
  1183. #:module-path (list directory)))
  1184. (out -> (derivation->output-path drv))
  1185. (done (built-derivations (list drv))))
  1186. (let* ((pipe (open-input-pipe out))
  1187. (data (read pipe)))
  1188. (return (and (zero? (close-pipe pipe))
  1189. (match data
  1190. ((load-path str*)
  1191. (and (string=? str* str)
  1192. (not (member directory load-path)))))))))))))
  1193. (test-assertm "program-file"
  1194. (let* ((n (random (expt 2 50)))
  1195. (exp (with-imported-modules '((guix build utils))
  1196. (gexp (begin
  1197. (use-modules (guix build utils))
  1198. (display (ungexp n))))))
  1199. (file (program-file "program" exp
  1200. #:guile %bootstrap-guile)))
  1201. (mlet* %store-monad ((drv (lower-object file))
  1202. (out -> (derivation->output-path drv)))
  1203. (mbegin %store-monad
  1204. (built-derivations (list drv))
  1205. (let* ((pipe (open-input-pipe out))
  1206. (str (get-string-all pipe)))
  1207. (return (and (zero? (close-pipe pipe))
  1208. (= n (string->number str)))))))))
  1209. (test-assert "program-file #:module-path"
  1210. (call-with-temporary-directory
  1211. (lambda (directory)
  1212. (define text (random-text))
  1213. (call-with-output-file (string-append directory "/stupid-module.scm")
  1214. (lambda (port)
  1215. (write `(begin (define-module (stupid-module))
  1216. (define-public %stupid-thing ,text))
  1217. port)))
  1218. (let* ((exp (with-imported-modules '((stupid-module))
  1219. (gexp (begin
  1220. (use-modules (stupid-module))
  1221. (display %stupid-thing)))))
  1222. (file (program-file "program" exp
  1223. #:guile %bootstrap-guile
  1224. #:module-path (list directory))))
  1225. (run-with-store %store
  1226. (mlet* %store-monad ((drv (lower-object file))
  1227. (out -> (derivation->output-path drv)))
  1228. (mbegin %store-monad
  1229. (built-derivations (list drv))
  1230. (let* ((pipe (open-input-pipe out))
  1231. (str (get-string-all pipe)))
  1232. (return (and (zero? (close-pipe pipe))
  1233. (string=? text str)))))))))))
  1234. (test-assertm "program-file & with-extensions"
  1235. (let* ((exp (with-extensions (list %extension-package)
  1236. (gexp (begin
  1237. (use-modules (hg2g))
  1238. (display the-answer)))))
  1239. (file (program-file "program" exp
  1240. #:guile %bootstrap-guile)))
  1241. (mlet* %store-monad ((drv (lower-object file))
  1242. (out -> (derivation->output-path drv)))
  1243. (mbegin %store-monad
  1244. (built-derivations (list drv))
  1245. (let* ((pipe (open-input-pipe out))
  1246. (str (get-string-all pipe)))
  1247. (return (and (zero? (close-pipe pipe))
  1248. (= 42 (string->number str)))))))))
  1249. (test-assertm "program-file #:system"
  1250. (let* ((exp (with-imported-modules '((guix build utils))
  1251. (gexp (begin
  1252. (use-modules (guix build utils))
  1253. (display "hi!")))))
  1254. (system (if (string=? (%current-system) "x86_64-linux")
  1255. "armhf-linux"
  1256. "x86_64-linux"))
  1257. (file (program-file "program" exp)))
  1258. (mlet %store-monad ((drv (lower-object file system)))
  1259. (return (and (string=? (derivation-system drv) system)
  1260. (find (lambda (input)
  1261. (let ((drv (pk (derivation-input-derivation input))))
  1262. (and (string=? (derivation-name drv)
  1263. "module-import-compiled")
  1264. (string=? (derivation-system drv)
  1265. system))))
  1266. (derivation-inputs drv)))))))
  1267. (test-assertm "scheme-file"
  1268. (let* ((text (plain-file "foo" "Hello, world!"))
  1269. (scheme (scheme-file "bar" #~(list "foo" #$text))))
  1270. (mlet* %store-monad ((drv (lower-object scheme))
  1271. (text (lower-object text))
  1272. (out -> (derivation->output-path drv)))
  1273. (mbegin %store-monad
  1274. (built-derivations (list drv))
  1275. (mlet %store-monad ((refs (references* out)))
  1276. (return (and (equal? refs (list text))
  1277. (equal? `(list "foo" ,text)
  1278. (call-with-input-file out read)))))))))
  1279. (test-assertm "raw-derivation-file"
  1280. (let* ((exp #~(let ((drv #$(raw-derivation-file coreutils)))
  1281. (when (file-exists? drv)
  1282. (symlink drv #$output)))))
  1283. (mlet* %store-monad ((dep (lower-object coreutils))
  1284. (drv (gexp->derivation "drv-ref" exp))
  1285. (out -> (derivation->output-path drv)))
  1286. (mbegin %store-monad
  1287. (built-derivations (list drv))
  1288. (mlet %store-monad ((refs (references* out)))
  1289. (return (and (member (derivation-file-name dep)
  1290. (derivation-sources drv))
  1291. (not (member (derivation-file-name dep)
  1292. (map derivation-input-path
  1293. (derivation-inputs drv))))
  1294. (equal? (readlink out) (derivation-file-name dep))
  1295. (equal? refs (list (derivation-file-name dep))))))))))
  1296. (test-assert "text-file*"
  1297. (run-with-store %store
  1298. (mlet* %store-monad
  1299. ((drv (package->derivation %bootstrap-guile))
  1300. (guile -> (derivation->output-path drv))
  1301. (file (text-file "bar" "This is bar."))
  1302. (text (text-file* "foo"
  1303. %bootstrap-guile "/bin/guile "
  1304. (gexp-input %bootstrap-guile "out") "/bin/guile "
  1305. drv "/bin/guile "
  1306. file))
  1307. (done (built-derivations (list text)))
  1308. (out -> (derivation->output-path text))
  1309. (refs (references* out)))
  1310. ;; Make sure we get the right references and the right content.
  1311. (return (and (lset= string=? refs (list guile file))
  1312. (equal? (call-with-input-file out get-string-all)
  1313. (string-append guile "/bin/guile "
  1314. guile "/bin/guile "
  1315. guile "/bin/guile "
  1316. file)))))
  1317. #:guile-for-build (package-derivation %store %bootstrap-guile)))
  1318. (test-assertm "mixed-text-file"
  1319. (mlet* %store-monad ((file -> (mixed-text-file "mixed"
  1320. #:guile %bootstrap-guile
  1321. "export PATH="
  1322. %bootstrap-guile "/bin"))
  1323. (drv (lower-object file))
  1324. (out -> (derivation->output-path drv))
  1325. (guile-drv (package->derivation %bootstrap-guile))
  1326. (guile -> (derivation->output-path guile-drv)))
  1327. (mbegin %store-monad
  1328. (built-derivations (list drv))
  1329. (mlet %store-monad ((refs (references* out)))
  1330. (return (and (string=? (string-append "export PATH=" guile "/bin")
  1331. (call-with-input-file out get-string-all))
  1332. (equal? refs (list guile))))))))
  1333. (test-assertm "file-union"
  1334. (mlet* %store-monad ((union -> (file-union "union"
  1335. `(("a" ,(plain-file "a" "1"))
  1336. ("b/c/d" ,(plain-file "d" "2"))
  1337. ("e" ,(plain-file "e" "3")))
  1338. #:guile %bootstrap-guile))
  1339. (drv (lower-object union))
  1340. (out -> (derivation->output-path drv)))
  1341. (define (contents=? file str)
  1342. (string=? (call-with-input-file (string-append out "/" file)
  1343. get-string-all)
  1344. str))
  1345. (mbegin %store-monad
  1346. (built-derivations (list drv))
  1347. (return (and (contents=? "a" "1")
  1348. (contents=? "b/c/d" "2")
  1349. (contents=? "e" "3"))))))
  1350. (test-assert "gexp->derivation vs. %current-target-system"
  1351. (let ((mval (gexp->derivation "foo"
  1352. #~(begin
  1353. (mkdir #$output)
  1354. (foo #+gnu-make))
  1355. #:target #f)))
  1356. ;; The value of %CURRENT-TARGET-SYSTEM at bind-time should have no
  1357. ;; influence.
  1358. (parameterize ((%current-target-system "fooooo"))
  1359. (derivation? (run-with-store %store mval)))))
  1360. (test-assertm "lower-object"
  1361. (mlet %store-monad ((drv1 (lower-object %bootstrap-guile))
  1362. (drv2 (lower-object (package-source coreutils)))
  1363. (item (lower-object (plain-file "foo" "Hello!"))))
  1364. (return (and (derivation? drv1) (derivation? drv2)
  1365. (store-path? item)))))
  1366. (test-assertm "lower-object, computed-file"
  1367. (let* ((text (plain-file "foo" "Hello!"))
  1368. (exp #~(begin
  1369. (mkdir #$output)
  1370. (symlink #$%bootstrap-guile
  1371. (string-append #$output "/guile"))
  1372. (symlink #$text (string-append #$output "/text"))))
  1373. (computed (computed-file "computed" exp
  1374. #:guile %bootstrap-guile)))
  1375. (mlet* %store-monad ((text (lower-object text))
  1376. (guile-drv (lower-object %bootstrap-guile))
  1377. (comp-drv (lower-object computed))
  1378. (comp -> (derivation->output-path comp-drv)))
  1379. (mbegin %store-monad
  1380. (built-derivations (list comp-drv))
  1381. (return (and (string=? (readlink (string-append comp "/guile"))
  1382. (derivation->output-path guile-drv))
  1383. (string=? (readlink (string-append comp "/text"))
  1384. text)))))))
  1385. (test-assert "lower-object, computed-file + grafts"
  1386. ;; The reference graph should refer to grafted packages when grafts are
  1387. ;; enabled. See <https://issues.guix.gnu.org/50676>.
  1388. (let* ((base (package
  1389. (inherit (dummy-package "trivial"))
  1390. (build-system trivial-build-system)
  1391. (arguments
  1392. `(#:guile ,%bootstrap-guile
  1393. #:builder (mkdir %output)))))
  1394. (pkg (package
  1395. (inherit base)
  1396. (version "1.1")
  1397. (replacement (package
  1398. (inherit base)
  1399. (version "9.9")))))
  1400. (exp #~(begin
  1401. (use-modules (ice-9 rdelim))
  1402. (let ((item (call-with-input-file "graph" read-line)))
  1403. (call-with-output-file #$output
  1404. (lambda (port)
  1405. (display item port))))))
  1406. (computed (computed-file "computed" exp
  1407. #:options
  1408. `(#:references-graphs (("graph" ,pkg)))
  1409. #:guile %bootstrap-guile))
  1410. (drv0 (package-derivation %store pkg #:graft? #t))
  1411. (drv1 (parameterize ((%graft? #t))
  1412. (run-with-store %store
  1413. (lower-object computed)))))
  1414. (build-derivations %store (list drv1))
  1415. ;; The graph obtained in COMPUTED should refer to the grafted version of
  1416. ;; PKG, not to PKG itself.
  1417. (string=? (call-with-input-file (derivation->output-path drv1)
  1418. get-string-all)
  1419. (derivation->output-path drv0))))
  1420. (test-equal "lower-object, computed-file, #:system"
  1421. '("mips64el-linux")
  1422. (run-with-store %store
  1423. (let* ((exp #~(symlink #$coreutils #$output))
  1424. (computed (computed-file "computed" exp
  1425. #:guile %bootstrap-guile)))
  1426. ;; Make sure that the SYSTEM argument to 'lower-object' is honored.
  1427. (mlet* %store-monad ((drv (lower-object computed "mips64el-linux"))
  1428. (refs (references* (derivation-file-name drv))))
  1429. (return (delete-duplicates
  1430. (filter-map (lambda (file)
  1431. (and (string-suffix? ".drv" file)
  1432. (let ((drv (read-derivation-from-file
  1433. file)))
  1434. (derivation-system drv))))
  1435. (cons (derivation-file-name drv)
  1436. refs))))))))
  1437. (test-assertm "lower-object, computed-file, #:target"
  1438. (let* ((target "i586-pc-gnu")
  1439. (computed (computed-file "computed-cross"
  1440. #~(symlink #$coreutils output)
  1441. #:guile (default-guile))))
  1442. ;; When lowered to TARGET, the derivation of COMPUTED should run natively,
  1443. ;; using a native Guile, but it should refer to the target COREUTILS.
  1444. (mlet* %store-monad ((drv (lower-object computed (%current-system)
  1445. #:target target))
  1446. (refs (references* (derivation-file-name drv)))
  1447. (guile (lower-object (default-guile)
  1448. (%current-system)
  1449. #:target #f))
  1450. (cross (lower-object coreutils #:target target))
  1451. (native (lower-object coreutils #:target #f)))
  1452. (return (and (string=? (derivation-system (pk 'drv drv)) (%current-system))
  1453. (string=? (derivation-builder drv)
  1454. (string-append (derivation->output-path guile)
  1455. "/bin/guile"))
  1456. (not (member (derivation-file-name native) refs))
  1457. (member (derivation-file-name cross) refs))))))
  1458. (test-assert "lower-object & gexp-input-error?"
  1459. (guard (c ((gexp-input-error? c)
  1460. (gexp-error-invalid-input c)))
  1461. (run-with-store %store
  1462. (lower-object (current-module))
  1463. #:guile-for-build (%guile-for-build))))
  1464. (test-assert "printer"
  1465. (string-match "^#<gexp \\(string-append .*#<package coreutils.*\
  1466. \"/bin/uname\"\\) [[:graph:]]+tests/gexp\\.scm:[0-9]+:[0-9]+ [[:xdigit:]]+>$"
  1467. (with-output-to-string
  1468. (lambda ()
  1469. (write
  1470. (gexp (string-append (ungexp coreutils)
  1471. "/bin/uname")))))))
  1472. (test-assert "printer vs. ungexp-splicing"
  1473. (string-match "^#<gexp .* [[:xdigit:]]+>$"
  1474. (with-output-to-string
  1475. (lambda ()
  1476. ;; #~(begin #$@#~())
  1477. (write
  1478. (gexp (begin (ungexp-splicing (gexp ())))))))))
  1479. (test-equal "sugar"
  1480. '(gexp (foo (ungexp bar) (ungexp baz "out")
  1481. (ungexp (chbouib 42))
  1482. (ungexp-splicing (list x y z))
  1483. (ungexp-native foo) (ungexp-native foo "out")
  1484. (ungexp-native (chbouib 42))
  1485. (ungexp-native-splicing (list x y z))))
  1486. '#~(foo #$bar #$baz:out #$(chbouib 42) #$@(list x y z)
  1487. #+foo #+foo:out #+(chbouib 42) #+@(list x y z)))
  1488. (test-assertm "gexp->file, cross-compilation"
  1489. (mlet* %store-monad ((target -> "aarch64-linux-gnu")
  1490. (exp -> (gexp (list (ungexp coreutils))))
  1491. (xdrv (gexp->file "foo" exp #:target target))
  1492. (refs (references*
  1493. (derivation-file-name xdrv)))
  1494. (xcu (package->cross-derivation coreutils
  1495. target))
  1496. (cu (package->derivation coreutils)))
  1497. (return (and (member (derivation-file-name xcu) refs)
  1498. (not (member (derivation-file-name cu) refs))))))
  1499. (test-assertm "gexp->file, cross-compilation with default target"
  1500. (mlet* %store-monad ((target -> "aarch64-linux-gnu")
  1501. (_ (set-current-target target))
  1502. (exp -> (gexp (list (ungexp coreutils))))
  1503. (xdrv (gexp->file "foo" exp))
  1504. (refs (references*
  1505. (derivation-file-name xdrv)))
  1506. (xcu (package->cross-derivation coreutils
  1507. target))
  1508. (cu (package->derivation coreutils)))
  1509. (return (and (member (derivation-file-name xcu) refs)
  1510. (not (member (derivation-file-name cu) refs))))))
  1511. (test-assertm "gexp->script, cross-compilation"
  1512. (mlet* %store-monad ((target -> "aarch64-linux-gnu")
  1513. (exp -> (gexp (list (ungexp coreutils))))
  1514. (xdrv (gexp->script "foo" exp #:target target))
  1515. (refs (references*
  1516. (derivation-file-name xdrv)))
  1517. (xcu (package->cross-derivation coreutils
  1518. target))
  1519. (cu (package->derivation coreutils)))
  1520. (return (and (member (derivation-file-name xcu) refs)
  1521. (not (member (derivation-file-name cu) refs))))))
  1522. (test-assertm "gexp->script, cross-compilation with default target"
  1523. (mlet* %store-monad ((target -> "aarch64-linux-gnu")
  1524. (_ (set-current-target target))
  1525. (exp -> (gexp (list (ungexp coreutils))))
  1526. (xdrv (gexp->script "foo" exp))
  1527. (refs (references*
  1528. (derivation-file-name xdrv)))
  1529. (xcu (package->cross-derivation coreutils
  1530. target))
  1531. (cu (package->derivation coreutils)))
  1532. (return (and (member (derivation-file-name xcu) refs)
  1533. (not (member (derivation-file-name cu) refs))))))
  1534. (test-end "gexp")
  1535. ;; Local Variables:
  1536. ;; eval: (put 'test-assertm 'scheme-indent-function 1)
  1537. ;; End: