gexp.scm 78 KB

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