android-repo-download.scm 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 (srfi srfi-1)
  32. #:export (android-repo-reference
  33. android-repo-reference?
  34. android-repo-reference-manifest-url
  35. android-repo-reference-revision
  36. android-repo-fetch
  37. android-repo-version
  38. android-repo-file-name))
  39. ;;; Commentary:
  40. ;;;
  41. ;;; An <origin> method that fetches a specific commit from an Android repo
  42. ;;; repository.
  43. ;;; The repository's manifest (URL and revision) can be specified with a
  44. ;;; <android-repo-reference> object.
  45. ;;;
  46. ;;; Code:
  47. (define-record-type* <android-repo-reference>
  48. android-repo-reference make-android-repo-reference
  49. android-repo-reference?
  50. (manifest-url android-repo-reference-manifest-url)
  51. (manifest-revision android-repo-reference-manifest-revision))
  52. (define (git-repo-package)
  53. "Return the default git-repo package."
  54. (let ((distro (resolve-interface '(gnu packages android))))
  55. (module-ref distro 'git-repo)))
  56. (define* (android-repo-fetch ref hash-algo hash
  57. #:optional name
  58. #:key (system (%current-system))
  59. (guile (default-guile))
  60. (git-repo (git-repo-package)))
  61. "Return a fixed-output derivation that fetches REF, an
  62. <android-repo-reference> object. The output is expected to have recursive
  63. hash HASH of type HASH-ALGO (a symbol). Use NAME as the file name, or a
  64. generic name if unset."
  65. ;; TODO: Remove.
  66. (define inputs
  67. (standard-packages))
  68. (define zlib
  69. (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
  70. (define guile-json
  71. (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4))
  72. (define guile-lzlib
  73. (module-ref (resolve-interface '(gnu packages guile)) 'guile-lzlib))
  74. (define gnutls
  75. (module-ref (resolve-interface '(gnu packages tls)) 'guile-gnutls))
  76. (define config.scm
  77. (scheme-file "config.scm"
  78. #~(begin
  79. (define-module (guix config)
  80. #:export (%libz))
  81. (define %libz
  82. #+(file-append zlib "/lib/libz")))))
  83. (define modules
  84. (cons `((guix config) => ,config.scm)
  85. (delete '(guix config)
  86. (source-module-closure '((guix build android-repo)
  87. (guix build utils)
  88. (guix build download-nar))))))
  89. (define build
  90. (with-imported-modules modules
  91. (with-extensions (list gnutls guile-json ;for (guix swh)
  92. guile-lzlib)
  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"))