unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* bug#26522: gnu: Add adb
@ 2017-04-15 16:31 Julien Lepiller
  2017-04-15 18:02 ` Marius Bakke
  2017-04-20  8:33 ` bug#26522: julien lepiller
  0 siblings, 2 replies; 8+ messages in thread
From: Julien Lepiller @ 2017-04-15 16:31 UTC (permalink / raw)
  To: 26522

[-- Attachment #1: Type: text/plain, Size: 191 bytes --]

Hi guix,

here is an updated version of Marius' patch mixed with my own. It
updates our patches to the latest 7_1_2.rc6, adapts to some changes
since last version, and fixes the build of adb.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-adb.patch --]
[-- Type: text/x-patch, Size: 19972 bytes --]

From 96a5136e94bcae6cc2db0c83c81ef4831258779e Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 15 Apr 2017 18:17:27 +0200
Subject: [PATCH] gnu: Add adb.

* gnu/packages/android.scm: New file.
* gnu/packages/patches/libbase-fix-includes.patch: New file.
* gnu/packages/patches/libbase-use-own-logging.patch: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Add them.

Co-Authored-By: Marius Bakke <mbakke@fastmail.com>
---
 gnu/local.mk                                       |   3 +
 gnu/packages/android.scm                           | 290 +++++++++++++++++++++
 gnu/packages/patches/libbase-fix-includes.patch    |  68 +++++
 gnu/packages/patches/libbase-use-own-logging.patch |  77 ++++++
 4 files changed, 438 insertions(+)
 create mode 100644 gnu/packages/android.scm
 create mode 100644 gnu/packages/patches/libbase-fix-includes.patch
 create mode 100644 gnu/packages/patches/libbase-use-own-logging.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 82e94171b..4a80afc7d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -45,6 +45,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/adns.scm				\
   %D%/packages/algebra.scm			\
   %D%/packages/aidc.scm				\
+  %D%/packages/android.scm			\
   %D%/packages/animation.scm			\
   %D%/packages/anthy.scm			\
   %D%/packages/apl.scm				\
@@ -686,6 +687,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/liba52-link-with-libm.patch		\
   %D%/packages/patches/liba52-set-soname.patch			\
   %D%/packages/patches/liba52-use-mtune-not-mcpu.patch		\
