guix-build.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. # Unbound variable: don't suggest modules that do not export the variable.
  167. cat > "$module_dir/aa-private.scm" <<EOF
  168. (define-module (aa-private))
  169. (define make-thing #f)
  170. (set! make-thing make-thing) ;don't inline
  171. EOF
  172. cat > "$module_dir/bb-public.scm" <<EOF
  173. (define-module (bb-public) #:export (make-thing))
  174. (define make-thing identity)
  175. EOF
  176. cat > "$module_dir/cc-user.scm" <<EOF
  177. ;; Make those module available in the global name space.
  178. (load-from-path "aa-private.scm")
  179. (load-from-path "bb-public.scm")
  180. (define-module (cc-user))
  181. (make-thing 42)
  182. EOF
  183. ! guix build -f "$module_dir/cc-user.scm" -n 2> "$module_dir/err"
  184. cat "$module_dir/err"
  185. grep "make-thing.*unbound" "$module_dir/err" # actual error
  186. grep "forget.*(bb-public)" "$module_dir/err" # hint
  187. rm -f "$module_dir"/*
  188. # Wrong 'define-module' clause reported by 'warn-about-load-error'.
  189. cat > "$module_dir/foo.scm" <<EOF
  190. (define-module (something foo)
  191. #:use-module (guix)
  192. #:use-module (gnu))
  193. EOF
  194. guix build guile-bootstrap -n 2> "$module_dir/err"
  195. grep "does not match file name" "$module_dir/err"
  196. rm "$module_dir"/*
  197. # Should all return valid log files.
  198. drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  199. out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  200. log="`guix build --log-file $drv`"
  201. echo "$log" | grep log/.*guile.*drv
  202. test -f "$log"
  203. test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
  204. = "$log"
  205. test "`guix build --log-file guile-bootstrap`" = "$log"
  206. test "`guix build --log-file $out`" = "$log"
  207. # Should fail because the name/version combination could not be found.
  208. ! guix build hello-0.0.1 -n
  209. # Keep a symlink to the result, registered as a root.
  210. result="t-result-$$"
  211. guix build -r "$result" \
  212. -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  213. test -x "$result/bin/guile"
  214. # Should fail, because $result already exists.
  215. ! guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  216. rm -f "$result"
  217. # Check relative file name canonicalization: <https://bugs.gnu.org/35271>.
  218. mkdir "$result"
  219. guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  220. test -x "$result/x/bin/guile"
  221. rm "$result/x"
  222. rmdir "$result"
  223. # Cross building.
  224. guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
  225. # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>).
  226. guix build --target=arm-linux-gnueabihf --dry-run \
  227. -e '(@ (gnu packages base) coreutils)'
  228. # Replacements.
  229. drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
  230. drv2=`guix build guix -d`
  231. test "$drv1" != "$drv2"
  232. drv1=`guix build guile -d`
  233. drv2=`guix build guile --with-input=gimp=ruby -d`
  234. test "$drv1" = "$drv2"
  235. # See <https://bugs.gnu.org/42156>.
  236. drv1=`guix build glib -d`
  237. drv2=`guix build glib -d --with-input=libreoffice=inkscape`
  238. test "$drv1" = "$drv2"
  239. # '--with-graft' should have no effect when using '--no-grafts'.
  240. # See <https://bugs.gnu.org/43890>.
  241. drv1=`guix build inkscape -d --no-grafts`
  242. drv2=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking`
  243. test "$drv1" = "$drv2"
  244. # Rewriting implicit inputs.
  245. drv1=`guix build hello -d`
  246. drv2=`guix build hello -d --with-input=gcc=gcc-toolchain`
  247. test "$drv1" != "$drv2"
  248. guix gc -R "$drv2" | grep `guix build -d gcc-toolchain`
  249. ! guix build guile --with-input=libunistring=something-really-silly
  250. # Deprecated/superseded packages.
  251. test "`guix build superseded -d`" = "`guix build bar -d`"
  252. # Parsing package names and versions.
  253. guix build -n time # PASS
  254. guix build -n time@1.9 # PASS, version found
  255. ! guix build -n time@3.2 # FAIL, version not found
  256. ! guix build -n something-that-will-never-exist # FAIL
  257. # Invoking a monadic procedure.
  258. guix build -e "(begin
  259. (use-modules (guix gexp))
  260. (lambda ()
  261. (gexp->derivation \"test\"
  262. (gexp (mkdir (ungexp output))))))" \
  263. --dry-run
  264. # Running a gexp.
  265. guix build -e '#~(mkdir #$output)' -d
  266. guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
  267. # Same with a file-like object.
  268. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
  269. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
  270. # Building from a package file.
  271. cat > "$module_dir/package.scm"<<EOF
  272. (use-modules (gnu))
  273. (use-package-modules bootstrap)
  274. %bootstrap-guile
  275. EOF
  276. guix build --file="$module_dir/package.scm"
  277. # Building from a monadic procedure file.
  278. cat > "$module_dir/proc.scm"<<EOF
  279. (use-modules (guix gexp))
  280. (lambda ()
  281. (gexp->derivation "test"
  282. (gexp (mkdir (ungexp output)))))
  283. EOF
  284. guix build --file="$module_dir/proc.scm" --dry-run
  285. # Building from a gexp file.
  286. cat > "$module_dir/gexp.scm"<<EOF
  287. (use-modules (guix gexp))
  288. (gexp (mkdir (ungexp output)))
  289. EOF
  290. guix build --file="$module_dir/gexp.scm" -d
  291. guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
  292. # Building from a manifest file.
  293. cat > "$module_dir/manifest.scm"<<EOF
  294. (specifications->manifest '("hello" "guix"))
  295. EOF
  296. test `guix build -d --manifest="$module_dir/manifest.scm" \
  297. | grep -e '-hello-' -e '-guix-' \
  298. | wc -l` -eq 2
  299. # Building from a manifest that contains a non-package object.
  300. cat > "$module_dir/manifest.scm"<<EOF
  301. (manifest
  302. (list (manifest-entry (name "foo") (version "0")
  303. (item (computed-file "computed-thingie"
  304. #~(mkdir (ungexp output)))))))
  305. EOF
  306. guix build -d -m "$module_dir/manifest.scm" \
  307. | grep 'computed-thingie\.drv$'
  308. rm "$module_dir"/*.scm
  309. # Using 'GUIX_BUILD_OPTIONS'.
  310. GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
  311. export GUIX_BUILD_OPTIONS
  312. guix build emacs
  313. GUIX_BUILD_OPTIONS="--something-completely-crazy"
  314. ! guix build emacs