提交 f5d3dfad authored 作者: nouiz's avatar nouiz

Merge pull request #1206 from lamblin/nvcc_compiler_not_pymodule

Make compile_str able to compile a lib that is not a Python module
......@@ -1486,7 +1486,7 @@ class GCC_compiler(object):
@staticmethod
def compile_str(module_name, src_code, location=None,
include_dirs=None, lib_dirs=None, libs=None,
preargs=None):
preargs=None, py_module=True):
"""
:param module_name: string (this has been embedded in the src_code
......@@ -1506,7 +1506,11 @@ class GCC_compiler(object):
:param preargs: a list of extra compiler arguments
:param py_module: if False, compile to a shared library, but do not
import it as a Python module.
:returns: dynamically-imported python module of the compiled code.
(unless py_module is False, in that case returns None.)
"""
#TODO: Do not do the dlimport in this function
......@@ -1631,6 +1635,7 @@ class GCC_compiler(object):
# Print errors just below the command line.
print compile_stderr
if py_module:
#touch the __init__ file
file(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename)
......
......@@ -164,7 +164,7 @@ class NVCC_compiler(object):
def compile_str(
module_name, src_code,
location=None, include_dirs=[], lib_dirs=[], libs=[], preargs=[],
rpaths=rpath_defaults):
rpaths=rpath_defaults, py_module=True):
""":param module_name: string (this has been embedded in the src_code
:param src_code: a complete c or c++ source listing for the module
:param location: a pre-existing filesystem directory where the
......@@ -178,8 +178,11 @@ class NVCC_compiler(object):
:param preargs: a list of extra compiler arguments
:param rpaths: list of rpaths to use with Xlinker.
Defaults to `rpath_defaults`.
:param py_module: if False, compile to a shared library, but
do not import as a Python module.
:returns: dynamically-imported python module of the compiled code.
(unless py_module is False, in that case returns None.)
:note 1: On Windows 7 with nvcc 3.1 we need to compile in the
real directory Otherwise nvcc never finish.
......@@ -393,6 +396,7 @@ class NVCC_compiler(object):
# this doesn't happen to my knowledge
print >> sys.stderr, "DEBUG: nvcc STDOUT", nvcc_stdout
if py_module:
#touch the __init__ file
file(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论