android-repo-download.scm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2017 Mathieu Lirzin <mthl@gnu.org>
  4. ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
  5. ;;; Copyright © 2020 Jakub Kądziołka <kuba@kadziolka.net>
  6. ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (guix android-repo-download)
  23. #:use-module (guix gexp)
  24. #:use-module (guix store)
  25. #:use-module (guix monads)
  26. #:use-module (guix records)
  27. #:use-module (guix packages)
  28. #:use-module (guix modules)
  29. #:autoload (guix build-system gnu) (standard-packages)
  30. #:use-module (ice-9 match)
  31. #:use-module (ice-9 vlist)
  32. #:use-module (srfi srfi-1)
  33. #:use-module (srfi srfi-34)
  34. #:use-module (srfi srfi-35)
  35. #:export (android-repo-reference
  36. android-repo-reference?
  37. android-repo-reference-manifest-url
  38. android-repo-reference-revision
  39. android-repo-fetch
  40. android-repo-version
  41. android-repo-file-name))
  42. ;;; Commentary:
  43. ;;;
  44. ;;; An <origin> method that fetches a specific commit from an Android repo
  45. ;;; repository.
  46. ;;; The repository's manifest (URL and revision) can be specified with a
  47. ;;; <android-repo-reference> object.
  48. ;;;
  49. ;;; Code:
  50. (define-record-type* <android-repo-reference>
  51. android-repo-reference make-android-repo-reference
  52. android-repo-reference?
  53. (manifest-url android-repo-reference-manifest-url)
  54. (manifest-revision android-repo-reference-manifest-revision))
  55. (define (git-repo-package)
  56. "Return the default git-repo package."
  57. (let ((distro (resolve-interface '(gnu packages android))))
  58. (module-ref distro 'git-repo)))
  59. (define* (android-repo-fetch ref hash-algo hash
  60. #:optional name
  61. #:key (system (%current-system))
  62. (guile (default-guile))
  63. (git-repo (git-repo-package)))
  64. "Return a fixed-output derivation that fetches REF, an
  65. <android-repo-reference> object. The output is expected to have recursive
  66. hash HASH of type HASH-ALGO (a symbol). Use NAME as the file name, or a
  67. generic name if unset."
  68. ;; TODO: Remove.
  69. (define inputs
  70. (standard-packages))
  71. (define zlib
  72. (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
  73. (define guile-json
  74. (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4))
  75. (define gnutls
  76. (module-ref (resolve-interface '(gnu packages tls)) 'gnutls))
  77. (define config.scm
  78. (scheme-file "config.scm"
  79. #~(begin
  80. (define-module (guix config)
  81. #:export (%libz))
  82. (define %libz
  83. #+(file-append zlib "/lib/libz")))))
  84. (define modules
  85. (cons `((guix config) => ,config.scm)
  86. (delete '(guix config)
  87. (source-module-closure '((guix build android-repo)
  88. (guix build utils)
  89. (guix build download-nar))))))
  90. (define build
  91. (with-imported-modules modules
  92. (with-extensions (list gnutls guile-json) ;for (guix swh)
  93. #~(begin
  94. (use-modules (guix build android-repo)
  95. (guix build utils)
  96. (guix build download-nar)
  97. (ice-9 match))
  98. ;; The 'git submodule' commands expects Coreutils, sed,
  99. ;; grep, etc. to be in $PATH.
  100. (set-path-environment-variable "PATH" '("bin")
  101. (match '#+inputs
  102. (((names dirs outputs ...) ...)
  103. dirs)))
  104. (setvbuf (current-output-port) 'line)
  105. (setvbuf (current-error-port) 'line)
  106. (or (android-repo-fetch (getenv "android-repo manifest-url")
  107. (getenv "android-repo manifest-revision")
  108. #$output
  109. #:git-repo-command
  110. (string-append #+git-repo "/bin/repo"))
  111. (download-nar #$output))))))
  112. (mlet %store-monad ((guile (package->derivation guile system)))
  113. (gexp->derivation (or name "android-repo-checkout") build
  114. ;; Use environment variables and a fixed script name so
  115. ;; there's only one script in store for all the
  116. ;; downloads.
  117. #:script-name "android-repo-download"
  118. #:env-vars
  119. `(("android-repo manifest-url" .
  120. ,(android-repo-reference-manifest-url ref))
  121. ("android-repo manifest-revision" .
  122. ,(android-repo-reference-manifest-revision ref)))
  123. #:leaked-env-vars '("http_proxy" "https_proxy"
  124. "LC_ALL" "LC_MESSAGES" "LANG"
  125. "COLUMNS")
  126. #:system system
  127. #:local-build? #t ;don't offload repo cloning
  128. #:hash-algo hash-algo
  129. #:hash hash
  130. #:recursive? #t
  131. #:guile-for-build guile)))
  132. (define (android-repo-version version revision)
  133. "Return the version string for packages using android-repo-download."
  134. (string-append version "-" (string-join (string-split revision #\/) "_")))
  135. (define (android-repo-file-name name version)
  136. "Return the file-name for packages using android-repo-download."
  137. (string-append name "-" version "-checkout"))