guix-build.sh 12 KB

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