Skip to content

Commit

Permalink
Patch monkeypatch link function to work in Python3
Browse files Browse the repository at this point in the history
The modified link command was originally taken from a Python 2.x distutils.
  • Loading branch information
soltanmm-google committed Jul 8, 2016
1 parent 586e383 commit 06c857c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 06c857c

Please sign in to comment.