Patch monkeypatch link function to work in Python3

The modified link command was originally taken from a Python 2.x distutils.
pull/7195/head
Masood Malekghassemi 9 years ago
parent 586e3835fe
commit 06c857cb86
  1. 4
      setup.py
  2. 12
      src/python/grpcio/_unixccompiler_patch.py

@ -57,13 +57,13 @@ os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.abspath(PYTHON_STEM))
# Break import-style to ensure we can actually find our in-repo dependencies.
import build
import _unixccompiler_patch
import commands
import grpc_core_dependencies
import grpc_version
# TODO(atash) make this conditional on being on a mingw32 build
build.monkeypatch_unix_compiler()
_unixccompiler_patch.monkeypatch_unix_compiler()
LICENSE = '3-clause BSD'

@ -61,8 +61,9 @@ def _unix_piecemeal_link(
if not dir in ('/lib', '/lib64', '/usr/lib', '/usr/lib64')]
lib_opts = ccompiler.gen_lib_options(self, library_dirs, runtime_library_dirs,
libraries)
if not isinstance(output_dir, basestring) and output_dir is not None:
raise TypeError, "'output_dir' must be a string or None"
if (not (isinstance(output_dir, str) or isinstance(output_dir, bytes))
and output_dir is not None):
raise TypeError("'output_dir' must be a string or None")
if output_dir is not None:
output_filename = os.path.join(output_dir, output_filename)
@ -106,11 +107,14 @@ def _unix_piecemeal_link(
escaped_ld_args = [arg.replace('\\', '\\\\') for arg in ld_args]
command_file.write(' '.join(escaped_ld_args))
self.spawn(linker + ['@{}'.format(command_filename)])
except errors.DistutilsExecError, msg:
raise ccompiler.LinkError, msg
except errors.DistutilsExecError:
raise ccompiler.LinkError
else:
log.debug("skipping %s (up-to-date)", output_filename)
# TODO(atash) try replacing this monkeypatch of the compiler harness' link
# operation with a monkeypatch of the distutils `spawn` that applies
# command-argument-file hacks where it can. Might be cleaner.
def monkeypatch_unix_compiler():
"""Monkeypatching is dumb, but it's either that or we become maintainers of
something much, much bigger."""
Loading…
Cancel
Save