+  %D%/packages/patches/libbase-fix-includes.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/libdrm-symbol-check.patch		\
diff --git a/gnu/packages/android.scm b/gnu/packages/android.scm
new file mode 100644
index 000000000..3e13b9a18
--- /dev/null
+++ b/gnu/packages/android.scm
@@ -0,0 +1,290 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2012 Stefan Handschuh <handschuh.stefan@googlemail.com>
+;;; Copyright © 2015 Kai-Chung Yan <seamlikok@gmail.com>
+;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2017 Julien Lepiller <julien@lepiller.eu>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 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 <handschuh.stefan@googlemail.com>
+;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
+;; Big thanks to them for laying the groundwork.
+
+;; The version tag is consistent between all repositories.
+(define (android-platform-version) "7.1.2_r6")
+
+(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
+      "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
+
+(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=gcc")
+       #: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 = liblog\n"
+                   "SOURCES = 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 += -fvisibility=hidden -fPIC\n"
+                   "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
+                   ;; Keep these two in sync with "liblog/Android.bp".
+                   " -DLIBLOG_LOG_TAG=1005"
+                   " -DSNET_EVENT_LOG_TAG=1397638484\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\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 Android
+Logging system for NDK (Native) applications and libraries and contain
+interfaces for either writing or reading logs.  The log buffers are divided up
+in Main, System, Radio and Events sub-logs.")
+    (license license:asl2.0)))
+
+(define libbase
+  (package
+    (name "libbase")
+    (version (android-platform-version))
+    (source (origin
+              (inherit (android-platform-system-core version))
+              (patches
+               (search-patches "libbase-use-own-logging.patch"
+                               "libbase-fix-includes.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 = libbase\n"
+                   "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
+                   " stringprintf.cpp strings.cpp errors_unix.cpp\n"
+
+                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
+                   "CPPFLAGS += -Iinclude -I../include\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
+                   " -L.. -llog\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\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 libcutils
+  (package
+    (name "libcutils")
+    (version (android-platform-version))
+    (source (android-platform-system-core version))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f ; TODO.
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'enter-source
+           (lambda _ (chdir "libcutils") #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 = libcutils\n"
+                   "SOURCES = load_file.o socket_local_client_unix.o"
+                   " socket_loopback_client_unix.o socket_network_client_unix.o"
+                   " socket_loopback_server_unix.o socket_local_server_unix.o"
+                   " sockets_unix.o socket_inaddr_any_server_unix.o"
+                   " sockets.o\n"
+                   "CC = gcc\n"
+
+                   "CFLAGS += -fPIC\n"
+                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
+                   "CPPFLAGS += -Iinclude -I../include\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"
+                   ))))))
+         (delete 'configure)
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib")))
+               (install-file "libcutils.so.0" lib)
+               (with-directory-excursion lib
+                 (symlink "libcutils.so.0" "libcutils.so"))
+               #t))))))
+    (home-page "https://developer.android.com/")
+    (synopsis "Android platform c utils library")
+    (description "@code{libcutils} 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 (origin
+              (inherit (android-platform-system-core version))
+              (patches
+               (search-patches "libbase-use-own-logging.patch"
+                               "libbase-fix-includes.patch"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'enter-source
+           (lambda _ (chdir "adb") #t))
+         (add-before 'build 'fix-clang
+           (lambda _
+             (substitute* "adb_client.h"
+                   (("_Nonnull") "")
+                   (("_Nullable") ""))))
+         (add-before 'build 'fix-main
+           (lambda _
+             (copy-file "client/main.cpp" "adb_main.cpp")))
+         (add-after 'enter-source 'create-Makefile
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; No useful makefile is shipped, so we create one.
+             (with-output-to-file "Makefile"
+               (lambda _
+                 (display
+                  (string-append
+                   ;; Common for all components.
+                   "CXXFLAGS += -std=gnu++14 -fpermissive\n"
+                   "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
+                   "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
+                   "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
+
+                   ;; Libadb specifics.
+                   "LIBADB_SOURCES = 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 transport_usb.cpp "
+                   "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
+                   "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
+                   "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
+
+                   "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
+                   "-lcrypto -lpthread -lbase\n"
+
+                   ;; Adb specifics.
+                   "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
+                   "adb_client.cpp file_sync_client.cpp\n"
+                   "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
+
+                   "build: libadb $(ADB_SOURCES)\n"
+                   "	$(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
+                   "$(ADB_LDFLAGS) $(LDFLAGS)\n"
+
+                   "libadb: $(LIBADB_SOURCES)\n"
+                   "	$(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
+                   "$(LIBADB_LDFLAGS)\n"
+                   "	ln -sv libadb.so.0 libadb.so\n"
+                   ))))))
+         (delete 'configure)
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib"))
+                    (bin (string-append out "/bin")))
+               (install-file "libadb.so.0" lib)
+               (install-file "adb" bin)
+               (with-directory-excursion lib
+                 (symlink "libadb.so.0" "libadb.so"))
+               #t))))
+       ;; Test suite must be run with attached devices
+       #:tests? #f))
+    (inputs
+     `(("libbase" ,libbase)
+       ("libcutils" ,libcutils)
+       ("openssl" ,openssl)))
+    (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 communicate
+with an emulator instance or connected Android device.  It facilitates a variety
+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-fix-includes.patch b/gnu/packages/patches/libbase-fix-includes.patch
new file mode 100644
index 000000000..24847ae0c
--- /dev/null
+++ b/gnu/packages/patches/libbase-fix-includes.patch
@@ -0,0 +1,68 @@
+This patch fixes the build of adb on linux. It was taken from archlinux.
+
+diff --git a/adb/sysdeps.h b/adb/sysdeps.h
+index 75dcc86..867f3ec 100644
+--- a/adb/sysdeps.h
++++ b/adb/sysdeps.h
+@@ -25,6 +25,7 @@
+ #endif
+ 
+ #include <errno.h>
++#include <sys/syscall.h>
+ 
+ #include <string>
+ #include <vector>
+@@ -831,7 +832,16 @@ static __inline__ int adb_is_absolute_host_path(const char* path) {
+ 
+ static __inline__ unsigned long adb_thread_id()
+ {
+-    return (unsigned long)gettid();
++  // TODO: this function should be merged with GetThreadId
++#if defined(__BIONIC__)
++  return gettid();
++#elif defined(__APPLE__)
++  return syscall(SYS_thread_selfid);
++#elif defined(__linux__)
++  return syscall(__NR_gettid);
++#elif defined(_WIN32)
++  return GetCurrentThreadId();
++#endif
+ }
+ 
+ #endif /* !_WIN32 */
+diff --git a/base/errors_unix.cpp b/base/errors_unix.cpp
+index 296995e..48269b6 100644
+--- a/base/errors_unix.cpp
++++ b/base/errors_unix.cpp
+@@ -17,6 +17,7 @@
+ #include "android-base/errors.h"
+ 
+ #include <errno.h>
++#include <string.h>
+ 
+ namespace android {
+ namespace base {
+diff --git a/base/file.cpp b/base/file.cpp
+index da1adba..91a3901 100644
+--- a/base/file.cpp
++++ b/base/file.cpp
+@@ -20,6 +20,7 @@
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
++#include <string.h>
+ 
+ #include <string>
+ 
+diff --git a/base/logging.cpp b/base/logging.cpp
+index 1741871..e97c7f1 100644
+--- a/base/logging.cpp
++++ b/base/logging.cpp
+@@ -21,6 +21,7 @@
+ #include "android-base/logging.h"
+ 
+ #include <libgen.h>
++#include <string.h>
+ 
+ // For getprogname(3) or program_invocation_short_name.
+ #if defined(__ANDROID__) || defined(__APPLE__)
diff --git a/gnu/packages/patches/libbase-use-own-logging.patch b/gnu/packages/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 <enh@google.com>
+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 <string>
+ 
+ #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"
+ 
+ namespace android {
+@@ -86,22 +85,22 @@ bool WriteStringToFile(const std::string& content, const std::string& path,
+   int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY;
+   int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
+   if (fd == -1) {
+-    ALOGE("android::WriteStringToFile open failed: %s", strerror(errno));
++    PLOG(ERROR) << "android::WriteStringToFile open failed";
+     return false;
+   }
+ 
+   // We do an explicit fchmod here because we assume that the caller really
+   // meant what they said and doesn't want the umask-influenced mode.
+   if (fchmod(fd, mode) == -1) {
+-    ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno));
++    PLOG(ERROR) << "android::WriteStringToFile fchmod failed";
+     return CleanUpAfterFailedWrite(path);
+   }
+   if (fchown(fd, owner, group) == -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 @@
+ 
+ #include "android-base/macros.h"
+ #include "android-base/strings.h"
+-#include "cutils/threads.h"
+ 
+ // Headers for LogMessage::LogLine.
+ #ifdef __ANDROID__
+ #include <android/set_abort_message.h>
+-#include "cutils/log.h"
++#include "log/log.h"
+ #else
+ #include <sys/types.h>
+ #include <unistd.h>
+-- 
+2.11.0
+
-- 
2.12.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#26522: gnu: Add adb
  2017-04-15 16:31 bug#26522: gnu: Add adb Julien Lepiller
@ 2017-04-15 18:02 ` Marius Bakke
  2017-04-16  9:22   ` Julien Lepiller
  2017-04-20  8:33 ` bug#26522: julien lepiller
  1 sibling, 1 reply; 8+ messages in thread
From: Marius Bakke @ 2017-04-15 18:02 UTC (permalink / raw)
  To: Julien Lepiller, 26522

[-- Attachment #1: Type: text/plain, Size: 10784 bytes --]

Julien Lepiller <julien@lepiller.eu> writes:

> Hi guix,
>
> here is an updated version of Marius' patch mixed with my own. It
> updates our patches to the latest 7_1_2.rc6, adapts to some changes
> since last version, and fixes the build of adb.

Wahoo! :)

I was *just* thinking yesterday that I should fix up this package ASAP.
Thanks a lot for beating me to it!

[...]

> +(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=gcc")
> +       #: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 = liblog\n"
> +                   "SOURCES = 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 += -fvisibility=hidden -fPIC\n"
> +                   "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
> +                   ;; Keep these two in sync with "liblog/Android.bp".
> +                   " -DLIBLOG_LOG_TAG=1005"
> +                   " -DSNET_EVENT_LOG_TAG=1397638484\n"
> +                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
> +
> +                   "build: $(SOURCES)\n"
> +                   "	$(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"))))))

I'm actually not sure what the return value of "display" is and the
Guile manual does not mention. I'd end this on a #t just to be "safe".

> +         (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 Android
> +Logging system for NDK (Native) applications and libraries and contain
> +interfaces for either writing or reading logs.  The log buffers are divided up
> +in Main, System, Radio and Events sub-logs.")
> +    (license license:asl2.0)))
> +
> +(define libbase
> +  (package
> +    (name "libbase")
> +    (version (android-platform-version))
> +    (source (origin
> +              (inherit (android-platform-system-core version))
> +              (patches
> +               (search-patches "libbase-use-own-logging.patch"
> +                               "libbase-fix-includes.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 = libbase\n"
> +                   "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
> +                   " stringprintf.cpp strings.cpp errors_unix.cpp\n"
> +
> +                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
> +                   "CPPFLAGS += -Iinclude -I../include\n"
> +                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
> +                   " -L.. -llog\n"
> +
> +                   "build: $(SOURCES)\n"
> +                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"
> +                   ))))))

Same here, and also move the parens to the previous line. Possibly also
break it into two lines :)

