guix-build.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2012-2014, 2016-2022 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
  4. # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
  5. #
  6. # This file is part of GNU Guix.
  7. #
  8. # GNU Guix is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or (at
  11. # your option) any later version.
  12. #
  13. # GNU Guix is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # Test the `guix build' command-line utility.
  22. #
  23. guix build --version
  24. # Should fail.
  25. guix build -e + && false
  26. # Source-less packages are accepted; they just return nothing.
  27. guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S
  28. test "`guix build -e '(@ (gnu packages bootstrap) %bootstrap-glibc)' -S`" = ""
  29. # Warn when attempting to build an unsupported package.
  30. case "$(guix build intelmetool -s armhf-linux -v0 -n 2>&1)" in
  31. *warning:*intelmetool*support*armhf*)
  32. true
  33. break;;
  34. *)
  35. false;
  36. break;;
  37. esac
  38. # Should pass.
  39. guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' | \
  40. grep -e '-guile-'
  41. guix build hello -d | \
  42. grep -e '-hello-[0-9\.]\+\.drv$'
  43. # Passing a .drv.
  44. drv="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' -d`"
  45. out="`guix build "$drv"`"
  46. out2="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  47. test "$out" = "$out2"
  48. # Passing the name of a .drv that doesn't exist. The daemon should try to
  49. # substitute the .drv. Here we just look for the "cannot build missing
  50. # derivation" error that indicates that the daemon did try to substitute the
  51. # .drv.
  52. guix build "$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo.drv" 2>&1 \
  53. | grep "missing derivation"
  54. # Passing a URI.
  55. GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
  56. guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  57. ( if GUIX_DAEMON_SOCKET="weird://uri" \
  58. guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
  59. then exit 1; fi )
  60. # Passing one '-s' flag.
  61. test `guix build sed -s x86_64-linux -d | wc -l` = 1
  62. # Passing multiple '-s' flags.
  63. all_systems="-s x86_64-linux -s i686-linux -s armhf-linux -s aarch64-linux \
  64. -s powerpc64le-linux"
  65. test `guix build sed $all_systems -d | sort -u | wc -l` = 5
  66. # Check there's no weird memoization effect leading to erroneous results.
  67. # See <https://bugs.gnu.org/40482>.
  68. drv1="`guix build sed -s x86_64-linux -s armhf-linux -d | sort`"
  69. drv2="`guix build sed -s armhf-linux -s x86_64-linux -d | sort`"
  70. test "$drv1" = "$drv2"
  71. # Check --sources option with its arguments
  72. module_dir="t-guix-build-$$"
  73. mkdir "$module_dir"
  74. trap "rm -rf $module_dir" EXIT
  75. # Check error reporting for '-f'.
  76. cat > "$module_dir/foo.scm" <<EOF
  77. (use-modules (guix))
  78. ) ;extra closing paren
  79. EOF
  80. guix build -f "$module_dir/foo.scm" 2> "$module_dir/stderr" && false
  81. grep "read error" "$module_dir/stderr"
  82. rm "$module_dir/stderr" "$module_dir/foo.scm"
  83. # Check 'GUIX_PACKAGE_PATH' & co.
  84. cat > "$module_dir/foo.scm"<<EOF
  85. (define-module (foo)
  86. #:use-module (guix tests)
  87. #:use-module (guix packages)
  88. #:use-module (guix download)
  89. #:use-module (guix build-system trivial))
  90. (define-public foo
  91. (package
  92. (name "foo")
  93. (version "42")
  94. (source (origin
  95. (method url-fetch)
  96. (uri "http://www.example.com/foo.tar.gz")
  97. (sha256
  98. (base32
  99. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
  100. (build-system trivial-build-system)
  101. (inputs
  102. (quasiquote (("bar" ,bar))))
  103. (home-page "www.example.com")
  104. (synopsis "Dummy package")
  105. (description "foo is a dummy package for testing.")
  106. (license #f)))
  107. (define-public bar
  108. (package
  109. (name "bar")
  110. (version "9001")
  111. (source (origin
  112. (method url-fetch)
  113. (uri "http://www.example.com/bar.tar.gz")
  114. (sha256
  115. (base32
  116. "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
  117. (build-system trivial-build-system)
  118. (inputs
  119. (quasiquote
  120. (("data" ,(origin
  121. (method url-fetch)
  122. (uri "http://www.example.com/bar.dat")
  123. (sha256
  124. (base32
  125. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
  126. (home-page "www.example.com")
  127. (synopsis "Dummy package")
  128. (description "bar is a dummy package for testing.")
  129. (license #f)))
  130. (define-public baz
  131. (dummy-package "baz" (replacement foo)))
  132. (define-public superseded
  133. (deprecated-package "superseded" bar))
  134. EOF
  135. GUIX_PACKAGE_PATH="$module_dir"
  136. export GUIX_PACKAGE_PATH
  137. # foo.tar.gz
  138. guix build -d -S foo
  139. guix build -d -S foo | grep -e 'foo\.tar\.gz'
  140. # 'baz' has a replacement so we should be getting the replacement's source.
  141. (unset GUIX_BUILD_OPTIONS;
  142. test "`guix build -d -S baz`" = "`guix build -d -S foo`")
  143. guix build -d --sources=package foo
  144. guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
  145. # bar.tar.gz and bar.dat
  146. guix build -d --sources bar
  147. test `guix build -d --sources bar \
  148. | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
  149. | wc -l` -eq 2
  150. # bar.tar.gz and bar.dat
  151. guix build -d --sources=all bar
  152. test `guix build -d --sources bar \
  153. | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
  154. | wc -l` -eq 2
  155. # Should include foo.tar.gz, bar.tar.gz, and bar.dat
  156. guix build -d --sources=transitive foo
  157. test `guix build -d --sources=transitive foo \
  158. | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
  159. | wc -l` -eq 3
  160. # Unbound variable in thunked field.
  161. cat > "$module_dir/foo.scm" <<EOF
  162. (define-module (foo)
  163. #:use-module (guix tests)
  164. #:use-module (guix build-system trivial))
  165. (define-public foo
  166. (dummy-package "package-with-something-wrong"
  167. (build-system trivial-build-system)
  168. (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
  169. EOF
  170. guix build package-with-something-wrong -n && false
  171. guix build package-with-something-wrong -n 2> "$module_dir/err" || true
  172. grep "unbound" "$module_dir/err" # actual error
  173. grep "forget.*(gnu packages base)" "$module_dir/err" # hint
  174. # Unbound variable at the top level.
  175. cat > "$module_dir/foo.scm" <<EOF
  176. (define-module (foo)
  177. #:use-module (guix tests))
  178. (define-public foo
  179. (dummy-package "package-with-something-wrong"
  180. (build-system gnu-build-system))) ;unbound variable
  181. EOF
  182. guix build sed -n 2> "$module_dir/err"
  183. grep "unbound" "$module_dir/err" # actual error
  184. grep "forget.*(guix build-system gnu)" "$module_dir/err" # hint
  185. rm -f "$module_dir"/*
  186. # Unbound variable: don't suggest modules that do not export the variable.
  187. cat > "$module_dir/aa-private.scm" <<EOF
  188. (define-module (aa-private))
  189. (define make-thing #f)
  190. (set! make-thing make-thing) ;don't inline
  191. EOF
  192. cat > "$module_dir/bb-public.scm" <<EOF
  193. (define-module (bb-public) #:export (make-thing))
  194. (define make-thing identity)
  195. EOF
  196. cat > "$module_dir/cc-user.scm" <<EOF
  197. ;; Make those module available in the global name space.
  198. (load-from-path "aa-private.scm")
  199. (load-from-path "bb-public.scm")
  200. (define-module (cc-user))
  201. (make-thing 42)
  202. EOF
  203. guix build -f "$module_dir/cc-user.scm" -n 2> "$module_dir/err" && false
  204. cat "$module_dir/err"
  205. grep "make-thing.*unbound" "$module_dir/err" # actual error
  206. grep "forget.*(bb-public)" "$module_dir/err" # hint
  207. rm -f "$module_dir"/*
  208. # Wrong 'define-module' clause reported by 'warn-about-load-error'.
  209. cat > "$module_dir/foo.scm" <<EOF
  210. (define-module (something foo)
  211. #:use-module (guix)
  212. #:use-module (gnu))
  213. EOF
  214. guix build guile-bootstrap -n 2> "$module_dir/err"
  215. grep "does not match file name" "$module_dir/err"
  216. rm "$module_dir"/*
  217. # Should all return valid log files.
  218. drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  219. out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  220. log="`guix build --log-file $drv`"
  221. echo "$log" | grep log/.*guile.*drv
  222. test -f "$log"
  223. test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
  224. = "$log"
  225. test "`guix build --log-file guile-bootstrap`" = "$log"
  226. test "`guix build --log-file $out`" = "$log"
  227. # Should fail because the name/version combination could not be found.
  228. guix build hello-0.0.1 -n && false
  229. # Keep a symlink to the result, registered as a root.
  230. result="t-result-$$"
  231. guix build -r "$result" \
  232. -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  233. test -x "$result/bin/guile"
  234. # Should fail, because $result already exists.
  235. guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' && false
  236. rm -f "$result"
  237. # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
  238. mkdir "$result"
  239. guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  240. test -x "$result/x/bin/guile"
  241. rm "$result/x"
  242. rmdir "$result"
  243. # Cross building.
  244. guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
  245. # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
  246. guix build --target=arm-linux-gnueabihf --dry-run \
  247. -e '(@ (gnu packages base) coreutils)'
  248. # Replacements.
  249. drv1=`guix build guix --with-input=guile-zstd=idutils -d`
  250. drv2=`guix build guix -d`
  251. test "$drv1" != "$drv2"
  252. drv1=`guix build guile -d`
  253. drv2=`guix build guile --with-input=gimp=ruby -d`
  254. test "$drv1" = "$drv2"
  255. # See <https://bugs.gnu.org/42156>.
  256. drv1=`guix build glib -d`
  257. drv2=`guix build glib -d --with-input=libreoffice=inkscape`
  258. test "$drv1" = "$drv2"
  259. # '--with-graft' should have no effect when using '--no-grafts'.
  260. # See <https://bugs.gnu.org/43890>.
  261. drv1=`guix build inkscape -d --no-grafts`
  262. drv2=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking`
  263. test "$drv1" = "$drv2"
  264. # Rewriting implicit inputs.
  265. drv1=`guix build grep -d`
  266. drv2=`guix build grep -d --with-input=coreutils=hello`
  267. test "$drv1" != "$drv2"
  268. guix gc -R "$drv2" | grep `guix build -d hello`
  269. guix build guile --with-input=libunistring=something-really-silly && false
  270. # Deprecated/superseded packages.
  271. test "`guix build superseded -d`" = "`guix build bar -d`"
  272. # Parsing package names and versions.
  273. guix build -n time # PASS
  274. guix build -n time@1.9 # PASS, version found
  275. guix build -n time@3.2 && false # FAIL, version not found
  276. guix build -n something-that-will-never-exist && false # FAIL
  277. # Invoking a monadic procedure.
  278. guix build -e "(begin
  279. (use-modules (guix gexp))
  280. (lambda ()
  281. (gexp->derivation \"test\"
  282. (gexp (mkdir (ungexp output))))))" \
  283. --dry-run
  284. # Running a gexp.
  285. guix build -e '#~(mkdir #$output)' -d
  286. guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
  287. # Same with a file-like object.
  288. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
  289. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
  290. # Building from a package file.
  291. cat > "$module_dir/package.scm"<<EOF
  292. (use-modules (gnu))
  293. (use-package-modules bootstrap)
  294. %bootstrap-guile
  295. EOF
  296. guix build --file="$module_dir/package.scm"
  297. # Building from a monadic procedure file.
  298. cat > "$module_dir/proc.scm"<<EOF
  299. (use-modules (guix gexp))
  300. (lambda ()
  301. (gexp->derivation "test"
  302. (gexp (mkdir (ungexp output)))))
  303. EOF
  304. guix build --file="$module_dir/proc.scm" --dry-run
  305. # Building from a gexp file.
  306. cat > "$module_dir/gexp.scm"<<EOF
  307. (use-modules (guix gexp))
  308. (gexp (mkdir (ungexp output)))
  309. EOF
  310. guix build --file="$module_dir/gexp.scm" -d
  311. guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
  312. # Building from a manifest file.
  313. cat > "$module_dir/manifest.scm"<<EOF
  314. (specifications->manifest '("hello" "guix"))
  315. EOF
  316. test `guix build -d --manifest="$module_dir/manifest.scm" \
  317. | grep -e '-hello-' -e '-guix-' \
  318. | wc -l` -eq 2
  319. # Building from a manifest that contains a non-package object.
  320. cat > "$module_dir/manifest.scm"<<EOF
  321. (manifest
  322. (list (manifest-entry (name "foo") (version "0")
  323. (item (computed-file "computed-thingie"
  324. #~(mkdir (ungexp output)))))))
  325. EOF
  326. guix build -d -m "$module_dir/manifest.scm" \
  327. | grep 'computed-thingie\.drv$'
  328. rm "$module_dir"/*.scm
  329. # Using 'GUIX_BUILD_OPTIONS'.
  330. GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
  331. export GUIX_BUILD_OPTIONS
  332. guix build emacs
  333. GUIX_BUILD_OPTIONS="--something-completely-crazy"
  334. guix build emacs && false
  335. exit 0