guix-build.sh 11 KB

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