guix-build.sh 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2012, 2013, 2014, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test the `guix build' command-line utility.
  20. #
  21. guix build --version
  22. # Should fail.
  23. if guix build -e +;
  24. then false; else true; fi
  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 URI.
  34. GUIX_DAEMON_SOCKET="file://$GUIX_STATE_DIRECTORY/daemon-socket/socket" \
  35. guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  36. ( if GUIX_DAEMON_SOCKET="weird://uri" \
  37. guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'; \
  38. then exit 1; fi )
  39. # Check --sources option with its arguments
  40. module_dir="t-guix-build-$$"
  41. mkdir "$module_dir"
  42. trap "rm -rf $module_dir" EXIT
  43. cat > "$module_dir/foo.scm"<<EOF
  44. (define-module (foo)
  45. #:use-module (guix tests)
  46. #:use-module (guix packages)
  47. #:use-module (guix download)
  48. #:use-module (guix build-system trivial))
  49. (define-public foo
  50. (package
  51. (name "foo")
  52. (version "42")
  53. (source (origin
  54. (method url-fetch)
  55. (uri "http://www.example.com/foo.tar.gz")
  56. (sha256
  57. (base32
  58. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))))
  59. (build-system trivial-build-system)
  60. (inputs
  61. (quasiquote (("bar" ,bar))))
  62. (home-page "www.example.com")
  63. (synopsis "Dummy package")
  64. (description "foo is a dummy package for testing.")
  65. (license #f)))
  66. (define-public bar
  67. (package
  68. (name "bar")
  69. (version "9001")
  70. (source (origin
  71. (method url-fetch)
  72. (uri "http://www.example.com/bar.tar.gz")
  73. (sha256
  74. (base32
  75. "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"))))
  76. (build-system trivial-build-system)
  77. (inputs
  78. (quasiquote
  79. (("data" ,(origin
  80. (method url-fetch)
  81. (uri "http://www.example.com/bar.dat")
  82. (sha256
  83. (base32
  84. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")))))))
  85. (home-page "www.example.com")
  86. (synopsis "Dummy package")
  87. (description "bar is a dummy package for testing.")
  88. (license #f)))
  89. (define-public baz
  90. (dummy-package "baz" (replacement foo)))
  91. (define-public superseded
  92. (deprecated-package "superseded" bar))
  93. EOF
  94. GUIX_PACKAGE_PATH="$module_dir"
  95. export GUIX_PACKAGE_PATH
  96. # foo.tar.gz
  97. guix build -d -S foo
  98. guix build -d -S foo | grep -e 'foo\.tar\.gz'
  99. # 'baz' has a replacement so we should be getting the replacement's source.
  100. (unset GUIX_BUILD_OPTIONS;
  101. test "`guix build -d -S baz`" = "`guix build -d -S foo`")
  102. guix build -d --sources=package foo
  103. guix build -d --sources=package foo | grep -e 'foo\.tar\.gz'
  104. # bar.tar.gz and bar.dat
  105. guix build -d --sources bar
  106. test `guix build -d --sources bar \
  107. | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
  108. | wc -l` -eq 2
  109. # bar.tar.gz and bar.dat
  110. guix build -d --sources=all bar
  111. test `guix build -d --sources bar \
  112. | grep -e 'bar\.tar\.gz' -e 'bar\.dat' \
  113. | wc -l` -eq 2
  114. # Should include foo.tar.gz, bar.tar.gz, and bar.dat
  115. guix build -d --sources=transitive foo
  116. test `guix build -d --sources=transitive foo \
  117. | grep -e 'foo\.tar\.gz' -e 'bar\.tar\.gz' -e 'bar\.dat' \
  118. | wc -l` -eq 3
  119. # Unbound variables.
  120. cat > "$module_dir/foo.scm"<<EOF
  121. (define-module (foo)
  122. #:use-module (guix tests)
  123. #:use-module (guix build-system trivial))
  124. (define-public foo
  125. (dummy-package "package-with-something-wrong"
  126. (build-system trivial-build-system)
  127. (inputs (quasiquote (("sed" ,sed)))))) ;unbound variable
  128. EOF
  129. if guix build package-with-something-wrong -n; then false; else true; fi
  130. guix build package-with-something-wrong -n 2> "$module_dir/err" || true
  131. grep "unbound" "$module_dir/err" # actual error
  132. grep "forget.*(gnu packages base)" "$module_dir/err" # hint
  133. rm -f "$module_dir"/*
  134. # Should all return valid log files.
  135. drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  136. out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`"
  137. log="`guix build --log-file $drv`"
  138. echo "$log" | grep log/.*guile.*drv
  139. test -f "$log"
  140. test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \
  141. = "$log"
  142. test "`guix build --log-file guile-bootstrap`" = "$log"
  143. test "`guix build --log-file $out`" = "$log"
  144. # Should fail because the name/version combination could not be found.
  145. if guix build hello-0.0.1 -n; then false; else true; fi
  146. # Keep a symlink to the result, registered as a root.
  147. result="t-result-$$"
  148. guix build -r "$result" \
  149. -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  150. test -x "$result/bin/guile"
  151. # Should fail, because $result already exists.
  152. if guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'
  153. then false; else true; fi
  154. rm -f "$result"
  155. # Cross building.
  156. guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
  157. # Replacements.
  158. drv1=`guix build guix --with-input=guile@2.0=guile@2.2 -d`
  159. drv2=`guix build guix -d`
  160. test "$drv1" != "$drv2"
  161. drv1=`guix build guile -d`
  162. drv2=`guix build guile --with-input=gimp=ruby -d`
  163. test "$drv1" = "$drv2"
  164. if guix build guile --with-input=libunistring=something-really-silly
  165. then false; else true; fi
  166. # Deprecated/superseded packages.
  167. test "`guix build superseded -d`" = "`guix build bar -d`"
  168. # Parsing package names and versions.
  169. guix build -n time # PASS
  170. guix build -n time@1.9 # PASS, version found
  171. if guix build -n time@3.2; # FAIL, version not found
  172. then false; else true; fi
  173. if guix build -n something-that-will-never-exist; # FAIL
  174. then false; else true; fi
  175. # Invoking a monadic procedure.
  176. guix build -e "(begin
  177. (use-modules (guix gexp))
  178. (lambda ()
  179. (gexp->derivation \"test\"
  180. (gexp (mkdir (ungexp output))))))" \
  181. --dry-run
  182. # Running a gexp.
  183. guix build -e '#~(mkdir #$output)' -d
  184. guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
  185. # Same with a file-like object.
  186. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
  187. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
  188. # Building from a package file.
  189. cat > "$module_dir/package.scm"<<EOF
  190. (use-modules (gnu))
  191. (use-package-modules bootstrap)
  192. %bootstrap-guile
  193. EOF
  194. guix build --file="$module_dir/package.scm"
  195. # Building from a monadic procedure file.
  196. cat > "$module_dir/proc.scm"<<EOF
  197. (use-modules (guix gexp))
  198. (lambda ()
  199. (gexp->derivation "test"
  200. (gexp (mkdir (ungexp output)))))
  201. EOF
  202. guix build --file="$module_dir/proc.scm" --dry-run
  203. # Building from a gexp file.
  204. cat > "$module_dir/gexp.scm"<<EOF
  205. (use-modules (guix gexp))
  206. (gexp (mkdir (ungexp output)))
  207. EOF
  208. guix build --file="$module_dir/gexp.scm" -d
  209. guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv'
  210. # Using 'GUIX_BUILD_OPTIONS'.
  211. GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
  212. export GUIX_BUILD_OPTIONS
  213. guix build emacs
  214. GUIX_BUILD_OPTIONS="--something-completely-crazy"
  215. if guix build emacs;
  216. then false; else true; fi