android-repo-download.scm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 gnutls
  74. (module-ref (resolve-interface '(gnu packages tls)) 'gnutls))
  75. (define config.scm
  76. (scheme-file "config.scm"
  77. #~(begin
  78. (define-module (guix config)
  79. #:export (%libz))
  80. (define %libz
  81. #+(file-append zlib "/lib/libz")))))
  82. (define modules
  83. (cons `((guix config) => ,config.scm)
  84. (delete '(guix config)
  85. (source-module-closure '((guix build android-repo)
  86. (guix build utils)
  87. (guix build download-nar))))))
  88. (define build
  89. (with-imported-modules modules
  90. (with-extensions (list gnutls)
  91. #~(begin
  92. (use-modules (guix build android-repo)
  93. (guix build utils)
  94. (guix build download-nar)
  95. (ice-9 match))
  96. ;; The 'git submodule' commands expects Coreutils, sed,
  97. ;; grep, etc. to be in $PATH.
  98. (set-path-environment-variable "PATH" '("bin")
  99. (match '#+inputs
  100. (((names dirs outputs ...) ...)
  101. dirs)))
  102. (setvbuf (current-output-port) 'line)
  103. (setvbuf (current-error-port) 'line)
  104. (or (android-repo-fetch (getenv "android-repo manifest-url")
  105. (getenv "android-repo manifest-revision")
  106. #$output
  107. #:git-repo-command
  108. (string-append #+git-repo "/bin/repo"))
  109. (download-nar #$output))))))
  110. (mlet %store-monad ((guile (package->derivation guile system)))
  111. (gexp->derivation (or name "android-repo-checkout") build
  112. ;; Use environment variables and a fixed script name so
  113. ;; there's only one script in store for all the
  114. ;; downloads.
  115. #:script-name "android-repo-download"
  116. #:env-vars
  117. `(("android-repo manifest-url" .
  118. ,(android-repo-reference-manifest-url ref))
  119. ("android-repo manifest-revision" .
  120. ,(android-repo-reference-manifest-revision ref)))
  121. #:leaked-env-vars '("http_proxy" "https_proxy"
  122. "LC_ALL" "LC_MESSAGES" "LANG"
  123. "COLUMNS")
  124. #:system system
  125. #:local-build? #t ;don't offload repo cloning
  126. #:hash-algo hash-algo
  127. #:hash hash
  128. #:recursive? #t
  129. #:guile-for-build guile)))
  130. (define (android-repo-version version revision)
  131. "Return the version string for packages using android-repo-download."
  132. (string-append version "-" (string-join (string-split revision #\/) "_")))
  133. (define (android-repo-file-name name version)
  134. "Return the file-name for packages using android-repo-download."
  135. (string-append name "-" version "-checkout"))