Commit | Line | Data |
---|---|---|
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 | |
72 | hash HASH of type HASH-ALGO (a symbol). Use NAME as the file name, or a | |
eb924a97 | 73 | generic 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 | ||
fd552740 MO |
81 | (define guile-json |
82 | (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4)) | |
83 | ||
3feb8464 DM |
84 | (define gnutls |
85 | (module-ref (resolve-interface '(gnu packages tls)) 'gnutls)) | |
86 | ||
87 | (define config.scm | |
88 | (scheme-file "config.scm" | |
89 | #~(begin | |
90 | (define-module (guix config) | |
91 | #:export (%libz)) | |
92 | ||
93 | (define %libz | |
94 | #+(file-append zlib "/lib/libz"))))) | |
95 | ||
96 | (define modules | |
97 | (cons `((guix config) => ,config.scm) | |
98 | (delete '(guix config) | |
99 | (source-module-closure '((guix build android-repo) | |
100 | (guix build utils) | |
101 | (guix build download-nar)))))) | |
102 | ||
103 | (define build | |
104 | (with-imported-modules modules | |
fd552740 | 105 | (with-extensions (list gnutls guile-json) ;for (guix swh) |
3feb8464 DM |
106 | #~(begin |
107 | (use-modules (guix build android-repo) | |
108 | (guix build utils) | |
109 | (guix build download-nar) | |
110 | (ice-9 match)) | |
111 | ||
112 | ;; The 'git submodule' commands expects Coreutils, sed, | |
113 | ;; grep, etc. to be in $PATH. | |
114 | (set-path-environment-variable "PATH" '("bin") | |
115 | (match '#+inputs | |
116 | (((names dirs outputs ...) ...) | |
117 | dirs))) | |
118 | ||
119 | (setvbuf (current-output-port) 'line) | |
120 | (setvbuf (current-error-port) 'line) | |
121 | ||
122 | (or (android-repo-fetch (getenv "android-repo manifest-url") | |
123 | (getenv "android-repo manifest-revision") | |
124 | #$output | |
125 | #:git-repo-command | |
126 | (string-append #+git-repo "/bin/repo")) | |
127 | (download-nar #$output)))))) | |
128 | ||
129 | (mlet %store-monad ((guile (package->derivation guile system))) | |
130 | (gexp->derivation (or name "android-repo-checkout") build | |
131 | ||
132 | ;; Use environment variables and a fixed script name so | |
133 | ;; there's only one script in store for all the | |
134 | ;; downloads. | |
135 | #:script-name "android-repo-download" | |
136 | #:env-vars | |
137 | `(("android-repo manifest-url" . | |
138 | ,(android-repo-reference-manifest-url ref)) | |
139 | ("android-repo manifest-revision" . | |
140 | ,(android-repo-reference-manifest-revision ref))) | |
141 | #:leaked-env-vars '("http_proxy" "https_proxy" | |
142 | "LC_ALL" "LC_MESSAGES" "LANG" | |
143 | "COLUMNS") | |
144 | #:system system | |
145 | #:local-build? #t ;don't offload repo cloning | |
146 | #:hash-algo hash-algo | |
147 | #:hash hash | |
148 | #:recursive? #t | |
149 | #:guile-for-build guile))) | |
150 | ||
151 | (define (android-repo-version version revision) | |
152 | "Return the version string for packages using android-repo-download." | |
153 | (string-append version "-" (string-join (string-split revision #\/) "_"))) | |
154 | ||
155 | (define (android-repo-file-name name version) | |
156 | "Return the file-name for packages using android-repo-download." | |
157 | (string-append name "-" version "-checkout")) | |
158 | ||
159 | \f |