From 85b5d76c2b9e3e4ccdd28cb724e5306d3c7ad311 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 29 Jun 2015 10:15:04 -0700 Subject: [PATCH 1/8] php minor script fix --- src/php/bin/determine_extension_dir.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/php/bin/determine_extension_dir.sh b/src/php/bin/determine_extension_dir.sh index 6fc392afc0a..6bbd934bf13 100755 --- a/src/php/bin/determine_extension_dir.sh +++ b/src/php/bin/determine_extension_dir.sh @@ -29,15 +29,15 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set -e -default_extension_dir=$(php -i | grep extension_dir | sed 's/.*=> //g') +default_extension_dir=$(php-config --extension-dir) if command -v brew >/dev/null && [ -d $(brew --prefix)/opt/grpc-php ]; then # homebrew and the grpc-php formula are installed extension_dir="-d extension_dir="$(brew --prefix)/opt/grpc-php -elif [ ! -f $default_extension_dir/grpc.so ]; then +elif [ ! -e $default_extension_dir/grpc.so ]; then # the grpc extension is not found in the default PHP extension dir # try the source modules directory module_dir=../ext/grpc/modules - if [ ! -f $module_dir/grpc.so ]; then + if [ ! -e $module_dir/grpc.so ]; then echo "Please run 'phpize && ./configure && make' from ext/grpc first" exit 1 fi From 24e2f4ad84d1d27e08f32391d7cdfb9b0728ce0e Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 29 Jun 2015 11:12:01 -0700 Subject: [PATCH 2/8] Added pkg-config checking to Makefile where possible --- BUILD | 6 ++++ Makefile | 45 +++++++++++++++++++++--- templates/Makefile.template | 45 +++++++++++++++++++++--- tools/run_tests/sources_and_headers.json | 16 +++++++++ 4 files changed, 102 insertions(+), 10 deletions(-) diff --git a/BUILD b/BUILD index 2110d02abe7..7273b17d739 100644 --- a/BUILD +++ b/BUILD @@ -978,11 +978,15 @@ objc_library( "src/core/transport/chttp2/hpack_parser.c", "src/core/transport/chttp2/hpack_table.c", "src/core/transport/chttp2/huffsyms.c", + "src/core/transport/chttp2/incoming_metadata.c", + "src/core/transport/chttp2/parsing.c", "src/core/transport/chttp2/status_conversion.c", "src/core/transport/chttp2/stream_encoder.c", + "src/core/transport/chttp2/stream_lists.c", "src/core/transport/chttp2/stream_map.c", "src/core/transport/chttp2/timeout_encoding.c", "src/core/transport/chttp2/varint.c", + "src/core/transport/chttp2/writing.c", "src/core/transport/chttp2_transport.c", "src/core/transport/metadata.c", "src/core/transport/stream_op.c", @@ -1071,6 +1075,8 @@ objc_library( "src/core/transport/chttp2/hpack_table.h", "src/core/transport/chttp2/http2_errors.h", "src/core/transport/chttp2/huffsyms.h", + "src/core/transport/chttp2/incoming_metadata.h", + "src/core/transport/chttp2/internal.h", "src/core/transport/chttp2/status_conversion.h", "src/core/transport/chttp2/stream_encoder.h", "src/core/transport/chttp2/stream_map.h", diff --git a/Makefile b/Makefile index 1d796b41982..5904f77d113 100644 --- a/Makefile +++ b/Makefile @@ -331,6 +331,8 @@ HOST_LDLIBS = $(LDLIBS) # These are automatically computed variables. # There shouldn't be any need to change anything from now on. +HAS_PKG_CONFIG = $(shell command -v pkg-config >/dev/null 2>&1 && echo true || echo false) + ifeq ($(SYSTEM),MINGW32) SHARED_EXT = dll endif @@ -355,6 +357,13 @@ ifeq ($(SYSTEM),Darwin) OPENSSL_REQUIRES_DL = true endif +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_ALPN_CHECK_CMD = pkg-config --atleast-version=1.0.2 openssl +ZLIB_CHECK_CMD = pkg-config --exists zlib +PERFTOOLS_CHECK_CMD = pkg-config --exists profiler +PROTOBUF_CHECK_CMD = pkg-config --atleast-version=3.0.0-alpha-3 protobuf +else # HAS_PKG_CONFIG + ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else @@ -365,15 +374,18 @@ OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/ope ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) -PROTOC_CHECK_CMD = which protoc > /dev/null -PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 -DTRACE_CHECK_CMD = which dtrace > /dev/null -SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) ifeq ($(OPENSSL_REQUIRES_DL),true) OPENSSL_ALPN_CHECK_CMD += -ldl endif +endif # HAS_PKG_CONFIG + +PROTOC_CHECK_CMD = which protoc > /dev/null +PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 +DTRACE_CHECK_CMD = which dtrace > /dev/null +SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) + ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_PERFTOOLS),true) @@ -442,6 +454,11 @@ LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib else DEP_MISSING += zlib endif +else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags zlib) +LDFLAGS += $(shell pkg-config --libs-only-L zlib) +endif endif ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false) @@ -458,13 +475,22 @@ else NO_SECURE = true endif else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags openssl) +LDFLAGS += $(shell pkg-config --libs-only-L openssl) +else LIBS_SECURE = $(OPENSSL_LIBS) ifeq ($(OPENSSL_REQUIRES_DL),true) LIBS_SECURE += dl endif endif +endif +ifeq ($(HAS_PKG_CONFIG),true) +LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl) +else LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) +endif ifeq ($(HAS_SYSTEM_PROTOBUF),false) ifeq ($(HAS_EMBEDDED_PROTOBUF),true) @@ -476,14 +502,23 @@ else NO_PROTOBUF = true endif else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags protobuf) +LDFLAGS += $(shell pkg-config --libs-only-L protobuf) +endif endif LIBS_PROTOBUF = protobuf LIBS_PROTOC = protoc protobuf -LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) +ifeq ($(HAS_PKG_CONFIG),true) +LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf) +else +LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) +endif + ifeq ($(MAKECMDGOALS),clean) NO_DEPS = true endif diff --git a/templates/Makefile.template b/templates/Makefile.template index ebe207f1918..5c1d90b9ada 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -345,6 +345,8 @@ HOST_LDLIBS = $(LDLIBS) # These are automatically computed variables. # There shouldn't be any need to change anything from now on. +HAS_PKG_CONFIG = $(shell command -v pkg-config >/dev/null 2>&1 && echo true || echo false) + ifeq ($(SYSTEM),MINGW32) SHARED_EXT = dll endif @@ -369,6 +371,13 @@ ifeq ($(SYSTEM),Darwin) OPENSSL_REQUIRES_DL = true endif +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_ALPN_CHECK_CMD = pkg-config --atleast-version=1.0.2 openssl +ZLIB_CHECK_CMD = pkg-config --exists zlib +PERFTOOLS_CHECK_CMD = pkg-config --exists profiler +PROTOBUF_CHECK_CMD = pkg-config --atleast-version=3.0.0-alpha-3 protobuf +else # HAS_PKG_CONFIG + ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else @@ -379,15 +388,18 @@ OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/ope ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) -PROTOC_CHECK_CMD = which protoc > /dev/null -PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 -DTRACE_CHECK_CMD = which dtrace > /dev/null -SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) ifeq ($(OPENSSL_REQUIRES_DL),true) OPENSSL_ALPN_CHECK_CMD += -ldl endif +endif # HAS_PKG_CONFIG + +PROTOC_CHECK_CMD = which protoc > /dev/null +PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 +DTRACE_CHECK_CMD = which dtrace > /dev/null +SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) + ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_PERFTOOLS),true) @@ -456,6 +468,11 @@ LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib else DEP_MISSING += zlib endif +else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags zlib) +LDFLAGS += $(shell pkg-config --libs-only-L zlib) +endif endif ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false) @@ -472,13 +489,22 @@ else NO_SECURE = true endif else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags openssl) +LDFLAGS += $(shell pkg-config --libs-only-L openssl) +else LIBS_SECURE = $(OPENSSL_LIBS) ifeq ($(OPENSSL_REQUIRES_DL),true) LIBS_SECURE += dl endif endif +endif +ifeq ($(HAS_PKG_CONFIG),true) +LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl) +else LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) +endif ifeq ($(HAS_SYSTEM_PROTOBUF),false) ifeq ($(HAS_EMBEDDED_PROTOBUF),true) @@ -490,14 +516,23 @@ else NO_PROTOBUF = true endif else +ifeq ($(HAS_PKG_CONFIG),true) +CPPFLAGS += $(shell pkg-config --cflags protobuf) +LDFLAGS += $(shell pkg-config --libs-only-L protobuf) +endif endif LIBS_PROTOBUF = protobuf LIBS_PROTOC = protoc protobuf -LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) +ifeq ($(HAS_PKG_CONFIG),true) +LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf) +else +LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) +endif + ifeq ($(MAKECMDGOALS),clean) NO_DEPS = true endif diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 5c74bf1eea3..eb2514fa46d 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -8717,6 +8717,8 @@ "src/core/transport/chttp2/hpack_table.h", "src/core/transport/chttp2/http2_errors.h", "src/core/transport/chttp2/huffsyms.h", + "src/core/transport/chttp2/incoming_metadata.h", + "src/core/transport/chttp2/internal.h", "src/core/transport/chttp2/status_conversion.h", "src/core/transport/chttp2/stream_encoder.h", "src/core/transport/chttp2/stream_map.h", @@ -8933,16 +8935,22 @@ "src/core/transport/chttp2/http2_errors.h", "src/core/transport/chttp2/huffsyms.c", "src/core/transport/chttp2/huffsyms.h", + "src/core/transport/chttp2/incoming_metadata.c", + "src/core/transport/chttp2/incoming_metadata.h", + "src/core/transport/chttp2/internal.h", + "src/core/transport/chttp2/parsing.c", "src/core/transport/chttp2/status_conversion.c", "src/core/transport/chttp2/status_conversion.h", "src/core/transport/chttp2/stream_encoder.c", "src/core/transport/chttp2/stream_encoder.h", + "src/core/transport/chttp2/stream_lists.c", "src/core/transport/chttp2/stream_map.c", "src/core/transport/chttp2/stream_map.h", "src/core/transport/chttp2/timeout_encoding.c", "src/core/transport/chttp2/timeout_encoding.h", "src/core/transport/chttp2/varint.c", "src/core/transport/chttp2/varint.h", + "src/core/transport/chttp2/writing.c", "src/core/transport/chttp2_transport.c", "src/core/transport/chttp2_transport.h", "src/core/transport/metadata.c", @@ -9116,6 +9124,8 @@ "src/core/transport/chttp2/hpack_table.h", "src/core/transport/chttp2/http2_errors.h", "src/core/transport/chttp2/huffsyms.h", + "src/core/transport/chttp2/incoming_metadata.h", + "src/core/transport/chttp2/internal.h", "src/core/transport/chttp2/status_conversion.h", "src/core/transport/chttp2/stream_encoder.h", "src/core/transport/chttp2/stream_map.h", @@ -9296,16 +9306,22 @@ "src/core/transport/chttp2/http2_errors.h", "src/core/transport/chttp2/huffsyms.c", "src/core/transport/chttp2/huffsyms.h", + "src/core/transport/chttp2/incoming_metadata.c", + "src/core/transport/chttp2/incoming_metadata.h", + "src/core/transport/chttp2/internal.h", + "src/core/transport/chttp2/parsing.c", "src/core/transport/chttp2/status_conversion.c", "src/core/transport/chttp2/status_conversion.h", "src/core/transport/chttp2/stream_encoder.c", "src/core/transport/chttp2/stream_encoder.h", + "src/core/transport/chttp2/stream_lists.c", "src/core/transport/chttp2/stream_map.c", "src/core/transport/chttp2/stream_map.h", "src/core/transport/chttp2/timeout_encoding.c", "src/core/transport/chttp2/timeout_encoding.h", "src/core/transport/chttp2/varint.c", "src/core/transport/chttp2/varint.h", + "src/core/transport/chttp2/writing.c", "src/core/transport/chttp2_transport.c", "src/core/transport/chttp2_transport.h", "src/core/transport/metadata.c", From da7a994a4dd5db80d77b2c2b453792a1a358fb9f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 29 Jun 2015 14:57:37 -0700 Subject: [PATCH 3/8] Fixed some linking problems --- Makefile | 55 ++++++++++++++++++++++++------------- templates/Makefile.template | 55 ++++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 5904f77d113..7760ebea734 100644 --- a/Makefile +++ b/Makefile @@ -461,7 +461,26 @@ LDFLAGS += $(shell pkg-config --libs-only-L zlib) endif endif -ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false) +OPENSSL_PKG_CONFIG = false + +ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags openssl) $(CPPFLAGS) +LDFLAGS_OPENSSL_PKG_CONFIG = $(shell pkg-config --libs-only-L openssl) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) +LDFLAGS_OPENSSL_PKG_CONFIG += $(shell pkg-config --libs-only-L openssl | sed s/L/Wl,-rpath,/) +endif +endif +LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) +else +LIBS_SECURE = $(OPENSSL_LIBS) +ifeq ($(OPENSSL_REQUIRES_DL),true) +LIBS_SECURE += dl +endif +endif +else ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true) OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a @@ -474,25 +493,28 @@ endif else NO_SECURE = true endif -else -ifeq ($(HAS_PKG_CONFIG),true) -CPPFLAGS += $(shell pkg-config --cflags openssl) -LDFLAGS += $(shell pkg-config --libs-only-L openssl) -else -LIBS_SECURE = $(OPENSSL_LIBS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl -endif -endif endif -ifeq ($(HAS_PKG_CONFIG),true) +ifeq ($(OPENSSL_PKG_CONFIG),true) LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl) else LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) endif -ifeq ($(HAS_SYSTEM_PROTOBUF),false) +PROTOBUF_PKG_CONFIG = false + +ifeq ($(HAS_SYSTEM_PROTOBUF),true) +ifeq ($(HAS_PKG_CONFIG),true) +PROTOBUF_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags protobuf) $(CPPFLAGS) +LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell pkg-config --libs-only-L protobuf) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) +LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell pkg-config --libs-only-L protobuf | sed s/L/Wl,-rpath,/) +endif +endif +endif +else ifeq ($(HAS_EMBEDDED_PROTOBUF),true) PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) @@ -501,11 +523,6 @@ PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc else NO_PROTOBUF = true endif -else -ifeq ($(HAS_PKG_CONFIG),true) -CPPFLAGS += $(shell pkg-config --cflags protobuf) -LDFLAGS += $(shell pkg-config --libs-only-L protobuf) -endif endif LIBS_PROTOBUF = protobuf @@ -513,7 +530,7 @@ LIBS_PROTOC = protoc protobuf HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) -ifeq ($(HAS_PKG_CONFIG),true) +ifeq ($(PROTOBUF_PKG_CONFIG),true) LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf) else LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) diff --git a/templates/Makefile.template b/templates/Makefile.template index 5c1d90b9ada..3b04d7d0415 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -475,7 +475,26 @@ LDFLAGS += $(shell pkg-config --libs-only-L zlib) endif endif -ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),false) +OPENSSL_PKG_CONFIG = false + +ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) +ifeq ($(HAS_PKG_CONFIG),true) +OPENSSL_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags openssl) $(CPPFLAGS) +LDFLAGS_OPENSSL_PKG_CONFIG = $(shell pkg-config --libs-only-L openssl) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) +LDFLAGS_OPENSSL_PKG_CONFIG += $(shell pkg-config --libs-only-L openssl | sed s/L/Wl,-rpath,/) +endif +endif +LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) +else +LIBS_SECURE = $(OPENSSL_LIBS) +ifeq ($(OPENSSL_REQUIRES_DL),true) +LIBS_SECURE += dl +endif +endif +else ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true) OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a @@ -488,25 +507,28 @@ endif else NO_SECURE = true endif -else -ifeq ($(HAS_PKG_CONFIG),true) -CPPFLAGS += $(shell pkg-config --cflags openssl) -LDFLAGS += $(shell pkg-config --libs-only-L openssl) -else -LIBS_SECURE = $(OPENSSL_LIBS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl -endif -endif endif -ifeq ($(HAS_PKG_CONFIG),true) +ifeq ($(OPENSSL_PKG_CONFIG),true) LDLIBS_SECURE += $(shell pkg-config --libs-only-l openssl) else LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) endif -ifeq ($(HAS_SYSTEM_PROTOBUF),false) +PROTOBUF_PKG_CONFIG = false + +ifeq ($(HAS_SYSTEM_PROTOBUF),true) +ifeq ($(HAS_PKG_CONFIG),true) +PROTOBUF_PKG_CONFIG = true +CPPFLAGS := $(shell pkg-config --cflags protobuf) $(CPPFLAGS) +LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell pkg-config --libs-only-L protobuf) +ifeq ($(SYSTEM),Linux) +ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) +LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell pkg-config --libs-only-L protobuf | sed s/L/Wl,-rpath,/) +endif +endif +endif +else ifeq ($(HAS_EMBEDDED_PROTOBUF),true) PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) @@ -515,11 +537,6 @@ PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc else NO_PROTOBUF = true endif -else -ifeq ($(HAS_PKG_CONFIG),true) -CPPFLAGS += $(shell pkg-config --cflags protobuf) -LDFLAGS += $(shell pkg-config --libs-only-L protobuf) -endif endif LIBS_PROTOBUF = protobuf @@ -527,7 +544,7 @@ LIBS_PROTOC = protoc protobuf HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) -ifeq ($(HAS_PKG_CONFIG),true) +ifeq ($(PROTOBUF_PKG_CONFIG),true) LDLIBS_PROTOBUF += $(shell pkg-config --libs-only-l protobuf) else LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) From a6cfa0ad3b1bbed9aae1836f3c0ab0cb1bf581d9 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Mon, 29 Jun 2015 15:06:08 -0700 Subject: [PATCH 4/8] Fix #2248 --- src/python/src/grpc/_adapter/_intermediary_low.py | 3 ++- src/python/src/grpc/_adapter/_intermediary_low_test.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/python/src/grpc/_adapter/_intermediary_low.py b/src/python/src/grpc/_adapter/_intermediary_low.py index 6b96aef1d34..3c7f0a26197 100644 --- a/src/python/src/grpc/_adapter/_intermediary_low.py +++ b/src/python/src/grpc/_adapter/_intermediary_low.py @@ -144,10 +144,11 @@ class Call(object): self._metadata.append((key, value)) def premetadata(self): - return self._internal.start_batch([ + result = self._internal.start_batch([ _types.OpArgs.send_initial_metadata(self._metadata) ], _IGNORE_ME_TAG) self._metadata = [] + return result def read(self, tag): return self._internal.start_batch([ diff --git a/src/python/src/grpc/_adapter/_intermediary_low_test.py b/src/python/src/grpc/_adapter/_intermediary_low_test.py index 1a9b0c69f3c..27a5b82e9c4 100644 --- a/src/python/src/grpc/_adapter/_intermediary_low_test.py +++ b/src/python/src/grpc/_adapter/_intermediary_low_test.py @@ -282,6 +282,9 @@ class EchoTest(unittest.TestCase): self.assertIn(server_trailing_binary_metadata_key, metadata) self.assertEqual(server_trailing_binary_metadata_value, metadata[server_trailing_binary_metadata_key]) + self.assertSetEqual(set(key for key, _ in finish_accepted.metadata), + set((server_trailing_metadata_key, + server_trailing_binary_metadata_key,))) server_timeout_none_event = self.server_completion_queue.get(0) self.assertIsNone(server_timeout_none_event) From ec5dc7f90b0a1a4d342be019beaee1a9dbe5269c Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Mon, 29 Jun 2015 15:32:44 -0700 Subject: [PATCH 5/8] Accept metadata sequences, return tuples --- src/python/src/grpc/_adapter/_c/types.h | 6 +-- src/python/src/grpc/_adapter/_c/utility.c | 53 ++++++++++++++++++----- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/python/src/grpc/_adapter/_c/types.h b/src/python/src/grpc/_adapter/_c/types.h index e189ae25660..3449f0643f7 100644 --- a/src/python/src/grpc/_adapter/_c/types.h +++ b/src/python/src/grpc/_adapter/_c/types.h @@ -241,10 +241,10 @@ double pygrpc_cast_gpr_timespec_to_double(gpr_timespec timespec); gpr_timespec pygrpc_cast_double_to_gpr_timespec(double seconds); /* Returns true on success, false on failure. */ -int pygrpc_cast_pylist_to_send_metadata( - PyObject *pylist, grpc_metadata **metadata, size_t *count); +int pygrpc_cast_pyseq_to_send_metadata( + PyObject *pyseq, grpc_metadata **metadata, size_t *count); /* Returns a metadata array as a Python object on success, else NULL. */ -PyObject *pygrpc_cast_metadata_array_to_pylist(grpc_metadata_array metadata); +PyObject *pygrpc_cast_metadata_array_to_pyseq(grpc_metadata_array metadata); /* Transliterate from a list of python channel arguments (2-tuples of string and string|integer|None) to a grpc_channel_args object. The strings placed diff --git a/src/python/src/grpc/_adapter/_c/utility.c b/src/python/src/grpc/_adapter/_c/utility.c index a433f26d769..480a720c21f 100644 --- a/src/python/src/grpc/_adapter/_c/utility.c +++ b/src/python/src/grpc/_adapter/_c/utility.c @@ -32,6 +32,7 @@ */ #include +#include #define PY_SSIZE_T_CLEAN #include @@ -118,7 +119,7 @@ PyObject *pygrpc_consume_event(grpc_event event) { tag->request_call_details.method, tag->request_call_details.host, pygrpc_cast_gpr_timespec_to_double(tag->request_call_details.deadline), GRPC_OP_RECV_INITIAL_METADATA, - pygrpc_cast_metadata_array_to_pylist(tag->request_metadata), Py_None, + pygrpc_cast_metadata_array_to_pyseq(tag->request_metadata), Py_None, Py_None, Py_None, Py_None, event.success ? Py_True : Py_False); } else { @@ -172,7 +173,7 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { c_op.flags = 0; switch (type) { case GRPC_OP_SEND_INITIAL_METADATA: - if (!pygrpc_cast_pylist_to_send_metadata( + if (!pygrpc_cast_pyseq_to_send_metadata( PyTuple_GetItem(op, INITIAL_METADATA_INDEX), &c_op.data.send_initial_metadata.metadata, &c_op.data.send_initial_metadata.count)) { @@ -190,7 +191,7 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { /* Don't need to fill in any other fields. */ break; case GRPC_OP_SEND_STATUS_FROM_SERVER: - if (!pygrpc_cast_pylist_to_send_metadata( + if (!pygrpc_cast_pyseq_to_send_metadata( PyTuple_GetItem(op, TRAILING_METADATA_INDEX), &c_op.data.send_status_from_server.trailing_metadata, &c_op.data.send_status_from_server.trailing_metadata_count)) { @@ -247,8 +248,16 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { } void pygrpc_discard_op(grpc_op op) { + size_t i; switch(op.op) { case GRPC_OP_SEND_INITIAL_METADATA: + /* Whenever we produce send-metadata, we allocate new strings (to handle + arbitrary sequence input as opposed to just lists or just tuples). We + thus must free those elements. */ + for (i = 0; i < op.data.send_initial_metadata.count; ++i) { + gpr_free((void *)op.data.send_initial_metadata.metadata[i].key); + gpr_free((void *)op.data.send_initial_metadata.metadata[i].value); + } gpr_free(op.data.send_initial_metadata.metadata); break; case GRPC_OP_SEND_MESSAGE: @@ -258,6 +267,16 @@ void pygrpc_discard_op(grpc_op op) { /* Don't need to free any fields. */ break; case GRPC_OP_SEND_STATUS_FROM_SERVER: + /* Whenever we produce send-metadata, we allocate new strings (to handle + arbitrary sequence input as opposed to just lists or just tuples). We + thus must free those elements. */ + for (i = 0; i < op.data.send_status_from_server.trailing_metadata_count; + ++i) { + gpr_free( + (void *)op.data.send_status_from_server.trailing_metadata[i].key); + gpr_free( + (void *)op.data.send_status_from_server.trailing_metadata[i].value); + } gpr_free(op.data.send_status_from_server.trailing_metadata); gpr_free((char *)op.data.send_status_from_server.status_details); break; @@ -419,31 +438,41 @@ void pygrpc_discard_channel_args(grpc_channel_args args) { gpr_free(args.args); } -int pygrpc_cast_pylist_to_send_metadata( - PyObject *pylist, grpc_metadata **metadata, size_t *count) { +int pygrpc_cast_pyseq_to_send_metadata( + PyObject *pyseq, grpc_metadata **metadata, size_t *count) { size_t i; Py_ssize_t value_length; - *count = PyList_Size(pylist); + char *key; + char *value; + if (!PySequence_Check(pyseq)) { + return 0; + } + *count = PySequence_Size(pyseq); *metadata = gpr_malloc(sizeof(grpc_metadata) * *count); for (i = 0; i < *count; ++i) { - if (!PyArg_ParseTuple( - PyList_GetItem(pylist, i), "ss#", - &(*metadata)[i].key, &(*metadata)[i].value, &value_length)) { + PyObject *item = PySequence_GetItem(pyseq, i); + if (!PyArg_ParseTuple(item, "ss#", &key, &value, &value_length)) { + Py_DECREF(item); gpr_free(*metadata); *count = 0; *metadata = NULL; return 0; + } else { + (*metadata)[i].key = gpr_strdup(key); + (*metadata)[i].value = gpr_malloc(value_length); + memcpy((void *)(*metadata)[i].value, value, value_length); + Py_DECREF(item); } (*metadata)[i].value_length = value_length; } return 1; } -PyObject *pygrpc_cast_metadata_array_to_pylist(grpc_metadata_array metadata) { - PyObject *result = PyList_New(metadata.count); +PyObject *pygrpc_cast_metadata_array_to_pyseq(grpc_metadata_array metadata) { + PyObject *result = PyTuple_New(metadata.count); size_t i; for (i = 0; i < metadata.count; ++i) { - PyList_SetItem( + PyTuple_SetItem( result, i, Py_BuildValue( "ss#", metadata.metadata[i].key, metadata.metadata[i].value, (Py_ssize_t)metadata.metadata[i].value_length)); From c60868622d61969416ea440aaecec21e2ebf265b Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 28 Jun 2015 23:47:48 -0700 Subject: [PATCH 6/8] =?UTF-8?q?Don=E2=80=99t=20import=20Protobuf=20runtime?= =?UTF-8?q?=20using=20Cocoapods=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/objective-c/ProtoRPC/ProtoRPC.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 39120344156..517c4812a78 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -33,7 +33,7 @@ #import "ProtoRPC.h" -#import +#import #import #import #import From 50f198260e350a6f875a2ae94ad496d28f711bf2 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 28 Jun 2015 23:48:30 -0700 Subject: [PATCH 7/8] Add Bazel target for ObjC gRPC runtime --- BUILD | 18 ++++++++++++++++++ templates/BUILD.template | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/BUILD b/BUILD index 934146f57e0..8a827ff54e1 100644 --- a/BUILD +++ b/BUILD @@ -1259,3 +1259,21 @@ objc_bundle_library( name = "gRPCCertificates", resources = ["etc/roots.pem"], ) + +proto_objc_rpc_path = objc_path + "/ProtoRPC" + +objc_library( + name = "proto_objc_rpc", + hdrs = glob([ + proto_objc_rpc_path + "/*.h", + ]), + srcs = glob([ + proto_objc_rpc_path + "/*.m", + ]), + includes = [objc_path], + deps = [ + ":grpc_client", + ":rx_library", + "//external:protobuf_objc", + ], +) diff --git a/templates/BUILD.template b/templates/BUILD.template index 4d2bf7db283..dffdc1dddde 100644 --- a/templates/BUILD.template +++ b/templates/BUILD.template @@ -205,3 +205,21 @@ objc_bundle_library( name = "gRPCCertificates", resources = ["etc/roots.pem"], ) + +proto_objc_rpc_path = objc_path + "/ProtoRPC" + +objc_library( + name = "proto_objc_rpc", + hdrs = glob([ + proto_objc_rpc_path + "/*.h", + ]), + srcs = glob([ + proto_objc_rpc_path + "/*.m", + ]), + includes = [objc_path], + deps = [ + ":grpc_client", + ":rx_library", + "//external:protobuf_objc", + ], +) From 3cacaacf88964a55bb2ed05c03967eeeaaef89f2 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 29 Jun 2015 16:45:46 -0700 Subject: [PATCH 8/8] Minor: add TODO to improve an error message. --- src/objective-c/ProtoRPC/ProtoRPC.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 517c4812a78..4da646d7b45 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -66,6 +66,8 @@ // A writer that serializes the proto messages to send. id bytesWriter = [[[GRXWriter alloc] initWithWriter:requestsWriter] map:^id(GPBMessage *proto) { + // TODO(jcanizales): Fail with an understandable error message if the requestsWriter isn't + // sending GPBMessages. return [proto data]; }]; if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) {