union.scm 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2015, 2017 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. (define-module (test-union)
  19. #:use-module (guix tests)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix derivations)
  23. #:use-module (guix packages)
  24. #:use-module (guix build union)
  25. #:use-module ((guix build utils)
  26. #:select (with-directory-excursion directory-exists?))
  27. #:use-module (gnu packages bootstrap)
  28. #:use-module (srfi srfi-1)
  29. #:use-module (srfi srfi-64)
  30. #:use-module (rnrs io ports)
  31. #:use-module (ice-9 match))
  32. ;; Exercise the (guix build union) module.
  33. (define %store
  34. (open-connection-for-tests))
  35. (test-begin "union")
  36. (test-assert "union-build with symlink to directory"
  37. ;; http://bugs.gnu.org/17083
  38. ;; Here both ONE and TWO provide an element called 'foo', but in ONE it's a
  39. ;; directory whereas in TWO it's a symlink to a directory.
  40. (let* ((one (build-expression->derivation
  41. %store "one"
  42. '(begin
  43. (use-modules (guix build utils) (srfi srfi-26))
  44. (let ((foo (string-append %output "/foo")))
  45. (mkdir-p foo)
  46. (call-with-output-file (string-append foo "/one")
  47. (cut display "one" <>))))
  48. #:modules '((guix build utils))))
  49. (two (build-expression->derivation
  50. %store "two"
  51. '(begin
  52. (use-modules (guix build utils) (srfi srfi-26))
  53. (let ((foo (string-append %output "/foo"))
  54. (bar (string-append %output "/bar")))
  55. (mkdir-p bar)
  56. (call-with-output-file (string-append bar "/two")
  57. (cut display "two" <>))
  58. (symlink "bar" foo)))
  59. #:modules '((guix build utils))))
  60. (builder '(begin
  61. (use-modules (guix build union))
  62. (union-build (assoc-ref %outputs "out")
  63. (list (assoc-ref %build-inputs "one")
  64. (assoc-ref %build-inputs "two")))))
  65. (drv
  66. (build-expression->derivation %store "union-collision-symlink"
  67. builder
  68. #:inputs `(("one" ,one) ("two" ,two))
  69. #:modules '((guix build union)))))
  70. (and (build-derivations %store (list drv))
  71. (with-directory-excursion (pk (derivation->output-path drv))
  72. (and (string=? "one"
  73. (call-with-input-file "foo/one" get-string-all))
  74. (string=? "two"
  75. (call-with-input-file "foo/two" get-string-all))
  76. (string=? "two"
  77. (call-with-input-file "bar/two" get-string-all))
  78. (not (file-exists? "bar/one")))))))
  79. (test-skip (if (and %store (network-reachable?))
  80. 0
  81. 1))
  82. (test-assert "union-build"
  83. (let* ((inputs (map (match-lambda
  84. ((name package)
  85. `(,name ,(package-derivation %store package))))
  86. ;; Purposefully leave duplicate entries.
  87. (append %bootstrap-inputs
  88. (take %bootstrap-inputs 3))))
  89. (builder `(begin
  90. (use-modules (guix build union))
  91. (union-build (assoc-ref %outputs "out")
  92. (map cdr %build-inputs))))
  93. (drv
  94. (build-expression->derivation %store "union-test"
  95. builder
  96. #:inputs inputs
  97. #:modules '((guix build union)))))
  98. (and (build-derivations %store (list (pk 'drv drv)))
  99. (with-directory-excursion (derivation->output-path drv)
  100. (and (file-exists? "bin/touch")
  101. (file-exists? "bin/gcc")
  102. (file-exists? "bin/ld")
  103. (file-exists? "lib/libc.so")
  104. (directory-exists? "lib/gcc")
  105. (file-exists? "include/unistd.h")
  106. ;; The 'include/c++' sub-directory is only found in
  107. ;; gcc-bootstrap, so it should be unified in a
  108. ;; straightforward way, without traversing it.
  109. (eq? 'symlink (stat:type (lstat "include/c++")))
  110. ;; Conversely, several inputs have a 'bin' sub-directory, so
  111. ;; unifying it requires traversing them all, and creating a
  112. ;; new 'bin' sub-directory in the profile.
  113. (eq? 'directory (stat:type (lstat "bin"))))))))
  114. (test-assert "union-build #:create-all-directories? #t"
  115. (let* ((build `(begin
  116. (use-modules (guix build union))
  117. (union-build (assoc-ref %outputs "out")
  118. (map cdr %build-inputs)
  119. #:create-all-directories? #t)))
  120. (input (package-derivation %store %bootstrap-guile))
  121. (drv (build-expression->derivation %store "union-test-all-dirs"
  122. build
  123. #:modules '((guix build union))
  124. #:inputs `(("g" ,input)))))
  125. (and (build-derivations %store (list drv))
  126. (with-directory-excursion (derivation->output-path drv)
  127. ;; Even though there's only one input to the union,
  128. ;; #:create-all-directories? #t must have created bin/ rather than
  129. ;; making it a symlink to Guile's bin/.
  130. (and (file-exists? "bin/guile")
  131. (file-is-directory? "bin")
  132. (eq? 'symlink (stat:type (lstat "bin/guile"))))))))
  133. (test-end)