From 46611926b2e150779c35926e3e63bcf98743b4ed Mon Sep 17 00:00:00 2001 From: Sebastien Gonzalve Date: Thu, 30 Apr 2015 15:51:16 +0200 Subject: [PATCH 1/4] Android: Remove the empty lib include trick hack The code was using a hack to export headers only through a empty lib. This trick does not work on darwin hosts. This patch remove this hack and use the standard export C include dir. Change-Id: I34a69a6f66479b3a499efc4a648c43f022e1c472 Signed-off-by: Sebastien Gonzalve --- parameter/Android.mk | 38 ++++---------------------------------- xmlserializer/Android.mk | 21 ++++----------------- 2 files changed, 8 insertions(+), 51 deletions(-) diff --git a/parameter/Android.mk b/parameter/Android.mk index 90e33f09b..5ed9fa03a 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -143,6 +143,8 @@ include $(CLEAR_VARS) LOCAL_COPY_HEADERS_TO := $(common_copy_headers_to) LOCAL_COPY_HEADERS := $(common_copy_headers) +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) + LOCAL_CFLAGS := $(common_cflags) LOCAL_SRC_FILES := $(common_src_files) @@ -170,6 +172,8 @@ include $(CLEAR_VARS) LOCAL_COPY_HEADERS_TO := $(common_copy_headers_to) LOCAL_COPY_HEADERS := $(common_copy_headers) +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) + LOCAL_CFLAGS := $(common_cflags) -O0 -ggdb LOCAL_SRC_FILES := $(common_src_files) @@ -188,37 +192,3 @@ LOCAL_LDLIBS += -ldl LOCAL_CLANG := false include $(BUILD_HOST_SHARED_LIBRARY) - -################################ -# Export includes for plugins (Target build) - -include $(CLEAR_VARS) - -LOCAL_MODULE := $(common_module)_includes -LOCAL_MODULE_OWNER := intel - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) - -LOCAL_STATIC_LIBRARIES := \ - libxmlserializer \ - libpfw_utility \ - libxml2 - -include $(BUILD_STATIC_LIBRARY) - -################################ -# Export includes for plugins (Host build) - -include $(CLEAR_VARS) - -LOCAL_MODULE := $(common_module)_includes_host -LOCAL_MODULE_OWNER := intel - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) - -LOCAL_STATIC_LIBRARIES := \ - libxmlserializer_host \ - libpfw_utility_host \ - libxml2 - -include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/xmlserializer/Android.mk b/xmlserializer/Android.mk index 37a8241df..de32991f0 100644 --- a/xmlserializer/Android.mk +++ b/xmlserializer/Android.mk @@ -63,6 +63,8 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(common_src_files) +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) + LOCAL_MODULE := $(common_module) LOCAL_MODULE_OWNER := intel LOCAL_MODULE_TAGS := $(common_module_tags) @@ -86,6 +88,8 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := $(common_src_files) +LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) + LOCAL_MODULE := $(common_module)_host LOCAL_MODULE_OWNER := intel LOCAL_MODULE_TAGS := $(common_module_tags) @@ -101,20 +105,3 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) include $(BUILD_HOST_STATIC_LIBRARY) -################################ -# Export includes for plugins (Target build) -include $(CLEAR_VARS) -LOCAL_MODULE := $(common_module)_includes -LOCAL_MODULE_OWNER := intel -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) -LOCAL_STATIC_LIBRARIES := libxml2 -include $(BUILD_STATIC_LIBRARY) - -################################ -# Export includes for plugins (Host build) -include $(CLEAR_VARS) -LOCAL_MODULE := $(common_module)_includes -LOCAL_MODULE_OWNER := intel -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) -LOCAL_STATIC_LIBRARIES := libxml2 -include $(BUILD_HOST_STATIC_LIBRARY) From 2a4abdc97166ab57702226f4a8203402f35eb758 Mon Sep 17 00:00:00 2001 From: Sebastien Gonzalve Date: Tue, 28 Apr 2015 14:47:53 +0200 Subject: [PATCH 2/4] try to fix swig generation for Darwin Pathes were hardcoded to linux which make compilation fail on MacOs. This patch gets the correct host build arch to fix compilation under MacOSx. Change-Id: Ie49d179cf1e7a54fa862f8b2f0996d7945884b96 Signed-off-by: Sebastien Gonzalve --- bindings/python/Android.mk | 15 +++++++++++++-- support/android/build_pfw_settings.mk | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bindings/python/Android.mk b/bindings/python/Android.mk index 977ffb79c..1529873c5 100644 --- a/bindings/python/Android.mk +++ b/bindings/python/Android.mk @@ -47,8 +47,13 @@ LOCAL_32_BIT_ONLY := true LOCAL_SHARED_LIBRARIES := libparameter_host LOCAL_STATIC_LIBRARIES := libxmlserializer_host +# python is only available in 32bits for now, thus arch is forced to 32bits +PYTHON_INSTALL_PATH := prebuilts/python/$(HOST_OS)-x86/2.7.5/ +PYTHON_INCLUDES_PATH := $(PYTHON_INSTALL_PATH)/include/python2.7 +PYTHON_BIN_PATH := $(PYTHON_INSTALL_PATH)/bin + LOCAL_C_INCLUDES := \ - prebuilts/python/linux-x86/2.7.5/include/python2.7 \ + $(PYTHON_INCLUDES_PATH) \ $(HOST_OUT_HEADERS)/parameter # The 'unused-but-set-variable' warning must be disabled because SWIG generates @@ -74,6 +79,12 @@ LOCAL_GENERATED_SOURCES := $(generated-sources-dir)/pfw_wrap.cxx $(generated-sou LOCAL_EXPORT_C_INCLUDE_DIRS := $(generated-sources-dir) +# Careful, we need to invoque the android python config not the host's one. +# BTW, the intenal install directory of python is hardcoded to a dummy value, +# thus we need to manually add the correct path to libs to the library list. +LOCAL_LDLIBS += $(shell $(PYTHON_BIN_PATH)/python $(PYTHON_BIN_PATH)/python-config --ldflags) \ + -L $(PYTHON_INSTALL_PATH)/lib/ + $(generated-sources-dir)/pfw_wrap.h: $(generated-sources-dir)/pfw_wrap.cxx # The PyPfw.py file is generated in the directory given by -outdir switch, thus @@ -82,7 +93,7 @@ $(generated-sources-dir)/pfw_wrap.cxx: $(LOCAL_PATH)/pfw.i @echo "Generating Python binding files" mkdir -p $(dir $@) # surprisingly, path is not generated by build system mkdir -p $(HOST_LIBRARY_PATH) - prebuilts/misc/linux-x86_64/swig/swig \ + prebuilts/misc/$(HOST_OS)-$(HOST_ARCH)/swig/swig \ -Iprebuilts/misc/common/swig/include/2.0.11/python/ \ -Iprebuilts/misc/common/swig/include/2.0.11/ \ -Wall -Werror -v -python -c++ -outdir $(HOST_LIBRARY_PATH)/ -o $@ $^ diff --git a/support/android/build_pfw_settings.mk b/support/android/build_pfw_settings.mk index 482c56d58..a9679d95f 100644 --- a/support/android/build_pfw_settings.mk +++ b/support/android/build_pfw_settings.mk @@ -35,7 +35,8 @@ $(LOCAL_BUILT_MODULE): MY_TOOL := $(HOST_OUT)/bin/domainGenerator.py # As of Android K, python is available as prebuilt. We can't reliably use the # host's default python because the low-level python binding has been compiled # against Android's Python headers. -$(LOCAL_BUILT_MODULE): MY_PYTHON := prebuilts/python/linux-x86/2.7.5/bin/python +# BTW, python is only available in 32bits for now, thus arch is forces to 32bits +$(LOCAL_BUILT_MODULE): MY_PYTHON := prebuilts/python/$(HOST_OS)-x86/2.7.5/bin/python # The parameter-framework binding module is installed on these locations on # Android (On 64bit machines, PyPfw.py is installed in the 'lib64' directory # and _PyPfw.so is installed in the 'lib' directory, hence the need for these From c7cf609165803caec9cb7e24457f846eba3b50d3 Mon Sep 17 00:00:00 2001 From: Sebastien Gonzalve Date: Wed, 29 Apr 2015 17:58:16 +0200 Subject: [PATCH 3/4] Remove useless NOSIGNAL flags Those signals are useless and causes problems on darwin (BSD) compilation. Actually on recv, the flag is ignored on Linux, and on send, it should not be necessary if we do not write on a closed socket. Thus patch thus removes the flags and close the socket on error. --- remote-processor/Socket.cpp | 42 +++++++++++++++++++++++++++---------- remote-processor/Socket.h | 1 + 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/remote-processor/Socket.cpp b/remote-processor/Socket.cpp index b36d32fc8..dd4551be5 100644 --- a/remote-processor/Socket.cpp +++ b/remote-processor/Socket.cpp @@ -39,8 +39,9 @@ #include #include #include +#include -CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0)) +CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0)), mSendFlag(0) { assert(_iSockFd != -1); @@ -50,6 +51,19 @@ CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0)) // they are ready to be sent, instead of waiting for more data on the // socket. setsockopt(_iSockFd, IPPROTO_TCP, TCP_NODELAY, (char *)&iNoDelay, sizeof(iNoDelay)); + + // Disable sigpipe reception on send +# if not defined(SIGPIPE) + // Pipe signal does not exist, there no sigpipe to ignore on send +# elif defined(SO_NOSIGPIPE) + const int set = 1; + setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set)); +# elif defined(MSG_NOSIGNAL) + // Use flag NOSIGNAL on send call + mSendFlag = MSG_NOSIGNAL; +# else +# error Can no disable SIGPIPE +# endif } CSocket::CSocket(int iSockId) : _iSockFd(iSockId) @@ -59,7 +73,11 @@ CSocket::CSocket(int iSockId) : _iSockFd(iSockId) CSocket::~CSocket() { - close(_iSockFd); + // fd might be invalide if send had an error. + // valgrind displays a warning if closing an invalid fd. + if (_iSockFd != -1) { + close(_iSockFd); + } } // Socket address init @@ -108,7 +126,7 @@ bool CSocket::read(void* pvData, uint32_t uiSize) while (uiSize) { - int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL); + int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, 0); switch (iAccessedSize) { case 0: @@ -140,17 +158,19 @@ bool CSocket::write(const void* pvData, uint32_t uiSize) while (uiSize) { - int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL); + int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, mSendFlag); if (iAccessedSize == -1) { - if (errno == ECONNRESET) { - // Peer has disconnected - _disconnected = true; - } - // errno == EINTR => The send system call was interrupted, try again - if (errno != EINTR) { - return false; + if (errno == EINTR) { + // The send system call was interrupted, try again + continue; } + + // An error occured, forget this socket + _disconnected = true; + close(_iSockFd); + _iSockFd = -1; // Avoid writing again on the same socket + return false; } else { uiSize -= iAccessedSize; uiOffset += iAccessedSize; diff --git a/remote-processor/Socket.h b/remote-processor/Socket.h index 00bd8bc39..8c3fb9f31 100644 --- a/remote-processor/Socket.h +++ b/remote-processor/Socket.h @@ -108,4 +108,5 @@ class CSocket * See hasPeerDisconnected for more details. */ bool _disconnected; + int mSendFlag; }; From df6984dc3d5b62f4d207fe1976a3a62fd797ee0a Mon Sep 17 00:00:00 2001 From: Sebastien Gonzalve Date: Mon, 4 May 2015 14:43:43 +0200 Subject: [PATCH 4/4] Android: workaround link problem on darwin The lib in prebuild/darwin-x86 is in fact a 64bit lib and link fails. This patch make the host binary use the host python to link (this is quite wrong as the version may not be compatible with the android swig version Change-Id: Ic6ed36a498904e082c1c60f05cc54827ca6ea705 Signed-off-by: Sebastien Gonzalve --- bindings/python/Android.mk | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/bindings/python/Android.mk b/bindings/python/Android.mk index 1529873c5..97afde5ea 100644 --- a/bindings/python/Android.mk +++ b/bindings/python/Android.mk @@ -79,11 +79,25 @@ LOCAL_GENERATED_SOURCES := $(generated-sources-dir)/pfw_wrap.cxx $(generated-sou LOCAL_EXPORT_C_INCLUDE_DIRS := $(generated-sources-dir) -# Careful, we need to invoque the android python config not the host's one. -# BTW, the intenal install directory of python is hardcoded to a dummy value, -# thus we need to manually add the correct path to libs to the library list. -LOCAL_LDLIBS += $(shell $(PYTHON_BIN_PATH)/python $(PYTHON_BIN_PATH)/python-config --ldflags) \ +# Get the interpreter ld options. +ifeq ($(HOST_OS), darwin) + # Contrary to linux, on darwin, a python 64 bit executable is installed + # in the x86 prebuild directory, + # As all host libraries are 32 bit in android. We can not link and host + # python module against the prebuild python library. + # + # As a *dirty* workaround, use the system's python configuration and hope + # it will be compatible with the prebuild python interpreter used at runtime. + # To summarize the prebuild python (64 bit?) interpreter will load a + # python native module (32bit) linked with the host (32 bit ?) python library. + LOCAL_LDLIBS += $(shell python-config --ldflags) +else + # Careful, we need to invoke the android python config not the host's one. + # Unfortunately, the internal install directory of python is hardcoded to a dummy value, + # As a workaround, we need to manually add the correct path to libs to the library list. + LOCAL_LDLIBS += $(shell $(PYTHON_BIN_PATH)/python $(PYTHON_BIN_PATH)/python-config --ldflags) \ -L $(PYTHON_INSTALL_PATH)/lib/ +endif $(generated-sources-dir)/pfw_wrap.h: $(generated-sources-dir)/pfw_wrap.cxx