gexp.scm 79 KB

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