From 2e1e789e2ac34402810321334537a3dd4992705c Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 23 Mar 2018 13:03:28 -0700 Subject: [PATCH 1/2] adb: fix windows test build. The switch over to soong unintentionally turned off building the Windows tests (and there's a bug preventing them from being turned on). Preemptively fix the build breakages that'll happen when we turn them back on. Test: mma with Android.bp 's/cc_test_host/cc_binary_host' hacks Change-Id: I6582cfc61b96052537d50d8ba90533dbb66e3e1d --- adb/Android.bp | 5 ++++- adb/fdevent_test.cpp | 1 + adb/sysdeps.h | 24 ++++++++++-------------- adb/sysdeps_win32.cpp | 9 ++++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/adb/Android.bp b/adb/Android.bp index bbf7cb42c..63c4d96d1 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -72,8 +72,11 @@ cc_defaults { "-DUNICODE=1", "-D_UNICODE=1", - // -std=gnu++14 doesn't set _GNU_SOURCE on Windows. + // -std=gnu++11 doesn't set _GNU_SOURCE on Windows. "-D_GNU_SOURCE", + + // MinGW hides some things behind _POSIX_SOURCE. + "-D_POSIX_SOURCE", ], }, }, diff --git a/adb/fdevent_test.cpp b/adb/fdevent_test.cpp index 95dc4c248..e3d5a356b 100644 --- a/adb/fdevent_test.cpp +++ b/adb/fdevent_test.cpp @@ -26,6 +26,7 @@ #include "adb_io.h" #include "fdevent_test.h" +#include "sysdeps/memory.h" class FdHandler { public: diff --git a/adb/sysdeps.h b/adb/sysdeps.h index fd08ad8b2..3be99f635 100644 --- a/adb/sysdeps.h +++ b/adb/sysdeps.h @@ -106,14 +106,14 @@ extern int adb_mkdir(const std::string& path, int mode); #define mkdir ___xxx_mkdir // See the comments for the !defined(_WIN32) versions of adb_*(). -extern int adb_open(const char* path, int options); -extern int adb_creat(const char* path, int mode); -extern int adb_read(int fd, void* buf, int len); -extern int adb_write(int fd, const void* buf, int len); -extern int adb_lseek(int fd, int pos, int where); -extern int adb_shutdown(int fd); -extern int adb_close(int fd); -extern int adb_register_socket(SOCKET s); +extern int adb_open(const char* path, int options); +extern int adb_creat(const char* path, int mode); +extern int adb_read(int fd, void* buf, int len); +extern int adb_write(int fd, const void* buf, int len); +extern int adb_lseek(int fd, int pos, int where); +extern int adb_shutdown(int fd, int direction = SHUT_RDWR); +extern int adb_close(int fd); +extern int adb_register_socket(SOCKET s); // See the comments for the !defined(_WIN32) version of unix_close(). static __inline__ int unix_close(int fd) @@ -414,14 +414,10 @@ static __inline__ int adb_open( const char* pathname, int options ) #undef open #define open ___xxx_open -static __inline__ int adb_shutdown(int fd) -{ - return shutdown(fd, SHUT_RDWR); -} -static __inline__ int adb_shutdown(int fd, int direction) -{ +static __inline__ int adb_shutdown(int fd, int direction = SHUT_RDWR) { return shutdown(fd, direction); } + #undef shutdown #define shutdown ____xxx_shutdown diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp index cd7d187aa..62f4ac831 100644 --- a/adb/sysdeps_win32.cpp +++ b/adb/sysdeps_win32.cpp @@ -1011,9 +1011,8 @@ int adb_socket_get_local_port(int fd) { return ntohs(reinterpret_cast(&addr_storage)->sin_port); } -int adb_shutdown(int fd) -{ - FH f = _fh_from_int(fd, __func__); +int adb_shutdown(int fd, int direction) { + FH f = _fh_from_int(fd, __func__); if (!f || f->clazz != &_fh_socket_class) { D("adb_shutdown: invalid fd %d", fd); @@ -1021,8 +1020,8 @@ int adb_shutdown(int fd) return -1; } - D( "adb_shutdown: %s", f->name); - if (shutdown(f->fh_socket, SD_BOTH) == SOCKET_ERROR) { + D("adb_shutdown: %s", f->name); + if (shutdown(f->fh_socket, direction) == SOCKET_ERROR) { const DWORD err = WSAGetLastError(); D("socket shutdown fd %d failed: %s", fd, android::base::SystemErrorCodeToString(err).c_str()); From f8a97c1f14cbd3de441637effa0dee20aefc3822 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 23 Mar 2018 15:37:20 -0700 Subject: [PATCH 2/2] adb: start building windows test again. Test: mma Change-Id: Iea2a3055cc3642905a1bbdd18550a9fc12702da8 --- adb/Android.bp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/adb/Android.bp b/adb/Android.bp index 63c4d96d1..d81bb4b26 100644 --- a/adb/Android.bp +++ b/adb/Android.bp @@ -78,6 +78,12 @@ cc_defaults { // MinGW hides some things behind _POSIX_SOURCE. "-D_POSIX_SOURCE", ], + + host_ldlibs: [ + "-lws2_32", + "-lgdi32", + "-luserenv", + ], }, }, } @@ -176,6 +182,13 @@ cc_test_host { "libdiagnose_usb", "libusb", ], + + target: { + windows: { + enabled: true, + shared_libs: ["AdbWinApi"], + }, + }, } cc_binary_host { @@ -223,11 +236,6 @@ cc_binary_host { windows: { enabled: true, ldflags: ["-municode"], - host_ldlibs: [ - "-lws2_32", - "-lgdi32", - ], - shared_libs: ["AdbWinApi"], required: [ "AdbWinUsbApi",