1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012 Stefan Handschuh <handschuh.stefan@googlemail.com>
3 ;;; Copyright © 2015 Kai-Chung Yan <seamlikok@gmail.com>
4 ;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2017 Julien Lepiller <julien@lepiller.eu>
6 ;;; Copyright © 2017 Hartmut Goebel <h.goebel@crazy-compilers.com>
7 ;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
9 ;;; This file is part of GNU Guix.
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24 (define-module (gnu packages android)
25 #:use-module (guix packages)
26 #:use-module (guix git-download)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix build-system python)
29 #:use-module (guix build-system trivial)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (gnu packages)
32 #:use-module (gnu packages gnupg)
33 #:use-module (gnu packages python)
34 #:use-module (gnu packages ssh)
35 #:use-module (gnu packages version-control)
36 #:use-module (gnu packages tls))
38 ;; The Makefiles that we add are largely based on the Debian
39 ;; packages. They are licensed under GPL-2 and have copyright:
40 ;; 2012, Stefan Handschuh <handschuh.stefan@googlemail.com>
41 ;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
42 ;; Big thanks to them for laying the groundwork.
44 ;; The version tag is consistent between all repositories.
45 (define (android-platform-version) "7.1.2_r6")
47 (define (android-platform-system-core version)
51 (url "https://android.googlesource.com/platform/system/core")
52 (commit (string-append "android-" version))))
53 (file-name (string-append "android-platform-system-core-"
57 "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
62 (version (android-platform-version))
63 (source (android-platform-system-core version))
64 (build-system gnu-build-system)
67 #:make-flags '("CC=gcc")
69 (modify-phases %standard-phases
70 (add-after 'unpack 'enter-source
71 (lambda _ (chdir "liblog") #t))
72 (add-after 'enter-source 'create-Makefile
74 ;; No useful makefile is shipped, so we create one.
75 (with-output-to-file "Makefile"
80 "SOURCES = log_event_list.c log_event_write.c"
81 " logger_write.c config_write.c logger_name.c"
82 " logger_lock.c fake_log_device.c fake_writer.c"
85 "CFLAGS += -fvisibility=hidden -fPIC\n"
86 "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
87 ;; Keep these two in sync with "liblog/Android.bp".
88 " -DLIBLOG_LOG_TAG=1005"
89 " -DSNET_EVENT_LOG_TAG=1397638484\n"
90 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
93 " $(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"))
97 (lambda* (#:key outputs #:allow-other-keys)
98 (let* ((out (assoc-ref outputs "out"))
99 (lib (string-append out "/lib")))
100 (install-file "liblog.so.0" lib)
101 (with-directory-excursion lib
102 (symlink "liblog.so.0" "liblog.so"))
104 (home-page "https://developer.android.com/")
105 (synopsis "Logging library from the Android platform.")
106 (description "@code{liblog} represents an interface to the volatile Android
107 Logging system for NDK (Native) applications and libraries and contain
108 interfaces for either writing or reading logs. The log buffers are divided up
109 in Main, System, Radio and Events sub-logs.")
110 (license license:asl2.0)))
115 (version (android-platform-version))
117 (inherit (android-platform-system-core version))
119 (search-patches "libbase-use-own-logging.patch"
120 "libbase-fix-includes.patch"))))
121 (build-system gnu-build-system)
123 `(#:tests? #f ; TODO.
125 (modify-phases %standard-phases
126 (add-after 'unpack 'enter-source
127 (lambda _ (chdir "base") #t))
128 (add-after 'enter-source 'create-Makefile
130 ;; No useful makefile is shipped, so we create one.
131 (with-output-to-file "Makefile"
136 "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
137 " stringprintf.cpp strings.cpp errors_unix.cpp\n"
139 "CXXFLAGS += -std=gnu++11 -fPIC\n"
140 "CPPFLAGS += -Iinclude -I../include\n"
141 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
144 "build: $(SOURCES)\n"
145 " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
150 (lambda* (#:key outputs #:allow-other-keys)
151 (let* ((out (assoc-ref outputs "out"))
152 (lib (string-append out "/lib")))
153 (install-file "libbase.so.0" lib)
154 (with-directory-excursion lib
155 (symlink "libbase.so.0" "libbase.so"))
156 (copy-recursively "include" out)
158 (inputs `(("liblog" ,liblog)))
159 (home-page "https://developer.android.com/")
160 (synopsis "Android platform base library")
161 (description "@code{libbase} is a library in common use by the
162 various Android core host applications.")
163 (license license:asl2.0)))
168 (version (android-platform-version))
169 (source (android-platform-system-core version))
170 (build-system gnu-build-system)
172 `(#:tests? #f ; TODO.
174 (modify-phases %standard-phases
175 (add-after 'unpack 'enter-source
176 (lambda _ (chdir "libcutils") #t))
177 (add-after 'enter-source 'create-Makefile
179 ;; No useful makefile is shipped, so we create one.
180 (with-output-to-file "Makefile"
185 "SOURCES = load_file.o socket_local_client_unix.o"
186 " socket_loopback_client_unix.o socket_network_client_unix.o"
187 " socket_loopback_server_unix.o socket_local_server_unix.o"
188 " sockets_unix.o socket_inaddr_any_server_unix.o"
193 "CXXFLAGS += -std=gnu++11 -fPIC\n"
194 "CPPFLAGS += -Iinclude -I../include\n"
195 "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
197 "build: $(SOURCES)\n"
198 " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
203 (lambda* (#:key outputs #:allow-other-keys)
204 (let* ((out (assoc-ref outputs "out"))
205 (lib (string-append out "/lib")))
206 (install-file "libcutils.so.0" lib)
207 (with-directory-excursion lib
208 (symlink "libcutils.so.0" "libcutils.so"))
210 (home-page "https://developer.android.com/")
211 (synopsis "Android platform c utils library")
212 (description "@code{libcutils} is a library in common use by the
213 various Android core host applications.")
214 (license license:asl2.0)))
219 (version (android-platform-version))
221 (inherit (android-platform-system-core version))
223 (search-patches "libbase-use-own-logging.patch"
224 "libbase-fix-includes.patch"))))
225 (build-system gnu-build-system)
228 (modify-phases %standard-phases
229 (add-after 'unpack 'enter-source
230 (lambda _ (chdir "adb") #t))
231 (add-before 'build 'fix-clang
233 ;; adb_client.h contains _Nonnull and _Nullable attributes, that
234 ;; are not understood by gcc.
235 (substitute* "adb_client.h"
239 (add-before 'build 'fix-main
241 ;; main.cpp used to be adb_main.cpp in the current directory
242 ;; rather than in its own subdirectory, but it was not fixed.
243 ;; This leads to some header files not being found anymore.
244 (copy-file "client/main.cpp" "adb_main.cpp")
246 (add-after 'enter-source 'create-Makefile
247 (lambda* (#:key outputs #:allow-other-keys)
248 ;; No useful makefile is shipped, so we create one.
249 (with-output-to-file "Makefile"
253 ;; Common for all components.
254 "CXXFLAGS += -std=gnu++14 -fpermissive\n"
255 "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
256 "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
257 "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
260 "LIBADB_SOURCES = adb.cpp adb_auth.cpp adb_io.cpp "
261 "adb_listeners.cpp adb_trace.cpp adb_utils.cpp fdevent.cpp "
262 "sockets.cpp transport.cpp transport_local.cpp transport_usb.cpp "
263 "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
264 "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
265 "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
267 "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
268 "-lcrypto -lpthread -lbase\n"
271 "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
272 "adb_client.cpp file_sync_client.cpp\n"
273 "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
275 "build: libadb $(ADB_SOURCES)\n"
276 " $(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
277 "$(ADB_LDFLAGS) $(LDFLAGS)\n"
279 "libadb: $(LIBADB_SOURCES)\n"
280 " $(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
281 "$(LIBADB_LDFLAGS)\n"
282 " ln -sv libadb.so.0 libadb.so\n"))
286 (lambda* (#:key outputs #:allow-other-keys)
287 (let* ((out (assoc-ref outputs "out"))
288 (lib (string-append out "/lib"))
289 (bin (string-append out "/bin")))
290 (install-file "libadb.so.0" lib)
291 (install-file "adb" bin)
292 (with-directory-excursion lib
293 (symlink "libadb.so.0" "libadb.so"))
295 ;; Test suite must be run with attached devices
298 `(("libbase" ,libbase)
299 ("libcutils" ,libcutils)
300 ("openssl" ,openssl)))
301 (home-page "https://developer.android.com/studio/command-line/adb.html")
302 (synopsis "Android Debug Bridge")
304 "@command{adb} is a versatile command line tool that lets you communicate
305 with an emulator instance or connected Android device. It facilitates a variety
306 of device actions, such as installing and debugging apps, and it provides access
307 to a Unix shell that can run commands on the connected device or emulator.")
308 (license license:asl2.0)))
310 (define-public android-udev-rules
312 (name "android-udev-rules")
318 (url "https://github.com/M0Rf30/android-udev-rules")
320 (file-name (string-append name "-" version "-checkout"))
322 (base32 "0vic40n3si0dxag3dyc3hi3pn7cjpm5q378x8v2ys19n3iz9fp1g"))))
323 (build-system trivial-build-system)
324 (native-inputs `(("source" ,source)))
326 '(#:modules ((guix build utils))
329 (use-modules (guix build utils))
330 (let ((source (assoc-ref %build-inputs "source")))
331 (install-file (string-append source "/51-android.rules")
332 (string-append %output "/lib/udev/rules.d"))))))
333 (home-page "https://github.com/M0Rf30/android-udev-rules")
334 (synopsis "udev rules for Android devices")
335 (description "Provides a set of udev rules to allow using Android devices
336 with tools such as @command{adb} and @command{fastboot} without root
337 privileges. This package is intended to be added as a rule to the
338 @code{udev-service-type} in your @code{operating-system} configuration.
339 Additionally, an @code{adbusers} group must be defined and your user added to
342 @emph{Simply installing this package will not have any effect.} It is meant
343 to be passed to the @code{udev} service.")
344 (license license:gpl3+)))
346 (define-public git-repo
354 (url "https://gerrit.googlesource.com/git-repo")
355 (commit (string-append "v" version))))
356 (file-name (string-append "git-repo-" version "-checkout"))
358 (base32 "0qp7jqhblv7xblfgpcq4n18dyjdv8shz7r60c3vnjxx2fngkj2jd"))))
359 (build-system python-build-system)
361 `(#:python ,python-2 ; code says: "Python 3 support is … experimental."
363 (modify-phases %standard-phases
364 (add-before 'build 'set-executable-paths
365 (lambda* (#:key inputs outputs #:allow-other-keys)
366 (let* ((out (assoc-ref outputs "out"))
367 (git (assoc-ref inputs "git"))
368 (gpg (assoc-ref inputs "gnupg"))
369 (ssh (assoc-ref inputs "ssh")))
370 (substitute* '("repo" "git_command.py")
372 (string-append "GIT = '" git "/bin/git' ")))
374 ((" cmd = \\['gpg',")
375 (string-append " cmd = ['" gpg "/bin/gpg',")))
376 (substitute* "git_config.py"
377 ((" command_base = \\['ssh',")
378 (string-append " command_base = ['" ssh "/bin/ssh',")))
380 (add-before 'build 'do-not-clone-this-source
381 (lambda* (#:key outputs #:allow-other-keys)
382 (let* ((out (assoc-ref outputs "out"))
383 (repo-dir (string-append out "/share/" ,name)))
385 (("^def _FindRepo\\(\\):.*")
388 '''Look for a repo installation, starting at the current directory.'''
389 # Use the installed version of git-repo.
390 repo_main = '~a/main.py'
393 while curdir != '/' and curdir != olddir:
394 dot_repo = os.path.join(curdir, repodir)
395 if os.path.isdir(dot_repo):
396 return (repo_main, dot_repo)
399 curdir = os.path.dirname(curdir)
402 # The remaining of this function is dead code. It was used to
403 # find a git-checked-out version in the local project.\n" repo-dir))
404 ;; Neither clone, check out, nor verify the git repository
405 (("(^\\s+)_Clone\\(.*\\)") "")
406 (("(^\\s+)_Checkout\\(.*\\)") "")
407 ((" rev = _Verify\\(.*\\)") " rev = None"))
409 (delete 'build) ; nothing to build
412 (zero? (system* "python" "-m" "nose"))))
414 (lambda* (#:key outputs #:allow-other-keys)
415 (let* ((out (assoc-ref outputs "out"))
416 (bin-dir (string-append out "/bin"))
417 (repo-dir (string-append out "/share/" ,name)))
420 (copy-recursively "." repo-dir)
421 (delete-file-recursively (string-append repo-dir "/tests"))
422 (symlink (string-append repo-dir "/repo")
423 (string-append bin-dir "/repo"))
426 ;; TODO: Add git-remote-persistent-https once it is available in guix
431 `(("nose" ,python2-nose)))
432 (home-page "https://code.google.com/p/git-repo/")
433 (synopsis "Helps to manage many Git repositories.")
434 (description "Repo is a tool built on top of Git. Repo helps manage many
435 Git repositories, does the uploads to revision control systems, and automates
436 parts of the development workflow. Repo is not meant to replace Git, only to
437 make it easier to work with Git. The repo command is an executable Python
438 script that you can put anywhere in your path.")
439 (license license:asl2.0)))