> +         (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 libcutils
> +  (package
> +    (name "libcutils")
> +    (version (android-platform-version))
> +    (source (android-platform-system-core version))
> +    (build-system gnu-build-system)
> +    (arguments
> +     `(#:tests? #f ; TODO.
> +       #:phases
> +       (modify-phases %standard-phases
> +         (add-after 'unpack 'enter-source
> +           (lambda _ (chdir "libcutils") #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 = libcutils\n"
> +                   "SOURCES = load_file.o socket_local_client_unix.o"
> +                   " socket_loopback_client_unix.o socket_network_client_unix.o"
> +                   " socket_loopback_server_unix.o socket_local_server_unix.o"
> +                   " sockets_unix.o socket_inaddr_any_server_unix.o"
> +                   " sockets.o\n"
> +                   "CC = gcc\n"
> +
> +                   "CFLAGS += -fPIC\n"
> +                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
> +                   "CPPFLAGS += -Iinclude -I../include\n"
> +                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
> +
> +                   "build: $(SOURCES)\n"
> +                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"
> +                   ))))))

...and here.

> +         (delete 'configure)
> +         (replace 'install
> +           (lambda* (#:key outputs #:allow-other-keys)
> +             (let* ((out (assoc-ref outputs "out"))
> +                    (lib (string-append out "/lib")))
> +               (install-file "libcutils.so.0" lib)
> +               (with-directory-excursion lib
> +                 (symlink "libcutils.so.0" "libcutils.so"))
> +               #t))))))
> +    (home-page "https://developer.android.com/")
> +    (synopsis "Android platform c utils library")
> +    (description "@code{libcutils} 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 (origin
> +              (inherit (android-platform-system-core version))
> +              (patches
> +               (search-patches "libbase-use-own-logging.patch"
> +                               "libbase-fix-includes.patch"))))
> +    (build-system gnu-build-system)
> +    (arguments
> +     `(#:phases
> +       (modify-phases %standard-phases
> +         (add-after 'unpack 'enter-source
> +           (lambda _ (chdir "adb") #t))
> +         (add-before 'build 'fix-clang
> +           (lambda _
> +             (substitute* "adb_client.h"
> +                   (("_Nonnull") "")
> +                   (("_Nullable") ""))))

Can you add a comment explaining what this does? From the phase name,
I'd guess it removes a clang dependency, but it's not clear how or why.
Also check indentation here and end with an explicit #t.

> +         (add-before 'build 'fix-main
> +           (lambda _
> +             (copy-file "client/main.cpp" "adb_main.cpp")))

This should also end on a #t. A comment would be nice too if you know
why it's needed, what an odd build step.

> +         (add-after 'enter-source 'create-Makefile
> +           (lambda* (#:key outputs #:allow-other-keys)
> +             ;; No useful makefile is shipped, so we create one.
> +             (with-output-to-file "Makefile"
> +               (lambda _
> +                 (display
> +                  (string-append
> +                   ;; Common for all components.
> +                   "CXXFLAGS += -std=gnu++14 -fpermissive\n"
> +                   "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
> +                   "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
> +                   "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
> +
> +                   ;; Libadb specifics.
> +                   "LIBADB_SOURCES = 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 transport_usb.cpp "
> +                   "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
> +                   "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
> +                   "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
> +
> +                   "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
> +                   "-lcrypto -lpthread -lbase\n"
> +
> +                   ;; Adb specifics.
> +                   "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
> +                   "adb_client.cpp file_sync_client.cpp\n"
> +                   "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
> +
> +                   "build: libadb $(ADB_SOURCES)\n"
> +                   "	$(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
> +                   "$(ADB_LDFLAGS) $(LDFLAGS)\n"
> +
> +                   "libadb: $(LIBADB_SOURCES)\n"
> +                   "	$(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
> +                   "$(LIBADB_LDFLAGS)\n"
> +                   "	ln -sv libadb.so.0 libadb.so\n"
> +                   ))))))

...lonely parens here too (`lint` should complain about this) :)

LGTM with these fixes! Thank you!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#26522: gnu: Add adb
  2017-04-15 18:02 ` Marius Bakke
@ 2017-04-16  9:22   ` Julien Lepiller
  2017-04-16 21:54     ` Marius Bakke
  0 siblings, 1 reply; 8+ messages in thread
From: Julien Lepiller @ 2017-04-16  9:22 UTC (permalink / raw)
  To: 26522

[-- Attachment #1: Type: text/plain, Size: 72 bytes --]

Hi Marius,

thanks for the quick review. This should fix your comments.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-adb.patch --]
[-- Type: text/x-patch, Size: 20431 bytes --]

From a6a608744dc5628bc94ffdb2bc9abf359daf72dc Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 15 Apr 2017 18:17:27 +0200
Subject: [PATCH] gnu: Add adb.

* gnu/packages/android.scm: New file.
* gnu/packages/patches/libbase-fix-includes.patch: New file.
* gnu/packages/patches/libbase-use-own-logging.patch: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Add them.

Co-Authored-By: Marius Bakke <mbakke@fastmail.com>
---
 gnu/local.mk                                       |   3 +
 gnu/packages/android.scm                           | 300 +++++++++++++++++++++
 gnu/packages/patches/libbase-fix-includes.patch    |  68 +++++
 gnu/packages/patches/libbase-use-own-logging.patch |  77 ++++++
 4 files changed, 448 insertions(+)
 create mode 100644 gnu/packages/android.scm
 create mode 100644 gnu/packages/patches/libbase-fix-includes.patch
 create mode 100644 gnu/packages/patches/libbase-use-own-logging.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 82e94171b..4a80afc7d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -45,6 +45,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/adns.scm				\
   %D%/packages/algebra.scm			\
   %D%/packages/aidc.scm				\
+  %D%/packages/android.scm			\
   %D%/packages/animation.scm			\
   %D%/packages/anthy.scm			\
   %D%/packages/apl.scm				\
@@ -686,6 +687,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/liba52-link-with-libm.patch		\
   %D%/packages/patches/liba52-set-soname.patch			\
   %D%/packages/patches/liba52-use-mtune-not-mcpu.patch		\
+  %D%/packages/patches/libbase-fix-includes.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/libdrm-symbol-check.patch		\
diff --git a/gnu/packages/android.scm b/gnu/packages/android.scm
new file mode 100644
index 000000000..e23d0fd91
--- /dev/null
+++ b/gnu/packages/android.scm
@@ -0,0 +1,300 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2012 Stefan Handschuh <handschuh.stefan@googlemail.com>
+;;; Copyright © 2015 Kai-Chung Yan <seamlikok@gmail.com>
+;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2017 Julien Lepiller <julien@lepiller.eu>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 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 <handschuh.stefan@googlemail.com>
+;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
+;; Big thanks to them for laying the groundwork.
+
+;; The version tag is consistent between all repositories.
+(define (android-platform-version) "7.1.2_r6")
+
+(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
+      "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
+
+(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=gcc")
+       #: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 = liblog\n"
+                   "SOURCES = 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 += -fvisibility=hidden -fPIC\n"
+                   "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
+                   ;; Keep these two in sync with "liblog/Android.bp".
+                   " -DLIBLOG_LOG_TAG=1005"
+                   " -DSNET_EVENT_LOG_TAG=1397638484\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"))
+                 #t))))
+         (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 Android
+Logging system for NDK (Native) applications and libraries and contain
+interfaces for either writing or reading logs.  The log buffers are divided up
+in Main, System, Radio and Events sub-logs.")
+    (license license:asl2.0)))
+
+(define libbase
+  (package
+    (name "libbase")
+    (version (android-platform-version))
+    (source (origin
+              (inherit (android-platform-system-core version))
+              (patches
+               (search-patches "libbase-use-own-logging.patch"
+                               "libbase-fix-includes.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 = libbase\n"
+                   "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
+                   " stringprintf.cpp strings.cpp errors_unix.cpp\n"
+
+                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
+                   "CPPFLAGS += -Iinclude -I../include\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
+                   " -L.. -llog\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
+                   " $(LDFLAGS)\n"))
+                 #t))))
+         (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 libcutils
+  (package
+    (name "libcutils")
+    (version (android-platform-version))
+    (source (android-platform-system-core version))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f ; TODO.
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'enter-source
+           (lambda _ (chdir "libcutils") #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 = libcutils\n"
+                   "SOURCES = load_file.o socket_local_client_unix.o"
+                   " socket_loopback_client_unix.o socket_network_client_unix.o"
+                   " socket_loopback_server_unix.o socket_local_server_unix.o"
+                   " sockets_unix.o socket_inaddr_any_server_unix.o"
+                   " sockets.o\n"
+                   "CC = gcc\n"
+
+                   "CFLAGS += -fPIC\n"
+                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
+                   "CPPFLAGS += -Iinclude -I../include\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
+                   " $(LDFLAGS)\n"))
+                 #t))))
+         (delete 'configure)
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib")))
+               (install-file "libcutils.so.0" lib)
+               (with-directory-excursion lib
+                 (symlink "libcutils.so.0" "libcutils.so"))
+               #t))))))
+    (home-page "https://developer.android.com/")
+    (synopsis "Android platform c utils library")
+    (description "@code{libcutils} 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 (origin
+              (inherit (android-platform-system-core version))
+              (patches
+               (search-patches "libbase-use-own-logging.patch"
+                               "libbase-fix-includes.patch"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'enter-source
+           (lambda _ (chdir "adb") #t))
+         (add-before 'build 'fix-clang
+           (lambda _
+             ;; adb_client.h contains _Nonnull and _Nullable attributes, that
+             ;; are not understood by gcc.
+             (substitute* "adb_client.h"
+                   (("_Nonnull") "")
+                   (("_Nullable") ""))
+             #t))
+         (add-before 'build 'fix-main
+           (lambda _
+             ;; main.cpp used to be adb_main.cpp in the current directory
+             ;; rather than in its own subdirectory, but it was not fixed.
+             ;; This leads to some header files not being found anymore.
+             (copy-file "client/main.cpp" "adb_main.cpp")
+             #t))
+         (add-after 'enter-source 'create-Makefile
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; No useful makefile is shipped, so we create one.
+             (with-output-to-file "Makefile"
+               (lambda _
+                 (display
+                  (string-append
+                   ;; Common for all components.
+                   "CXXFLAGS += -std=gnu++14 -fpermissive\n"
+                   "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
+                   "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
+                   "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
+
+                   ;; Libadb specifics.
+                   "LIBADB_SOURCES = 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 transport_usb.cpp "
+                   "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
+                   "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
+                   "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
+
+                   "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
+                   "-lcrypto -lpthread -lbase\n"
+
+                   ;; Adb specifics.
+                   "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
+                   "adb_client.cpp file_sync_client.cpp\n"
+                   "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
+
+                   "build: libadb $(ADB_SOURCES)\n"
+                   "	$(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
+                   "$(ADB_LDFLAGS) $(LDFLAGS)\n"
+
+                   "libadb: $(LIBADB_SOURCES)\n"
+                   "	$(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
+                   "$(LIBADB_LDFLAGS)\n"
+                   "	ln -sv libadb.so.0 libadb.so\n"))
+                 #t))))
+         (delete 'configure)
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib"))
+                    (bin (string-append out "/bin")))
+               (install-file "libadb.so.0" lib)
+               (install-file "adb" bin)
+               (with-directory-excursion lib
+                 (symlink "libadb.so.0" "libadb.so"))
+               #t))))
+       ;; Test suite must be run with attached devices
+       #:tests? #f))
+    (inputs
+     `(("libbase" ,libbase)
+       ("libcutils" ,libcutils)
+       ("openssl" ,openssl)))
+    (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 communicate
+with an emulator instance or connected Android device.  It facilitates a variety
+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-fix-includes.patch b/gnu/packages/patches/libbase-fix-includes.patch
new file mode 100644
index 000000000..24847ae0c
--- /dev/null
+++ b/gnu/packages/patches/libbase-fix-includes.patch
@@ -0,0 +1,68 @@
+This patch fixes the build of adb on linux. It was taken from archlinux.
+
+diff --git a/adb/sysdeps.h b/adb/sysdeps.h
+index 75dcc86..867f3ec 100644
+--- a/adb/sysdeps.h
++++ b/adb/sysdeps.h
+@@ -25,6 +25,7 @@
+ #endif
+ 
+ #include <errno.h>
++#include <sys/syscall.h>
+ 
+ #include <string>
+ #include <vector>
+@@ -831,7 +832,16 @@ static __inline__ int adb_is_absolute_host_path(const char* path) {
+ 
+ static __inline__ unsigned long adb_thread_id()
+ {
+-    return (unsigned long)gettid();
++  // TODO: this function should be merged with GetThreadId
++#if defined(__BIONIC__)
++  return gettid();
++#elif defined(__APPLE__)
++  return syscall(SYS_thread_selfid);
++#elif defined(__linux__)
++  return syscall(__NR_gettid);
++#elif defined(_WIN32)
++  return GetCurrentThreadId();
++#endif
+ }
+ 
+ #endif /* !_WIN32 */
+diff --git a/base/errors_unix.cpp b/base/errors_unix.cpp
+index 296995e..48269b6 100644
+--- a/base/errors_unix.cpp
++++ b/base/errors_unix.cpp
+@@ -17,6 +17,7 @@
+ #include "android-base/errors.h"
+ 
+ #include <errno.h>
++#include <string.h>
+ 
+ namespace android {
+ namespace base {
+diff --git a/base/file.cpp b/base/file.cpp
+index da1adba..91a3901 100644
+--- a/base/file.cpp
++++ b/base/file.cpp
+@@ -20,6 +20,7 @@
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
++#include <string.h>
+ 
+ #include <string>
+ 
+diff --git a/base/logging.cpp b/base/logging.cpp
+index 1741871..e97c7f1 100644
+--- a/base/logging.cpp
++++ b/base/logging.cpp
+@@ -21,6 +21,7 @@
+ #include "android-base/logging.h"
+ 
+ #include <libgen.h>
++#include <string.h>
+ 
+ // For getprogname(3) or program_invocation_short_name.
+ #if defined(__ANDROID__) || defined(__APPLE__)
diff --git a/gnu/packages/patches/libbase-use-own-logging.patch b/gnu/packages/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 <enh@google.com>
+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 <string>
+ 
+ #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"
+ 
+ namespace android {
+@@ -86,22 +85,22 @@ bool WriteStringToFile(const std::string& content, const std::string& path,
+   int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY;
+   int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
+   if (fd == -1) {
+-    ALOGE("android::WriteStringToFile open failed: %s", strerror(errno));
++    PLOG(ERROR) << "android::WriteStringToFile open failed";
+     return false;
+   }
+ 
+   // We do an explicit fchmod here because we assume that the caller really
+   // meant what they said and doesn't want the umask-influenced mode.
+   if (fchmod(fd, mode) == -1) {
+-    ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno));
++    PLOG(ERROR) << "android::WriteStringToFile fchmod failed";
+     return CleanUpAfterFailedWrite(path);
+   }
+   if (fchown(fd, owner, group) == -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 @@
+ 
+ #include "android-base/macros.h"
+ #include "android-base/strings.h"
+-#include "cutils/threads.h"
+ 
+ // Headers for LogMessage::LogLine.
+ #ifdef __ANDROID__
+ #include <android/set_abort_message.h>
+-#include "cutils/log.h"
++#include "log/log.h"
+ #else
+ #include <sys/types.h>
+ #include <unistd.h>
+-- 
+2.11.0
+
-- 
2.12.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#26522: gnu: Add adb
  2017-04-16  9:22   ` Julien Lepiller
@ 2017-04-16 21:54     ` Marius Bakke
  2017-04-17  8:40       ` Julien Lepiller
  0 siblings, 1 reply; 8+ messages in thread
From: Marius Bakke @ 2017-04-16 21:54 UTC (permalink / raw)
  To: Julien Lepiller, 26522

[-- Attachment #1: Type: text/plain, Size: 561 bytes --]

Julien Lepiller <julien@lepiller.eu> writes:

> Hi Marius,
>
> thanks for the quick review. This should fix your comments.

Great! One thing I overlooked last time was the patches. It would be
good to include the origin in URL form, so we can dig them out later.

The arch patch shouldn't be too hard to find (but URL would be
convenient!), I'm curious where the other patch comes from.

Patches tend to evolve over time, so checking what happened "upstream"
can be handy when you're stumped. See e.g. any CVE patch for examples :)

Other than that looks good!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#26522: gnu: Add adb
  2017-04-16 21:54     ` Marius Bakke
@ 2017-04-17  8:40       ` Julien Lepiller
  2017-04-17 15:09         ` Marius Bakke
  0 siblings, 1 reply; 8+ messages in thread
From: Julien Lepiller @ 2017-04-17  8:40 UTC (permalink / raw)
  To: 26522

[-- Attachment #1: Type: text/plain, Size: 863 bytes --]

Le Sun, 16 Apr 2017 23:54:47 +0200,
Marius Bakke <mbakke@fastmail.com> a écrit :

> Julien Lepiller <julien@lepiller.eu> writes:
> 
> > Hi Marius,
> >
> > thanks for the quick review. This should fix your comments.
> 
> Great! One thing I overlooked last time was the patches. It would be
> good to include the origin in URL form, so we can dig them out later.
> 
> The arch patch shouldn't be too hard to find (but URL would be
> convenient!), I'm curious where the other patch comes from.
> 
> Patches tend to evolve over time, so checking what happened "upstream"
> can be handy when you're stumped. See e.g. any CVE patch for
> examples :)
> 
> Other than that looks good!

Here is an updated patch with a link to archlinux' patch. You were the
one to add the other patch, and I can't find it. I'm also curious where
it comes from :p

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-Add-adb.patch --]
[-- Type: text/x-patch, Size: 20544 bytes --]

From 063e22dd5faceb9b0461c5daee5b5b963336ad75 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 15 Apr 2017 18:17:27 +0200
Subject: [PATCH] gnu: Add adb.

* gnu/packages/android.scm: New file.
* gnu/packages/patches/libbase-fix-includes.patch: New file.
* gnu/packages/patches/libbase-use-own-logging.patch: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Add them.

Co-Authored-By: Marius Bakke <mbakke@fastmail.com>
---
 gnu/local.mk                                       |   3 +
 gnu/packages/android.scm                           | 300 +++++++++++++++++++++
 gnu/packages/patches/libbase-fix-includes.patch    |  71 +++++
 gnu/packages/patches/libbase-use-own-logging.patch |  77 ++++++
 4 files changed, 451 insertions(+)
 create mode 100644 gnu/packages/android.scm
 create mode 100644 gnu/packages/patches/libbase-fix-includes.patch
 create mode 100644 gnu/packages/patches/libbase-use-own-logging.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 82e94171b..4a80afc7d 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -45,6 +45,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/adns.scm				\
   %D%/packages/algebra.scm			\
   %D%/packages/aidc.scm				\
+  %D%/packages/android.scm			\
   %D%/packages/animation.scm			\
   %D%/packages/anthy.scm			\
   %D%/packages/apl.scm				\
@@ -686,6 +687,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/liba52-link-with-libm.patch		\
   %D%/packages/patches/liba52-set-soname.patch			\
   %D%/packages/patches/liba52-use-mtune-not-mcpu.patch		\
+  %D%/packages/patches/libbase-fix-includes.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/libdrm-symbol-check.patch		\
diff --git a/gnu/packages/android.scm b/gnu/packages/android.scm
new file mode 100644
index 000000000..e23d0fd91
--- /dev/null
+++ b/gnu/packages/android.scm
@@ -0,0 +1,300 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2012 Stefan Handschuh <handschuh.stefan@googlemail.com>
+;;; Copyright © 2015 Kai-Chung Yan <seamlikok@gmail.com>
+;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2017 Julien Lepiller <julien@lepiller.eu>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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 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 <handschuh.stefan@googlemail.com>
+;; 2015, Kai-Chung Yan <seamlikok@gmail.com>
+;; Big thanks to them for laying the groundwork.
+
+;; The version tag is consistent between all repositories.
+(define (android-platform-version) "7.1.2_r6")
+
+(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
+      "0xc2n7jxrf1iw9cc278pijdfjix2fkiig5ws27f6rwp40zg5mrgg"))))
+
+(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=gcc")
+       #: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 = liblog\n"
+                   "SOURCES = 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 += -fvisibility=hidden -fPIC\n"
+                   "CPPFLAGS += -I../include -DFAKE_LOG_DEVICE=1"
+                   ;; Keep these two in sync with "liblog/Android.bp".
+                   " -DLIBLOG_LOG_TAG=1005"
+                   " -DSNET_EVENT_LOG_TAG=1397638484\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0 -lpthread\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CC) $^ -o $(NAME).so.0 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)\n"))
+                 #t))))
+         (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 Android
+Logging system for NDK (Native) applications and libraries and contain
+interfaces for either writing or reading logs.  The log buffers are divided up
+in Main, System, Radio and Events sub-logs.")
+    (license license:asl2.0)))
+
+(define libbase
+  (package
+    (name "libbase")
+    (version (android-platform-version))
+    (source (origin
+              (inherit (android-platform-system-core version))
+              (patches
+               (search-patches "libbase-use-own-logging.patch"
+                               "libbase-fix-includes.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 = libbase\n"
+                   "SOURCES = file.cpp logging.cpp parsenetaddress.cpp"
+                   " stringprintf.cpp strings.cpp errors_unix.cpp\n"
+
+                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
+                   "CPPFLAGS += -Iinclude -I../include\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0"
+                   " -L.. -llog\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
+                   " $(LDFLAGS)\n"))
+                 #t))))
+         (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 libcutils
+  (package
+    (name "libcutils")
+    (version (android-platform-version))
+    (source (android-platform-system-core version))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f ; TODO.
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'enter-source
+           (lambda _ (chdir "libcutils") #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 = libcutils\n"
+                   "SOURCES = load_file.o socket_local_client_unix.o"
+                   " socket_loopback_client_unix.o socket_network_client_unix.o"
+                   " socket_loopback_server_unix.o socket_local_server_unix.o"
+                   " sockets_unix.o socket_inaddr_any_server_unix.o"
+                   " sockets.o\n"
+                   "CC = gcc\n"
+
+                   "CFLAGS += -fPIC\n"
+                   "CXXFLAGS += -std=gnu++11 -fPIC\n"
+                   "CPPFLAGS += -Iinclude -I../include\n"
+                   "LDFLAGS += -shared -Wl,-soname,$(NAME).so.0\n"
+
+                   "build: $(SOURCES)\n"
+                   "	$(CXX) $^ -o $(NAME).so.0 $(CXXFLAGS) $(CPPFLAGS)"
+                   " $(LDFLAGS)\n"))
+                 #t))))
+         (delete 'configure)
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib")))
+               (install-file "libcutils.so.0" lib)
+               (with-directory-excursion lib
+                 (symlink "libcutils.so.0" "libcutils.so"))
+               #t))))))
+    (home-page "https://developer.android.com/")
+    (synopsis "Android platform c utils library")
+    (description "@code{libcutils} 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 (origin
+              (inherit (android-platform-system-core version))
+              (patches
+               (search-patches "libbase-use-own-logging.patch"
+                               "libbase-fix-includes.patch"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'enter-source
+           (lambda _ (chdir "adb") #t))
+         (add-before 'build 'fix-clang
+           (lambda _
+             ;; adb_client.h contains _Nonnull and _Nullable attributes, that
+             ;; are not understood by gcc.
+             (substitute* "adb_client.h"
+                   (("_Nonnull") "")
+                   (("_Nullable") ""))
+             #t))
+         (add-before 'build 'fix-main
+           (lambda _
+             ;; main.cpp used to be adb_main.cpp in the current directory
+             ;; rather than in its own subdirectory, but it was not fixed.
+             ;; This leads to some header files not being found anymore.
+             (copy-file "client/main.cpp" "adb_main.cpp")
+             #t))
+         (add-after 'enter-source 'create-Makefile
+           (lambda* (#:key outputs #:allow-other-keys)
+             ;; No useful makefile is shipped, so we create one.
+             (with-output-to-file "Makefile"
+               (lambda _
+                 (display
+                  (string-append
+                   ;; Common for all components.
+                   "CXXFLAGS += -std=gnu++14 -fpermissive\n"
+                   "CPPFLAGS += -I../include -I../base/include -I. -DADB_HOST=1 "
+                   "-DADB_REVISION='\"" ,version "\"' -fPIC\n"
+                   "LDFLAGS += -lcrypto -lpthread -lbase -lcutils -L. -ladb\n"
+
+                   ;; Libadb specifics.
+                   "LIBADB_SOURCES = 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 transport_usb.cpp "
+                   "get_my_path_linux.cpp sysdeps_unix.cpp usb_linux.cpp "
+                   "adb_auth_host.cpp diagnose_usb.cpp services.cpp "
+                   "shell_service_protocol.cpp bugreport.cpp line_printer.cpp\n"
+
+                   "LIBADB_LDFLAGS += -shared -Wl,-soname,libadb.so.0 "
+                   "-lcrypto -lpthread -lbase\n"
+
+                   ;; Adb specifics.
+                   "ADB_SOURCES = adb_main.cpp console.cpp commandline.cpp "
+                   "adb_client.cpp file_sync_client.cpp\n"
+                   "ADB_LDFLAGS += -Wl,-rpath=" (assoc-ref outputs "out") "/lib\n"
+
+                   "build: libadb $(ADB_SOURCES)\n"
+                   "	$(CXX) $(ADB_SOURCES) -o adb $(CXXFLAGS) $(CPPFLAGS) "
+                   "$(ADB_LDFLAGS) $(LDFLAGS)\n"
+
+                   "libadb: $(LIBADB_SOURCES)\n"
+                   "	$(CXX) $^ -o libadb.so.0 $(CXXFLAGS) $(CPPFLAGS) "
+                   "$(LIBADB_LDFLAGS)\n"
+                   "	ln -sv libadb.so.0 libadb.so\n"))
+                 #t))))
+         (delete 'configure)
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (lib (string-append out "/lib"))
+                    (bin (string-append out "/bin")))
+               (install-file "libadb.so.0" lib)
+               (install-file "adb" bin)
+               (with-directory-excursion lib
+                 (symlink "libadb.so.0" "libadb.so"))
+               #t))))
+       ;; Test suite must be run with attached devices
+       #:tests? #f))
+    (inputs
+     `(("libbase" ,libbase)
+       ("libcutils" ,libcutils)
+       ("openssl" ,openssl)))
+    (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 communicate
+with an emulator instance or connected Android device.  It facilitates a variety
+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-fix-includes.patch b/gnu/packages/patches/libbase-fix-includes.patch
new file mode 100644
index 000000000..3071a0c40
--- /dev/null
+++ b/gnu/packages/patches/libbase-fix-includes.patch
@@ -0,0 +1,71 @@
+This patch fixes the build of adb on linux.
+
+Copied from archlinux repository:
+https://git.archlinux.org/svntogit/community.git/tree/trunk/fix_build.patch?h=packages/android-tools
+
+diff --git a/adb/sysdeps.h b/adb/sysdeps.h
+index 75dcc86..867f3ec 100644
+--- a/adb/sysdeps.h
++++ b/adb/sysdeps.h
+@@ -25,6 +25,7 @@
+ #endif
+ 
+ #include <errno.h>
++#include <sys/syscall.h>
+ 
+ #include <string>
+ #include <vector>
+@@ -831,7 +832,16 @@ static __inline__ int adb_is_absolute_host_path(const char* path) {
+ 
+ static __inline__ unsigned long adb_thread_id()
+ {
+-    return (unsigned long)gettid();
++  // TODO: this function should be merged with GetThreadId
++#if defined(__BIONIC__)
++  return gettid();
++#elif defined(__APPLE__)
++  return syscall(SYS_thread_selfid);
++#elif defined(__linux__)
++  return syscall(__NR_gettid);
++#elif defined(_WIN32)
++  return GetCurrentThreadId();
++#endif
+ }
+ 
+ #endif /* !_WIN32 */
+diff --git a/base/errors_unix.cpp b/base/errors_unix.cpp
+index 296995e..48269b6 100644
+--- a/base/errors_unix.cpp
++++ b/base/errors_unix.cpp
+@@ -17,6 +17,7 @@
+ #include "android-base/errors.h"
+ 
+ #include <errno.h>
++#include <string.h>
+ 
+ namespace android {
+ namespace base {
+diff --git a/base/file.cpp b/base/file.cpp
+index da1adba..91a3901 100644
+--- a/base/file.cpp
++++ b/base/file.cpp
+@@ -20,6 +20,7 @@
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
++#include <string.h>
+ 
+ #include <string>
+ 
+diff --git a/base/logging.cpp b/base/logging.cpp
+index 1741871..e97c7f1 100644
+--- a/base/logging.cpp
++++ b/base/logging.cpp
+@@ -21,6 +21,7 @@
+ #include "android-base/logging.h"
+ 
+ #include <libgen.h>
++#include <string.h>
+ 
+ // For getprogname(3) or program_invocation_short_name.
+ #if defined(__ANDROID__) || defined(__APPLE__)
diff --git a/gnu/packages/patches/libbase-use-own-logging.patch b/gnu/packages/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 <enh@google.com>
+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 <string>
+ 
+ #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"
+ 
+ namespace android {
+@@ -86,22 +85,22 @@ bool WriteStringToFile(const std::string& content, const std::string& path,
+   int flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW | O_BINARY;
+   int fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
+   if (fd == -1) {
+-    ALOGE("android::WriteStringToFile open failed: %s", strerror(errno));
++    PLOG(ERROR) << "android::WriteStringToFile open failed";
+     return false;
+   }
+ 
+   // We do an explicit fchmod here because we assume that the caller really
+   // meant what they said and doesn't want the umask-influenced mode.
+   if (fchmod(fd, mode) == -1) {
+-    ALOGE("android::WriteStringToFile fchmod failed: %s", strerror(errno));
++    PLOG(ERROR) << "android::WriteStringToFile fchmod failed";
+     return CleanUpAfterFailedWrite(path);
+   }
+   if (fchown(fd, owner, group) == -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 @@
+ 
+ #include "android-base/macros.h"
+ #include "android-base/strings.h"
+-#include "cutils/threads.h"
+ 
+ // Headers for LogMessage::LogLine.
+ #ifdef __ANDROID__
+ #include <android/set_abort_message.h>
+-#include "cutils/log.h"
++#include "log/log.h"
+ #else
+ #include <sys/types.h>
+ #include <unistd.h>
+-- 
+2.11.0
+
-- 
2.12.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#26522: gnu: Add adb
  2017-04-17  8:40       ` Julien Lepiller
@ 2017-04-17 15:09         ` Marius Bakke
  2017-04-18  8:21           ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Marius Bakke @ 2017-04-17 15:09 UTC (permalink / raw)
  To: Julien Lepiller, 26522

[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]

Julien Lepiller <julien@lepiller.eu> writes:

> Le Sun, 16 Apr 2017 23:54:47 +0200,
> Marius Bakke <mbakke@fastmail.com> a écrit :
>
>> Julien Lepiller <julien@lepiller.eu> writes:
>> 
>> > Hi Marius,
>> >
>> > thanks for the quick review. This should fix your comments.
>> 
>> Great! One thing I overlooked last time was the patches. It would be
>> good to include the origin in URL form, so we can dig them out later.
>> 
>> The arch patch shouldn't be too hard to find (but URL would be
>> convenient!), I'm curious where the other patch comes from.
>> 
>> Patches tend to evolve over time, so checking what happened "upstream"
>> can be handy when you're stumped. See e.g. any CVE patch for
>> examples :)
>> 
>> Other than that looks good!
>
> Here is an updated patch with a link to archlinux' patch. You were the
> one to add the other patch, and I can't find it. I'm also curious where
> it comes from :p

Hehe...I deliberately did not add a reference just to prove this point!

...but I remember now, it is this commit, which I don't think will hit a
release until Android 8 if I've understood their branching correctly:

https://android.googlesource.com/platform/system/core/+/e5dd71a290f664d3f3bf0dd8a4bad411dc7ad416

Please add it and push! :D


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#26522: gnu: Add adb
  2017-04-17 15:09         ` Marius Bakke
@ 2017-04-18  8:21           ` Ludovic Courtès
  0 siblings, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2017-04-18  8:21 UTC (permalink / raw)
  To: Marius Bakke; +Cc: 26522

Marius Bakke <mbakke@fastmail.com> skribis:

> Please add it and push! :D

Awesome, nice work gentlefolks!

Ludo’.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#26522:
  2017-04-15 16:31 bug#26522: gnu: Add adb Julien Lepiller
  2017-04-15 18:02 ` Marius Bakke
@ 2017-04-20  8:33 ` julien lepiller
  1 sibling, 0 replies; 8+ messages in thread
From: julien lepiller @ 2017-04-20  8:33 UTC (permalink / raw)
  To: 26522-done



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-04-20  8:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-15 16:31 bug#26522: gnu: Add adb Julien Lepiller
2017-04-15 18:02 ` Marius Bakke
2017-04-16  9:22   ` Julien Lepiller
2017-04-16 21:54     ` Marius Bakke
2017-04-17  8:40       ` Julien Lepiller
2017-04-17 15:09         ` Marius Bakke
2017-04-18  8:21           ` Ludovic Courtès
2017-04-20  8:33 ` bug#26522: julien lepiller

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).