summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Milosavljevic <dannym@scratchpost.org>2020-07-30 17:00:45 +0200
committerDanny Milosavljevic <dannym@scratchpost.org>2020-09-02 13:51:38 +0200
commit3feb846420f24ef1c8b3fe310d293c7a2c91e1d4 (patch)
tree69ba7726726bb6f88c160385c9b81557362570ef
parentf30e739395fecf90d7b4c0f8b36e994c12a319dd (diff)
Add (guix android-repo-download).
* guix/build/android-repo.scm: New file. * guix/android-repo-download.scm: New file. * Makefile.am (MODULES): Add them.
-rw-r--r--Makefile.am2
-rw-r--r--guix/android-repo-download.scm160
-rw-r--r--guix/build/android-repo.scm74
3 files changed, 236 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 063556c7acf..49fe57a0956 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -80,6 +80,7 @@ MODULES = \
80 guix/modules.scm \ 80 guix/modules.scm \
81 guix/download.scm \ 81 guix/download.scm \
82 guix/discovery.scm \ 82 guix/discovery.scm \
83 guix/android-repo-download.scm \
83 guix/bzr-download.scm \ 84 guix/bzr-download.scm \
84 guix/git-download.scm \ 85 guix/git-download.scm \
85 guix/hg-download.scm \ 86 guix/hg-download.scm \
@@ -170,6 +171,7 @@ MODULES = \
170 guix/build/minify-build-system.scm \ 171 guix/build/minify-build-system.scm \
171 guix/build/font-build-system.scm \ 172 guix/build/font-build-system.scm \
172 guix/build/go-build-system.scm \ 173 guix/build/go-build-system.scm \
174 guix/build/android-repo.scm \
173 guix/build/asdf-build-system.scm \ 175 guix/build/asdf-build-system.scm \
174 guix/build/bzr.scm \ 176 guix/build/bzr.scm \
175 guix/build/copy-build-system.scm \ 177 guix/build/copy-build-system.scm \
diff --git a/guix/android-repo-download.scm b/guix/android-repo-download.scm
new file mode 100644
index 00000000000..722e885ec9e
--- /dev/null
+++ b/guix/android-repo-download.scm
@@ -0,0 +1,160 @@
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
diff --git a/guix/build/android-repo.scm b/guix/build/android-repo.scm
new file mode 100644
index 00000000000..cba50270ea3
--- /dev/null
+++ b/guix/build/android-repo.scm
@@ -0,0 +1,74 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2016, 2019 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (guix build android-repo)
21 #:use-module (guix build utils)
22 #:use-module (srfi srfi-34)
23 #:use-module (ice-9 format)
24 #:export (android-repo-fetch))
25
26;;; Commentary:
27;;;
28;;; This is the build-side support code of (guix android-repo-download).
29;;; It allows a multirepository managed by the git-repo tool to be cloned and
30;;; checked out at a specific revision.
31;;;
32;;; Code:
33
34(define* (android-repo-fetch manifest-url manifest-revision directory
35 #:key (git-repo-command "git-repo"))
36 "Fetch packages according to the manifest at MANIFEST-URL with
37MANIFEST-REVISION. MANIFEST-REVISION must be either a revision
38or a branch. Return #t on success, #f otherwise."
39
40 ;; Disable TLS certificate verification. The hash of the checkout is known
41 ;; in advance anyway.
42 (setenv "GIT_SSL_NO_VERIFY" "true")
43
44 (mkdir-p directory)
45
46 (guard (c ((invoke-error? c)
47 (format (current-error-port)
48 "android-repo-fetch: '~a~{ ~a~}' failed with exit code ~a~%"
49 (invoke-error-program c)
50 (invoke-error-arguments c)
51 (or (invoke-error-exit-status c) ;XXX: not quite accurate
52 (invoke-error-stop-signal c)
53 (invoke-error-term-signal c)))
54 (delete-file-recursively directory)
55 #f))
56 (with-directory-excursion directory
57 (invoke git-repo-command "init" "-u" manifest-url "-b" manifest-revision
58 "--depth=1")
59 (invoke git-repo-command "sync" "-c" "--fail-fast" "-v" "-j" "3")
60
61 ;; Delete vendor/**/.git, system/**/.git, toolchain/**/.git,
62 ;; .repo/**/.git etc since they contain timestamps.
63 (for-each delete-file-recursively
64 (find-files "." "^\\.git$" #:directories? #t))
65
66 ;; Delete git state directories since they contain timestamps.
67 (for-each delete-file-recursively
68 (find-files ".repo" "^.*\\.git$" #:directories? #t))
69
70 ;; This file contains timestamps.
71 (delete-file ".repo/.repo_fetchtimes.json")
72 #t)))
73
74;;; android-repo.scm ends here