cpio.scm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 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-cpio)
  19. #:use-module (guix cpio)
  20. #:use-module (guix tests)
  21. #:use-module ((guix build utils) #:select (which))
  22. #:use-module ((guix utils) #:select (call-with-temporary-output-file))
  23. #:use-module (ice-9 match)
  24. #:use-module (ice-9 popen)
  25. #:use-module (rnrs io ports)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (srfi srfi-26)
  28. #:use-module (srfi srfi-64))
  29. (define %cpio-program
  30. (which "cpio"))
  31. (test-begin "cpio")
  32. (test-assert "file->cpio-header + write-cpio-header + read-cpio-header"
  33. (let* ((file (search-path %load-path "guix.scm"))
  34. (header (file->cpio-header file)))
  35. (call-with-values
  36. (lambda ()
  37. (open-bytevector-output-port))
  38. (lambda (port get-bv)
  39. (write-cpio-header header port)
  40. (let ((port (open-bytevector-input-port (get-bv))))
  41. (equal? header (read-cpio-header port)))))))
  42. (unless %cpio-program (test-skip 1))
  43. (test-assert "bit-identical to GNU cpio's output"
  44. (call-with-temporary-output-file
  45. (lambda (link _)
  46. (delete-file link)
  47. (symlink "chbouib" link)
  48. (let ((files (cons* "/"
  49. (canonicalize-path
  50. (dirname (search-path %load-path "guix.scm")))
  51. link
  52. (map (compose canonicalize-path
  53. (cut search-path %load-path <>))
  54. '("guix.scm" "guix/build/syscalls.scm"
  55. "guix/packages.scm")))))
  56. (call-with-temporary-output-file
  57. (lambda (ref-file _)
  58. (let ((pipe (open-pipe* OPEN_WRITE %cpio-program "-o" "-O" ref-file
  59. "-H" "newc" "--null")))
  60. (for-each (lambda (file)
  61. (format pipe "~a\0" file))
  62. files)
  63. (and (zero? (close-pipe pipe))
  64. (call-with-temporary-output-file
  65. (lambda (file port)
  66. (write-cpio-archive files port)
  67. (close-port port)
  68. (or (file=? ref-file file)
  69. (throw 'cpio-archives-differ files
  70. ref-file file
  71. (stat:size (stat ref-file))
  72. (stat:size (stat file))))))))))))))
  73. (test-end "cpio")