android.scm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  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.
  15. ;;;
  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.
  20. ;;;
  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/>.
  23. (define-module (gnu packages android)
  24. #:use-module (guix packages)
  25. #:use-module (guix git-download)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (guix build-system python)
  28. #:use-module (guix build-system trivial)
  29. #:use-module ((guix licenses) #:prefix license:)
  30. #:use-module (gnu packages)
  31. #:use-module (gnu packages gnupg)
  32. #:use-module (gnu packages python)
  33. #:use-module (gnu packages ssh)
  34. #:use-module (gnu packages version-control)
  35. #:use-module (gnu packages tls))
  36. ;; The Makefiles that we add are largely based on the Debian
  37. ;; packages. They are licensed under GPL-2 and have copyright:
  38. ;; 2012, Stefan Handschuh <handschuh.stefan@googlemail.com>
  39. ;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
  40. ;; Big thanks to them for laying the groundwork.
  41. ;; The version tag is consistent between all repositories.
  42. (define (android-platform-version) "7.1.2_r6")
  43. (define (android-platform-system-core version)
  44. (origin
  45. (method git-fetch)
  46. (uri (git-reference
  47. (url "https://android.googlesource.com/platform/system/core")
  48. (commit (string-append "android-" version))))
  49. (file-name (string-append "android-platform-system-core-"
  50. version "-checkout"))
  51. (sha256
  52. (base32
  53. "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
  54. (define liblog
  55. (package
  56. (name "liblog")
  57. (version (android-platform-version))
  58. (source (android-platform-system-core version))
  59. (build-system gnu-build-system)
  60. (arguments
  61. `(#:tests? #f ; TODO.
  62. #:make-flags '("CC=gcc")
  63. #:phases
  64. (modify-phases %standard-phases
  65. (add-after 'unpack 'enter-source
  66. (lambda _ (chdir "liblog") #t))
  67. (add-after 'enter-source 'create-Makefile
  68. (lambda _
  69. ;; No useful makefile is shipped, so we create one.
  70. (with-output-to-file "Makefile"
  71. (lambda _
  72. (display
  73. (string-append
  74. "NAME = liblog\n"
  75. "SOURCES = log_event_list.c log_event_write.c"
  76. " logger_write.c config_write.c logger_name.c"
  77. " logger_lock.c fake_log_device.c fake_writer.c"
  78. " event_tag_map.c\n"
  79. "CFLAGS += -fvisibility=hidden -fPIC\n"
  80. "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
  81. ;; Keep these two in sync with "liblog/Android.bp".
  82. " -DLIBLOG_LOG_TAG=1005"
  83. " -DSNET_EVENT_LOG_TAG=1397638484\n"
  84. "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
  85. "build: $(SOURCES)\n"
  86. " $(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"))
  87. #t))))
  88. (delete 'configure)
  89. (replace 'install
  90. (lambda* (#:key outputs #:allow-other-keys)
  91. (let* ((out (assoc-ref outputs "out"))
  92. (lib (string-append out "/lib")))
  93. (install-file "liblog.so.0" lib)
  94. (with-directory-excursion lib
  95. (symlink "liblog.so.0" "liblog.so"))
  96. #t))))))
  97. (home-page "https://developer.android.com/")
  98. (synopsis "Logging library from the Android platform.")
  99. (description "@code{liblog} represents an interface to the volatile Android
  100. Logging system for NDK (Native) applications and libraries and contain
  101. interfaces for either writing or reading logs. The log buffers are divided up
  102. in Main, System, Radio and Events sub-logs.")
  103. (license license:asl2.0)))
  104. (define libbase
  105. (package
  106. (name "libbase")
  107. (version (android-platform-version))
  108. (source (origin
  109. (inherit (android-platform-system-core version))
  110. (patches
  111. (search-patches "libbase-use-own-logging.patch"
  112. "libbase-fix-includes.patch"))))
  113. (build-system gnu-build-system)
  114. (arguments
  115. `(#:tests? #f ; TODO.
  116. #:phases
  117. (modify-phases %standard-phases
  118. (add-after 'unpack 'enter-source
  119. (lambda _ (chdir "base") #t))
  120. (add-after 'enter-source 'create-Makefile
  121. (lambda _
  122. ;; No useful makefile is shipped, so we create one.
  123. (with-output-to-file "Makefile"
  124. (lambda _
  125. (display
  126. (string-append
  127. "NAME = libbase\n"
  128. "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
  129. " stringprintf.cpp strings.cpp errors_unix.cpp\n"
  130. "CXXFLAGS += -std=gnu++11 -fPIC\n"
  131. "CPPFLAGS += -Iinclude -I../include\n"
  132. "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
  133. " -L.. -llog\n"
  134. "build: $(SOURCES)\n"
  135. " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
  136. " $(LDFLAGS)\n"))
  137. #t))))
  138. (delete 'configure)
  139. (replace 'install
  140. (lambda* (#:key outputs #:allow-other-keys)
  141. (let* ((out (assoc-ref outputs "out"))
  142. (lib (string-append out "/lib")))
  143. (install-file "libbase.so.0" lib)
  144. (with-directory-excursion lib
  145. (symlink "libbase.so.0" "libbase.so"))
  146. (copy-recursively "include" out)
  147. #t))))))
  148. (inputs `(("liblog" ,liblog)))
  149. (home-page "https://developer.android.com/")
  150. (synopsis "Android platform base library")
  151. (description "@code{libbase} is a library in common use by the
  152. various Android core host applications.")
  153. (license license:asl2.0)))
  154. (define libcutils
  155. (package
  156. (name "libcutils")
  157. (version (android-platform-version))
  158. (source (android-platform-system-core version))
  159. (build-system gnu-build-system)
  160. (arguments
  161. `(#:tests? #f ; TODO.
  162. #:phases
  163. (modify-phases %standard-phases
  164. (add-after 'unpack 'enter-source
  165. (lambda _ (chdir "libcutils") #t))
  166. (add-after 'enter-source 'create-Makefile
  167. (lambda _
  168. ;; No useful makefile is shipped, so we create one.
  169. (with-output-to-file "Makefile"
  170. (lambda _
  171. (display
  172. (string-append
  173. "NAME = libcutils\n"
  174. "SOURCES = load_file.o socket_local_client_unix.o"
  175. " socket_loopback_client_unix.o socket_network_client_unix.o"
  176. " socket_loopback_server_unix.o socket_local_server_unix.o"
  177. " sockets_unix.o socket_inaddr_any_server_unix.o"
  178. " sockets.o\n"
  179. "CC = gcc\n"
  180. "CFLAGS += -fPIC\n"
  181. "CXXFLAGS += -std=gnu++11 -fPIC\n"
  182. "CPPFLAGS += -Iinclude -I../include\n"
  183. "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
  184. "build: $(SOURCES)\n"
  185. " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
  186. " $(LDFLAGS)\n"))
  187. #t))))
  188. (delete 'configure)
  189. (replace 'install
  190. (lambda* (#:key outputs #:allow-other-keys)
  191. (let* ((out (assoc-ref outputs "out"))
  192. (lib (string-append out "/lib")))
  193. (install-file "libcutils.so.0" lib)
  194. (with-directory-excursion lib
  195. (symlink "libcutils.so.0" "libcutils.so"))
  196. #t))))))
  197. (home-page "https://developer.android.com/")
  198. (synopsis "Android platform c utils library")
  199. (description "@code{libcutils} is a library in common use by the
  200. various Android core host applications.")
  201. (license license:asl2.0)))
  202. (define-public adb
  203. (package
  204. (name "adb")
  205. (version (android-platform-version))
  206. (source (origin
  207. (inherit (android-platform-system-core version))
  208. (patches
  209. (search-patches "libbase-use-own-logging.patch"
  210. "libbase-fix-includes.patch"))))
  211. (build-system gnu-build-system)
  212. (arguments
  213. `(#:phases
  214. (modify-phases %standard-phases
  215. (add-after 'unpack 'enter-source
  216. (lambda _ (chdir "adb") #t))
  217. (add-before 'build 'fix-clang
  218. (lambda _
  219. ;; adb_client.h contains _Nonnull and _Nullable attributes, that
  220. ;; are not understood by gcc.
  221. (substitute* "adb_client.h"
  222. (("_Nonnull") "")
  223. (("_Nullable") ""))
  224. #t))
  225. (add-before 'build 'fix-main
  226. (lambda _
  227. ;; main.cpp used to be adb_main.cpp in the current directory
  228. ;; rather than in its own subdirectory, but it was not fixed.
  229. ;; This leads to some header files not being found anymore.
  230. (copy-file "client/main.cpp" "adb_main.cpp")
  231. #t))
  232. (add-after 'enter-source 'create-Makefile
  233. (lambda* (#:key outputs #:allow-other-keys)
  234. ;; No useful makefile is shipped, so we create one.
  235. (with-output-to-file "Makefile"
  236. (lambda _
  237. (display
  238. (string-append
  239. ;; Common for all components.
  240. "CXXFLAGS += -std=gnu++14 -fpermissive\n"
  241. "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
  242. "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
  243. "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
  244. ;; Libadb specifics.
  245. "LIBADB_SOURCES = adb.cpp adb_auth.cpp adb_io.cpp "
  246. "adb_listeners.cpp adb_trace.cpp adb_utils.cpp fdevent.cpp "
  247. "sockets.cpp transport.cpp transport_local.cpp transport_usb.cpp "
  248. "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
  249. "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
  250. "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
  251. "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
  252. "-lcrypto -lpthread -lbase\n"
  253. ;; Adb specifics.
  254. "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
  255. "adb_client.cpp file_sync_client.cpp\n"
  256. "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
  257. "build: libadb $(ADB_SOURCES)\n"
  258. " $(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
  259. "$(ADB_LDFLAGS) $(LDFLAGS)\n"
  260. "libadb: $(LIBADB_SOURCES)\n"
  261. " $(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
  262. "$(LIBADB_LDFLAGS)\n"
  263. " ln -sv libadb.so.0 libadb.so\n"))
  264. #t))))
  265. (delete 'configure)
  266. (replace 'install
  267. (lambda* (#:key outputs #:allow-other-keys)
  268. (let* ((out (assoc-ref outputs "out"))
  269. (lib (string-append out "/lib"))
  270. (bin (string-append out "/bin")))
  271. (install-file "libadb.so.0" lib)
  272. (install-file "adb" bin)
  273. (with-directory-excursion lib
  274. (symlink "libadb.so.0" "libadb.so"))
  275. #t))))
  276. ;; Test suite must be run with attached devices
  277. #:tests? #f))
  278. (inputs
  279. `(("libbase" ,libbase)
  280. ("libcutils" ,libcutils)
  281. ("openssl" ,openssl)))
  282. (home-page "https://developer.android.com/studio/command-line/adb.html")
  283. (synopsis "Android Debug Bridge")
  284. (description
  285. "@command{adb} is a versatile command line tool that lets you communicate
  286. with an emulator instance or connected Android device. It facilitates a variety
  287. of device actions, such as installing and debugging apps, and it provides access
  288. to a Unix shell that can run commands on the connected device or emulator.")
  289. (license license:asl2.0)))
  290. (define-public android-udev-rules
  291. (package
  292. (name "android-udev-rules")
  293. (version "20170910")
  294. (source
  295. (origin
  296. (method git-fetch)
  297. (uri (git-reference
  298. (url "https://github.com/M0Rf30/android-udev-rules")
  299. (commit version)))
  300. (file-name (string-append name "-" version "-checkout"))
  301. (sha256
  302. (base32 "0vic40n3si0dxag3dyc3hi3pn7cjpm5q378x8v2ys19n3iz9fp1g"))))
  303. (build-system trivial-build-system)
  304. (native-inputs `(("source" ,source)))
  305. (arguments
  306. '(#:modules ((guix build utils))
  307. #:builder
  308. (begin
  309. (use-modules (guix build utils))
  310. (let ((source (assoc-ref %build-inputs "source")))
  311. (install-file (string-append source "/51-android.rules")
  312. (string-append %output "/lib/udev/rules.d"))))))
  313. (home-page "https://github.com/M0Rf30/android-udev-rules")
  314. (synopsis "udev rules for Android devices")
  315. (description "Provides a set of udev rules to allow using Android devices
  316. with tools such as @command{adb} and @command{fastboot} without root
  317. privileges. This package is intended to be added as a rule to the
  318. @code{udev-service-type} in your @code{operating-system} configuration.
  319. Additionally, an @code{adbusers} group must be defined and your user added to
  320. it.
  321. @emph{Simply installing this package will not have any effect.} It is meant
  322. to be passed to the @code{udev} service.")
  323. (license license:gpl3+)))
  324. (define-public git-repo
  325. (package
  326. (name "git-repo")
  327. (version "1.12.37")
  328. (source
  329. (origin
  330. (method git-fetch)
  331. (uri (git-reference
  332. (url "https://gerrit.googlesource.com/git-repo")
  333. (commit (string-append "v" version))))
  334. (file-name (string-append "git-repo-" version "-checkout"))
  335. (sha256
  336. (base32 "0qp7jqhblv7xblfgpcq4n18dyjdv8shz7r60c3vnjxx2fngkj2jd"))))
  337. (build-system python-build-system)
  338. (arguments
  339. `(#:python ,python-2 ; code says: "Python 3 support is … experimental."
  340. #:phases
  341. (modify-phases %standard-phases
  342. (add-before 'build 'set-executable-paths
  343. (lambda* (#:key inputs outputs #:allow-other-keys)
  344. (let* ((out (assoc-ref outputs "out"))
  345. (git (assoc-ref inputs "git"))
  346. (gpg (assoc-ref inputs "gnupg"))
  347. (ssh (assoc-ref inputs "ssh")))
  348. (substitute* '("repo" "git_command.py")
  349. (("^GIT = 'git' ")
  350. (string-append "GIT = '" git "/bin/git' ")))
  351. (substitute* "repo"
  352. ((" cmd = \\['gpg',")
  353. (string-append " cmd = ['" gpg "/bin/gpg',")))
  354. (substitute* "git_config.py"
  355. ((" command_base = \\['ssh',")
  356. (string-append " command_base = ['" ssh "/bin/ssh',")))
  357. #t)))
  358. (add-before 'build 'do-not-clone-this-source
  359. (lambda* (#:key outputs #:allow-other-keys)
  360. (let* ((out (assoc-ref outputs "out"))
  361. (repo-dir (string-append out "/share/" ,name)))
  362. (substitute* "repo"
  363. (("^def _FindRepo\\(\\):.*")
  364. (format #f "
  365. def _FindRepo():
  366. '''Look for a repo installation, starting at the current directory.'''
  367. # Use the installed version of git-repo.
  368. repo_main = '~a/main.py'
  369. curdir = os.getcwd()
  370. olddir = None
  371. while curdir != '/' and curdir != olddir:
  372. dot_repo = os.path.join(curdir, repodir)
  373. if os.path.isdir(dot_repo):
  374. return (repo_main, dot_repo)
  375. else:
  376. olddir = curdir
  377. curdir = os.path.dirname(curdir)
  378. return None, ''
  379. # The remaining of this function is dead code. It was used to
  380. # find a git-checked-out version in the local project.\n" repo-dir))
  381. ;; Neither clone, check out, nor verify the git repository
  382. (("(^\\s+)_Clone\\(.*\\)") "")
  383. (("(^\\s+)_Checkout\\(.*\\)") "")
  384. ((" rev = _Verify\\(.*\\)") " rev = None"))
  385. #t)))
  386. (delete 'build) ; nothing to build
  387. (replace 'check
  388. (lambda _
  389. (zero? (system* "python" "-m" "nose"))))
  390. (replace 'install
  391. (lambda* (#:key outputs #:allow-other-keys)
  392. (let* ((out (assoc-ref outputs "out"))
  393. (bin-dir (string-append out "/bin"))
  394. (repo-dir (string-append out "/share/" ,name)))
  395. (mkdir-p bin-dir)
  396. (mkdir-p repo-dir)
  397. (copy-recursively "." repo-dir)
  398. (delete-file-recursively (string-append repo-dir "/tests"))
  399. (symlink (string-append repo-dir "/repo")
  400. (string-append bin-dir "/repo"))
  401. #t))))))
  402. (inputs
  403. ;; TODO: Add git-remote-persistent-https once it is available in guix
  404. `(("git" ,git)
  405. ("gnupg" ,gnupg)
  406. ("ssh", openssh)))
  407. (native-inputs
  408. `(("nose" ,python2-nose)))
  409. (home-page "https://code.google.com/p/git-repo/")
  410. (synopsis "Helps to manage many Git repositories.")
  411. (description "Repo is a tool built on top of Git. Repo helps manage many
  412. Git repositories, does the uploads to revision control systems, and automates
  413. parts of the development workflow. Repo is not meant to replace Git, only to
  414. make it easier to work with Git. The repo command is an executable Python
  415. script that you can put anywhere in your path.")
  416. (license license:asl2.0)))