disarchive-manifest.scm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021-2022 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.4.0, Disarchive can only deal with raw tarballs,
  30. ;; gzip-compressed tarballs, and xz-compressed tarballs.
  31. (and (origin-hash origin)
  32. (or (string-suffix? ".tar.gz" file)
  33. (string-suffix? ".tgz" file)
  34. (string-suffix? ".tar.xz" file)
  35. (string-suffix? ".tar" file))))))
  36. (define (origin->disarchive origin)
  37. "Return a directory containing Disarchive metadata for ORIGIN, a tarball, or
  38. an empty directory if ORIGIN could not be disassembled."
  39. (define file-name
  40. (let ((hash (origin-hash origin)))
  41. (string-append (symbol->string (content-hash-algorithm hash))
  42. "/"
  43. (bytevector->base16-string
  44. (content-hash-value hash)))))
  45. (define disarchive
  46. (specification->package "disarchive"))
  47. (define build
  48. (with-imported-modules '((guix build utils))
  49. #~(begin
  50. (use-modules (guix build utils)
  51. (srfi srfi-34))
  52. (define tarball
  53. #+(upstream-origin origin))
  54. (define file-name
  55. (string-append #$output "/" #$file-name))
  56. (define profile
  57. #+(profile (content (packages->manifest (list disarchive)))))
  58. (mkdir-p (dirname file-name))
  59. (setenv "PATH" (string-append profile "/bin"))
  60. (setenv "GUILE_LOAD_PATH"
  61. (string-append profile "/share/guile/site/"
  62. (effective-version)))
  63. (setenv "GUILE_LOAD_COMPILED_PATH"
  64. (string-append profile "/lib/guile/" (effective-version)
  65. "/site-ccache"))
  66. (guard (c ((invoke-error? c)
  67. ;; Sometimes Disarchive fails with "could not find Gzip
  68. ;; compressor". When that happens, produce an empty
  69. ;; directory instead of failing.
  70. (report-invoke-error c)
  71. (delete-file file-name)))
  72. (with-output-to-file file-name
  73. (lambda ()
  74. ;; Disarchive records the tarball name in its output. Thus,
  75. ;; strip the hash from TARBALL.
  76. (let ((short-name (strip-store-file-name tarball)))
  77. (symlink tarball short-name)
  78. (invoke "disarchive" "disassemble" short-name))))))))
  79. (computed-file (match (origin-actual-file-name origin)
  80. ((? string? str) (string-append str ".dis"))
  81. (#f "anonymous-tarball.dis"))
  82. build))
  83. (define (disarchive-collection origins)
  84. "Return a directory containing all the Disarchive metadata for ORIGINS."
  85. (directory-union "disarchive-collection"
  86. (filter-map (lambda (origin)
  87. (and (tarball-origin? origin)
  88. ;; Dismiss origins with (sha256 #f) such
  89. ;; as that of IceCat.
  90. (and=> (origin-hash origin)
  91. content-hash-value)
  92. ;; FIXME: Exclude the Chromium tarball
  93. ;; because it's huge and "disarchive
  94. ;; disassemble" exceeds the max-silent
  95. ;; timeout.
  96. (not (string-prefix?
  97. "chromium-"
  98. (origin-actual-file-name origin)))
  99. (origin->disarchive origin)))
  100. origins)
  101. #:copy? #t))
  102. ;; The manifest containing Disarchive data.
  103. (let ((origins (all-origins)))
  104. (manifest
  105. (list (manifest-entry
  106. (name "disarchive-collection")
  107. (version (number->string (length origins)))
  108. (item (disarchive-collection origins))))))