diff options
author | Alistair Veitch <aveitch@google.com> | 2016-01-15 17:57:56 -0800 |
---|---|---|
committer | Alistair Veitch <aveitch@google.com> | 2016-01-15 17:57:56 -0800 |
commit | 0923126cf85a83dab29bbd21f66c5df1f9a56bf8 (patch) | |
tree | 27e80289f06ab43187a30ac58d8a44a5b616299e /src/python/grpcio | |
parent | 04de8c16d2f1fc4f9c97e460ea1f450872981d58 (diff) | |
parent | 7e098a272ccb2b2ac06464064cb59fca857e2e2a (diff) |
Merge branch 'master' into tag_set
Diffstat (limited to 'src/python/grpcio')
-rw-r--r-- | src/python/grpcio/commands.py | 50 | ||||
-rw-r--r-- | src/python/grpcio/grpc_core_dependencies.py | 1 |
2 files changed, 44 insertions, 7 deletions
diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 81dab1b518..e1a3f4bed3 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -40,6 +40,17 @@ import setuptools from setuptools.command import build_py from setuptools.command import test +# Because we need to support building without Cython but simultaneously need to +# subclass its command class when we need to and because distutils requires a +# special hook to acquire a command class, we attempt to import Cython's +# build_ext, and if that fails we import setuptools'. +try: + # Due to the strange way Cython's Distutils module re-imports build_ext, we + # import the build_ext class directly. + from Cython.Distutils.build_ext import build_ext +except ImportError: + from setuptools.command.build_ext import build_ext + PYTHON_STEM = os.path.dirname(os.path.abspath(__file__)) CONF_PY_ADDENDUM = """ @@ -51,6 +62,10 @@ html_theme = 'sphinx_rtd_theme' """ +class CommandError(Exception): + """Simple exception class for GRPC custom commands.""" + + class SphinxDocumentation(setuptools.Command): """Command to generate documentation via sphinx.""" @@ -104,10 +119,10 @@ class BuildProtoModules(setuptools.Command): def run(self): if not self.protoc_command: - raise Exception('could not find protoc') + raise CommandError('could not find protoc') if not self.grpc_python_plugin_command: - raise Exception('could not find grpc_python_plugin ' - '(protoc plugin for GRPC Python)') + raise CommandError('could not find grpc_python_plugin ' + '(protoc plugin for GRPC Python)') include_regex = re.compile(self.include) exclude_regex = re.compile(self.exclude) if self.exclude else None paths = [] @@ -130,7 +145,7 @@ class BuildProtoModules(setuptools.Command): subprocess.check_output(' '.join(command), cwd=root_directory, shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - raise Exception('Command:\n{}\nMessage:\n{}\nOutput:\n{}'.format( + raise CommandError('Command:\n{}\nMessage:\n{}\nOutput:\n{}'.format( command, e.message, e.output)) @@ -156,13 +171,34 @@ class BuildPy(build_py.build_py): """Custom project build command.""" def run(self): - # TODO(atash): make this warn if the proto modules couldn't be built rather - # than cause build failure - self.run_command('build_proto_modules') + try: + self.run_command('build_proto_modules') + except CommandError as error: + sys.stderr.write('warning: %s\n' % error.message) self.run_command('build_project_metadata') build_py.build_py.run(self) +class BuildExt(build_ext): + """Custom build_ext command to enable compiler-specific flags.""" + + C_OPTIONS = { + 'unix': ('-pthread', '-std=gnu99'), + 'msvc': (), + } + LINK_OPTIONS = {} + + def build_extensions(self): + compiler = self.compiler.compiler_type + if compiler in BuildExt.C_OPTIONS: + for extension in self.extensions: + extension.extra_compile_args += list(BuildExt.C_OPTIONS[compiler]) + if compiler in BuildExt.LINK_OPTIONS: + for extension in self.extensions: + extension.extra_link_args += list(BuildExt.LINK_OPTIONS[compiler]) + build_ext.build_extensions(self) + + class Gather(setuptools.Command): """Command to gather project dependencies.""" diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index f5b8b897f9..66a55ef3e5 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -188,6 +188,7 @@ CORE_SOURCE_FILES = [ 'src/core/surface/server.c', 'src/core/surface/server_chttp2.c', 'src/core/surface/server_create.c', + 'src/core/surface/validate_metadata.c', 'src/core/surface/version.c', 'src/core/transport/byte_stream.c', 'src/core/transport/chttp2/alpn.c', |