From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marius Bakke Subject: Re: [PATCH] Add adb Date: Sun, 11 Dec 2016 18:28:56 +0100 Message-ID: <87fuluml2f.fsf@kirby.i-did-not-set--mail-host-address--so-tickle-me> References: <20161211172643.0da9750f@lepiller.eu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cG7vs-0001lt-G6 for guix-devel@gnu.org; Sun, 11 Dec 2016 12:29:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cG7vp-0002G9-95 for guix-devel@gnu.org; Sun, 11 Dec 2016 12:29:04 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:34920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cG7vo-0002Fw-WB for guix-devel@gnu.org; Sun, 11 Dec 2016 12:29:01 -0500 In-Reply-To: <20161211172643.0da9750f@lepiller.eu> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Julien Lepiller , guix-devel@gnu.org --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain Julien Lepiller writes: > Hi, > > I wanted to use adb, so here is a patch to have it in the distro. It > works when ran as root, or if you add some udev rules to your os > configuration. > > An issue I can see with this package is that it is only a part of the > upstream repository, which in turn is only a part of a bigger build > system. Normally, you would download multiple repos and build them all > together to get an android image, and some android tools (including > adb). I don't think we want to build a full android image, so I wrote a > recipe for adb only. > > I took the recipe from archlinux, as well as the patch (android-tools > package: > https://git.archlinux.org/svntogit/community.git/tree/trunk?h=packages/android-tools, > see build.sh and fix-build.patch). They use clang, but our version isn't > able to build c++ source files (it cannot find includes such as > or ), so I fixed the source to remove clang dialect > in adb/adb_client.h so we can build the files using gcc. > > Archlinux also builds fastboot and mkbootimg. Should I build them along > with adb, or in a separate packages? Wow, go build system and adb in a single weekend, is it Christmas already :) I happen to have a work-in-progress adb expression as well, but creating liblog and libbase as standalone packages. Also creating Makefiles (based on the Debian approach) instead of calling g++ directly. Looking at the attached patch here, I think what's missing in my build is the string.h inclusions. We should join efforts and get this in ASAP! Attaching my patch here. I think having liblog and libbase as separate expressions is cleaner, but creating Makefiles may be unnecessary. WDYT? I also wonder if it's worth adding a snippet to each package source, so that the source derivations only contain the files relevant to each respective package for licensing reasons. --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAlhNjNkACgkQoqBt8qM6 VPoImwf+OsE1xq6irqapK2ljKqfLFwLpTa1uRYGnrPWZV/8DQ771/JkDAoct6J0g ZhknkuD+56N7Ju8LXV2J+qEEhOBHf2/G3kLxdetg2uubCFbyMIwl9/12bnTS8f9A 2W6GbDvu59aDx60yaF84HdY0Kjm6sVT1pc/ytSEe91RiaWcOC2Oqmp/04epTycRD PtFqkB1BhnAOCaXbmrtGPZH3roN7gXBDXBDcOr4XGks8zJOwLdQg25481dkqknN2 Y0yBzuaXuKDgAkWp+YyFEZjsTsx3QuNmUlAvQN8iCDix1PffPJ/iQ75+/n6g+9Vo YGraBB3SYSPaIyROfGyOXy2PibmSfw== =6td9 -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-gnu-Add-adb.patch Content-Transfer-Encoding: quoted-printable >From 28bfa5086ac048c40bfb9a44436ca977fbe5b018 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Thu, 17 Nov 2016 23:00:48 +0100 Subject: [PATCH] gnu: Add adb. * gnu/packages/android.scm: New file. * gnu/packages/patches/libbase-use-own-logging.patch: New file. * gnu/local.mk: Add them. --- gnu/local.mk | 1 + gnu/packages/android.scm | 238 +++++++++++++++++= ++++ gnu/packages/patches/libbase-use-own-logging.patch | 77 +++++++ 3 files changed, 316 insertions(+) create mode 100644 gnu/packages/android.scm create mode 100644 gnu/packages/patches/libbase-use-own-logging.patch diff --git a/gnu/local.mk b/gnu/local.mk index 98a7f65ca..c632b0790 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -657,6 +657,7 @@ dist_patch_DATA =3D \ %D%/packages/patches/libarchive-fix-symlink-check.patch \ %D%/packages/patches/libarchive-fix-filesystem-attacks.patch \ %D%/packages/patches/libarchive-safe_fprintf-buffer-overflow.patch \ + %D%/packages/patches/libbase-use-own-logging.patch \ %D%/packages/patches/libbonobo-activation-test-race.patch \ %D%/packages/patches/libcanberra-sound-theme-freedesktop.patch \ %D%/packages/patches/libcmis-fix-test-onedrive.patch \ diff --git a/gnu/packages/android.scm b/gnu/packages/android.scm new file mode 100644 index 000000000..38495d77d --- /dev/null +++ b/gnu/packages/android.scm @@ -0,0 +1,238 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2012 Stefan Handschuh +;;; Copyright =C2=A9 2015 Kai-Chung Yan +;;; Copyright =C2=A9 2016 Marius Bakke +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu packages android) + #:use-module (guix packages) + #:use-module (guix git-download) + #:use-module (guix build-system gnu) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (gnu packages) + #:use-module (gnu packages python) + #:use-module (gnu packages tls)) + +;; The Makefiles that we add are largely based on the Debian +;; packages. They are licensed under GPL-2 and have copyright: +;; 2012, Stefan Handschuh +;; 2015, Kai-Chung Yan +;; Big thanks to them for laying the groundwork. + +;; The version tag is consistent between all repositories. +(define (android-platform-version) "7.1.1_r4") + +;; Note: Use git checkouts since the tarballs are generated on +;; download with current timestamps causing the hash to change. +(define (android-platform-build version) + (origin + (method git-fetch) + (uri (git-reference + (url "https://android.googlesource.com/platform/build") + (commit (string-append "android-" version)))) + (file-name (string-append "android-platform-build-" + version "-checkout")) + (sha256 + (base32 + "04dwq2abmw88frj6fmdcl7fc4v55fvcdg6y1yrrszkjwmdnrhhyx")))) + +(define (android-platform-system-core version) + (origin + (method git-fetch) + (uri (git-reference + (url "https://android.googlesource.com/platform/system/core") + (commit (string-append "android-" version)))) + (file-name (string-append "android-platform-system-core-" + version "-checkout")) + (sha256 + (base32 + "1xrms8nc575wdh9rjlnibjh501i0pj8vjcyaivj4zjqkhw18s4km")))) +;; (define android-platform-system-core-license +;; (use-modules (guix licenses) #:prefix license) +;; (list (license:asl2.0 ; Main distribution. +;; license:bsd-2 ; fastboot, libcutils, libpixelflinger, tool= box/bsd-compatibility.h +;; license:bsd-4 ; Many files from libpixelflinger. +;; license:bsd-3 ; mincrypt, toolbox/*.c +;; license:gpl-2 ; Makefiles + some files that are dual ASL2.= 0/GPL-2 +;; license:expat))) ; libcutils/strlcpy.c + +(define liblog + (package + (name "liblog") + (version (android-platform-version)) + (source (android-platform-system-core version)) + (build-system gnu-build-system) + (arguments + `(#:tests? #f ; TODO. + #:make-flags '("CC=3Dgcc") + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'enter-source + (lambda _ (chdir "liblog") #t)) + (add-after 'enter-source 'create-Makefile + (lambda _ + ;; No useful makefile is shipped, so we create one. + (with-output-to-file "Makefile" + (lambda _ + (display + (string-append + "NAME =3D liblog\n" + "SOURCES =3D log_event_list.c log_event_write.c" + " logger_write.c config_write.c logger_name.c" + " logger_lock.c fake_log_device.c fake_writer.c" + " event_tag_map.c\n" + + "CFLAGS +=3D -fvisibility=3Dhidden -fPIC\n" + "CPPFLAGS +=3D -I../include -DFAKE_LOG_DEVICE=3D1" + ;; Keep these two in sync with "liblog/Android.bp". + " -DLIBLOG_LOG_TAG=3D1005" + " -DSNET_EVENT_LOG_TAG=3D1397638484\n" + "LDFLAGS +=3D -shared -Wl,-soname,$(NAME).so.0 -lpthrea= d\n" + + "build: $(SOURCES)\n" + " $(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFL= AGS)\n")))))) + (delete 'configure) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (lib (string-append out "/lib"))) + (install-file "liblog.so.0" lib) + (with-directory-excursion lib + (symlink "liblog.so.0" "liblog.so")) + #t)))))) + (home-page "https://developer.android.com/") + (synopsis "Logging library from the Android platform.") + (description "@code{liblog} represents an interface to the volatile An= droid +Logging system for NDK (Native) applications and libraries and contain +interfaces for either writing or reading logs. The log buffers are divide= d up +in Main, System, Radio and Events sub-logs.") + (license license:asl2.0))) + +(define libbase + (package + (name "libbase") + (version (android-platform-version)) + ;(source (android-platform-system-core version)) + (source (origin + (inherit (android-platform-system-core version)) + (patches + (search-patches "libbase-use-own-logging.patch")))) + (build-system gnu-build-system) + (arguments + `(#:tests? #f ; TODO. + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'enter-source + (lambda _ (chdir "base") #t)) + (add-after 'enter-source 'create-Makefile + (lambda _ + ;; No useful makefile is shipped, so we create one. + (with-output-to-file "Makefile" + (lambda _ + (display + (string-append + "NAME =3D libbase\n" + "SOURCES =3D file.cpp logging.cpp parsenetaddress.cpp" + " stringprintf.cpp strings.cpp errors_unix.cpp\n" + + "CXXFLAGS +=3D -std=3Dgnu++11\n" + "CPPFLAGS +=3D -Iinclude -I../include\n" + "LDFLAGS +=3D -shared -Wl,-soname,$(NAME).so.0" + " -L.. -llog\n" + + "build: $(SOURCES)\n" + " $(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(L= DFLAGS)\n" + )))))) + (delete 'configure) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (lib (string-append out "/lib"))) + (install-file "libbase.so.0" lib) + (with-directory-excursion lib + (symlink "libbase.so.0" "libbase.so")) + (copy-recursively "include" out) + #t)))))) + (inputs `(("liblog" ,liblog))) + (home-page "https://developer.android.com/") + (synopsis "Android platform base library") + (description "@code{libbase} is a library in common use by the +various Android core host applications.") + (license license:asl2.0))) + +(define-public adb + (package + (name "adb") + (version (android-platform-version)) + (source (android-platform-system-core version)) + (build-system gnu-build-system) + (arguments + `(#:phases + (modify-phases %standard-phases + (add-after 'unpack 'enter-source + (lambda _ (chdir "adb") #t)) + (add-after 'enter-source 'create-Makefile + (lambda _ + ;; No useful makefile is shipped, so we create one. + (with-output-to-file "Makefile" + (lambda _ + (display + (string-append + ;; Common for all components. + "CXXFLAGS +=3D -std=3Dgnu++14 -fpermissive\n" + + ;; Libabd specifics. + "LIBABD_SOURCES =3D adb.cpp adb_auth.cpp adb_io.cpp " + "adb_listeners.cpp adb_trace.cpp adb_utils.cpp fdevent.= cpp " + "sockets.cpp transport.cpp transport_local.cpp transpor= t_usb.cpp " + "fdevent.cpp get_my_path_linux.cpp sysdeps_unix.cpp " + "usb_linux.cpp adb_auth_host.cpp diagnose_usb.cpp servi= ces.cpp\n" + + "LIBADB_CPPFLAGS +=3D -I../include -I../base/include -D= ADB_HOST=3D1 " + "-DADB_REVISION=3D'\"" ,version "\"'\n" + "LIBADB_LDFLAGS +=3D -shared -Wl,-soname,libadb.so.0 " + "-lcrypto -lpthread -L.. -lbase -lcutils\n" + + ;; Adb specifics. + "ADB_SOURCES =3D adb_main.cpp console.cpp commandline.c= pp " + "adb_client.cpp file_sync_client.cpp\n" + + "libadb: $(LIBABD_SOURCES)\n" + " $(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(LIBADB_CPPFLAG= S) " + "$(LIBADB_LDFLAGS)\n" + + "build: libabd $(ADB_SOURCES)\n" + " $(CXX) $^ -o adb $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\n" + )))))) + (delete 'configure) + (replace 'check + (lambda _ + (zero? (system* "python" "test_adb.py")))) + ))) + (inputs + `(("libbase" ,libbase) + ("openssl" ,openssl))) + (native-inputs + `(("python" ,python-wrapper))) + (home-page "https://developer.android.com/studio/command-line/adb.html= ") + (synopsis "Android Debug Bridge") + (description + "@command{adb} is a versatile command line tool that lets you communi= cate +with an emulator instance or connected Android device. It facilitates a v= ariety +of device actions, such as installing and debugging apps, and it provides = access +to a Unix shell that can run commands on the connected device or emulator.= ") + (license license:asl2.0))) diff --git a/gnu/packages/patches/libbase-use-own-logging.patch b/gnu/packa= ges/patches/libbase-use-own-logging.patch new file mode 100644 index 000000000..4fcff832f --- /dev/null +++ b/gnu/packages/patches/libbase-use-own-logging.patch @@ -0,0 +1,77 @@ +From e5dd71a290f664d3f3bf0dd8a4bad411dc7ad416 Mon Sep 17 00:00:00 2001 +From: Elliott Hughes +Date: Thu, 28 Jul 2016 15:15:28 -0700 +Subject: [PATCH] libbase should use its own logging! + +Not doing so led to us using a bogus log tag. + +Bug: http://b/30281203 +Change-Id: I3ac91758a1a043146c65f2ae0f36fcfbe372c30f +--- + base/file.cpp | 11 +++++------ + base/logging.cpp | 3 +-- + 2 files changed, 6 insertions(+), 8 deletions(-) + +diff --git a/base/file.cpp b/base/file.cpp +index da1adba19..4e7ac82d1 100644 +--- a/base/file.cpp ++++ b/base/file.cpp +@@ -24,9 +24,8 @@ + #include +=20 + #include "android-base/macros.h" // For TEMP_FAILURE_RETRY on Darwin. ++#include "android-base/logging.h" + #include "android-base/utf8.h" +-#define LOG_TAG "base.file" +-#include "cutils/log.h" + #include "utils/Compat.h" +=20 + namespace android { +@@ -86,22 +85,22 @@ bool WriteStringToFile(const std::string& content, con= st std::string& path, + int flags =3D O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O= _BINARY; + int fd =3D TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode)); + if (fd =3D=3D -1) { +- ALOGE("android::WriteStringToFile open failed: %s", strerror(errno)); ++ PLOG(ERROR) << "android::WriteStringToFile open failed"; + return false; + } +=20 + // We do an explicit fchmod here because we assume that the caller real= ly + // meant what they said and doesn't want the umask-influenced mode. + if (fchmod(fd, mode) =3D=3D -1) { +- ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno)= ); ++ PLOG(ERROR) << "android::WriteStringToFile fchmod failed"; + return CleanUpAfterFailedWrite(path); + } + if (fchown(fd, owner, group) =3D=3D -1) { +- ALOGE("android::WriteStringToFile fchown failed: %s", strerror(errno)= ); ++ PLOG(ERROR) << "android::WriteStringToFile fchown failed"; + return CleanUpAfterFailedWrite(path); + } + if (!WriteStringToFd(content, fd)) { +- ALOGE("android::WriteStringToFile write failed: %s", strerror(errno)); ++ PLOG(ERROR) << "android::WriteStringToFile write failed"; + return CleanUpAfterFailedWrite(path); + } + close(fd); +diff --git a/base/logging.cpp b/base/logging.cpp +index 769c266c9..959bb8b05 100644 +--- a/base/logging.cpp ++++ b/base/logging.cpp +@@ -43,12 +43,11 @@ +=20 + #include "android-base/macros.h" + #include "android-base/strings.h" +-#include "cutils/threads.h" +=20 + // Headers for LogMessage::LogLine. + #ifdef __ANDROID__ + #include +-#include "cutils/log.h" ++#include "log/log.h" + #else + #include + #include +--=20 +2.11.0 + --=20 2.11.0 --=-=-=--