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