disarchive-manifest.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 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. ;;; This file returns a manifest that builds a directory containing Disarchive
  19. ;;; metadata for all the tarballs packages refer to.
  20. (use-modules (srfi srfi-1) (ice-9 match)
  21. (guix packages) (guix gexp) (guix profiles)
  22. (guix base16)
  23. (gnu packages))
  24. (include "source-manifest.scm")
  25. (define (tarball-origin? origin)
  26. (match (origin-actual-file-name origin)
  27. (#f #f)
  28. ((? string? file)
  29. ;; As of version 0.2.1, Disarchive can only deal with raw tarballs and
  30. ;; gzip-compressed tarballs.
  31. (and (origin-hash origin)
  32. (or (string-suffix? ".tar.gz" file)
  33. (string-suffix? ".tgz" file)
  34. (string-suffix? ".tar" file))))))
  35. (define (origin->disarchive origin)
  36. "Return a directory containing Disarchive metadata for ORIGIN, a tarball, or
  37. an empty directory if ORIGIN could not be disassembled."
  38. (define file-name
  39. (let ((hash (origin-hash origin)))
  40. (string-append (symbol->string (content-hash-algorithm hash))
  41. "/"
  42. (bytevector->base16-string
  43. (content-hash-value hash)))))
  44. (define disarchive
  45. (specification->package "disarchive"))
  46. (define build
  47. (with-imported-modules '((guix build utils))
  48. #~(begin
  49. (use-modules (guix build utils)
  50. (srfi srfi-34))
  51. (define tarball
  52. #+(upstream-origin origin))
  53. (define file-name
  54. (string-append #$output "/" #$file-name))
  55. (define profile
  56. #+(profile (content (packages->manifest (list disarchive)))))
  57. (mkdir-p (dirname file-name))
  58. (setenv "PATH" (string-append profile "/bin"))
  59. (setenv "GUILE_LOAD_PATH"
  60. (string-append profile "/share/guile/site/"
  61. (effective-version)))
  62. (setenv "GUILE_LOAD_COMPILED_PATH"
  63. (string-append profile "/lib/guile/" (effective-version)
  64. "/site-ccache"))
  65. (guard (c ((invoke-error? c)
  66. ;; Sometimes Disarchive fails with "could not find Gzip
  67. ;; compressor". When that happens, produce an empty
  68. ;; directory instead of failing.
  69. (report-invoke-error c)
  70. (delete-file file-name)))
  71. (with-output-to-file file-name
  72. (lambda ()
  73. ;; Disarchive records the tarball name in its output. Thus,
  74. ;; strip the hash from TARBALL.
  75. (let ((short-name (strip-store-file-name tarball)))
  76. (symlink tarball short-name)
  77. (invoke "disarchive" "disassemble" short-name))))))))
  78. (computed-file (match (origin-actual-file-name origin)
  79. ((? string? str) (string-append str ".dis"))
  80. (#f "anonymous-tarball.dis"))
  81. build))
  82. (define (disarchive-collection origins)
  83. "Return a directory containing all the Disarchive metadata for ORIGINS."
  84. (directory-union "disarchive-collection"
  85. (filter-map (lambda (origin)
  86. (and (tarball-origin? origin)
  87. (origin->disarchive origin)))
  88. origins)
  89. #:copy? #t))
  90. ;; The manifest containing Disarchive data.
  91. (let ((origins (all-origins)))
  92. (manifest
  93. (list (manifest-entry
  94. (name "disarchive-collection")
  95. (version (length origins))
  96. (item (disarchive-collection origins))))))