ssh: Fix progress bar crash when there are zero items to send.
[jackhill/guix/guix.git] / guix / android-repo-download.scm
CommitLineData
3feb8464
DM
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
23(define-module (guix android-repo-download)
24 #:use-module (guix gexp)
25 #:use-module (guix store)
26 #:use-module (guix monads)
27 #:use-module (guix records)
28 #:use-module (guix packages)
29 #:use-module (guix modules)
30 #:autoload (guix build-system gnu) (standard-packages)
31 #:use-module (git) ; FIXME Remove
32 #:use-module (ice-9 match)
33 #:use-module (ice-9 vlist)
34 #:use-module (srfi srfi-1)
35 #:use-module (srfi srfi-34)
36 #:use-module (srfi srfi-35)
37 #:export (android-repo-reference
38 android-repo-reference?
39 android-repo-reference-mainfest-url
40 android-repo-reference-revision
41
42 android-repo-fetch
43 android-repo-version
44 android-repo-file-name))
45
46;;; Commentary:
47;;;
48;;; An <origin> method that fetches a specific commit from an Android repo
49;;; repository.
50;;; The repository's manifest (URL and revision) can be specified with a
51;; <android-repo-reference> object.
52;;;
53;;; Code:
54
55(define-record-type* <android-repo-reference>
56 android-repo-reference make-android-repo-reference
57 android-repo-reference?
58 (manifest-url android-repo-reference-manifest-url)
59 (manifest-revision android-repo-reference-manifest-revision))
60
61(define (git-repo-package)
62 "Return the default git-repo package."
63 (let ((distro (resolve-interface '(gnu packages android))))
64 (module-ref distro 'git-repo)))
65
66(define* (android-repo-fetch ref hash-algo hash
67 #:optional name
68 #:key (system (%current-system))
69 (guile (default-guile))
70 (git-repo (git-repo-package)))
71 "Return a fixed-output derivation that fetches REF, an
72<android-repo-reference> object. The output is expected to have recursive
73hash HASH of type HASH-ALGO (a symbol). Use NAME as the file name, or a
74generic name if #f."
75 ;; TODO: Remove.
76 (define inputs
77 (standard-packages))
78
79 (define zlib
80 (module-ref (resolve-interface '(gnu packages compression)) 'zlib))
81
82 (define guile-json
83 (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-3))
84
85 (define gnutls
86 (module-ref (resolve-interface '(gnu packages tls)) 'gnutls))
87
88 (define config.scm
89 (scheme-file "config.scm"
90 #~(begin
91 (define-module (guix config)
92 #:export (%libz))
93
94 (define %libz
95 #+(file-append zlib "/lib/libz")))))
96
97 (define modules
98 (cons `((guix config) => ,config.scm)
99 (delete '(guix config)
100 (source-module-closure '((guix build android-repo)
101 (guix build utils)
102 (guix build download-nar))))))
103
104 (define build
105 (with-imported-modules modules
106 (with-extensions (list guile-json gnutls) ;for (guix swh)
107 #~(begin
108 (use-modules (guix build android-repo)
109 (guix build utils)
110 (guix build download-nar)
111 (ice-9 match))
112
113 ;; The 'git submodule' commands expects Coreutils, sed,
114 ;; grep, etc. to be in $PATH.
115 (set-path-environment-variable "PATH" '("bin")
116 (match '#+inputs
117 (((names dirs outputs ...) ...)
118 dirs)))
119
120 (setvbuf (current-output-port) 'line)
121 (setvbuf (current-error-port) 'line)
122
123 (or (android-repo-fetch (getenv "android-repo manifest-url")
124 (getenv "android-repo manifest-revision")
125 #$output
126 #:git-repo-command
127 (string-append #+git-repo "/bin/repo"))
128 (download-nar #$output))))))
129
130 (mlet %store-monad ((guile (package->derivation guile system)))
131 (gexp->derivation (or name "android-repo-checkout") build
132
133 ;; Use environment variables and a fixed script name so
134 ;; there's only one script in store for all the
135 ;; downloads.
136 #:script-name "android-repo-download"
137 #:env-vars
138 `(("android-repo manifest-url" .
139 ,(android-repo-reference-manifest-url ref))
140 ("android-repo manifest-revision" .
141 ,(android-repo-reference-manifest-revision ref)))
142 #:leaked-env-vars '("http_proxy" "https_proxy"
143 "LC_ALL" "LC_MESSAGES" "LANG"
144 "COLUMNS")
145 #:system system
146 #:local-build? #t ;don't offload repo cloning
147 #:hash-algo hash-algo
148 #:hash hash
149 #:recursive? #t
150 #:guile-for-build guile)))
151
152(define (android-repo-version version revision)
153 "Return the version string for packages using android-repo-download."
154 (string-append version "-" (string-join (string-split revision #\/) "_")))
155
156(define (android-repo-file-name name version)
157 "Return the file-name for packages using android-repo-download."
158 (string-append name "-" version "-checkout"))
159
160\f