本文整理汇总了Python中pypy.translator.tool.cbuild.ExternalCompilationInfo类的典型用法代码示例。如果您正苦于以下问题:Python ExternalCompilationInfo类的具体用法?Python ExternalCompilationInfo怎么用?Python ExternalCompilationInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExternalCompilationInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compile_module
def compile_module(space, modname, **kwds):
"""
Build an extension module and return the filename of the resulting native
code file.
modname is the name of the module, possibly including dots if it is a module
inside a package.
Any extra keyword arguments are passed on to ExternalCompilationInfo to
build the module (so specify your source with one of those).
"""
modname = modname.split('.')[-1]
eci = ExternalCompilationInfo(
export_symbols=['init%s' % (modname,)],
include_dirs=api.include_dirs,
**kwds
)
eci = eci.convert_sources_to_files()
dirname = (udir/uniquemodulename('module')).ensure(dir=1)
soname = platform.platform.compile(
[], eci,
outputfilename=str(dirname/modname),
standalone=False)
from pypy.module.imp.importing import get_so_extension
pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
soname.rename(pydname)
return str(pydname)
示例2: get_eci
def get_eci(self):
from distutils import sysconfig
python_inc = sysconfig.get_python_inc()
eci = ExternalCompilationInfo(
include_dirs=[python_inc],
includes=["Python.h",
],
)
return eci.merge(CBuilder.get_eci(self))
示例3: test_convert_sources_to_c_files
def test_convert_sources_to_c_files(self):
eci = ExternalCompilationInfo(
separate_module_sources = ['xxx'],
separate_module_files = ['x.c'],
)
cache_dir = udir.join('test_convert_sources').ensure(dir=1)
neweci = eci.convert_sources_to_files(cache_dir)
assert not neweci.separate_module_sources
res = neweci.separate_module_files
assert len(res) == 2
assert res[0] == 'x.c'
assert str(res[1]).startswith(str(cache_dir))
e = ExternalCompilationInfo()
assert e.convert_sources_to_files() is e
示例4: get_rsdl_compilation_info
def get_rsdl_compilation_info():
if sys.platform == 'darwin':
eci = ExternalCompilationInfo(
includes = ['SDL.h'],
include_dirs = ['/Library/Frameworks/SDL.framework/Headers'],
link_files = [
str(py.magic.autopath().dirpath().join('macosx-sdl-main/SDLMain.m')),
],
frameworks = ['SDL', 'Cocoa']
)
else:
eci = ExternalCompilationInfo(
includes=['SDL.h'],
)
eci = eci.merge(ExternalCompilationInfo.from_config_tool('sdl-config'))
return eci
示例5: test_merge2
def test_merge2(self):
e1 = ExternalCompilationInfo(
pre_include_bits = ['1'],
link_files = ['1.c']
)
e2 = ExternalCompilationInfo(
pre_include_bits = ['2'],
link_files = ['1.c', '2.c']
)
e3 = ExternalCompilationInfo(
pre_include_bits = ['3'],
link_files = ['1.c', '2.c', '3.c']
)
e = e1.merge(e2)
e = e.merge(e3, e3)
assert e.pre_include_bits == ('1', '2', '3')
assert e.link_files == ('1.c', '2.c', '3.c')
示例6: test_from_linker_flags
def test_from_linker_flags(self):
flags = ('-L/some/lib/path -L/other/lib/path '
'-lmylib1 -lmylib2 -?1 -!2')
eci = ExternalCompilationInfo.from_linker_flags(flags)
assert eci.libraries == ('mylib1', 'mylib2')
assert eci.library_dirs == ('/some/lib/path',
'/other/lib/path')
assert eci.link_extra == ('-?1', '-!2')
示例7: test_make_shared_lib
def test_make_shared_lib(self):
eci = ExternalCompilationInfo(
separate_module_sources = ['''
int get()
{
return 42;
}''']
)
neweci = eci.compile_shared_lib()
assert len(neweci.libraries) == 1
try:
import ctypes
except ImportError:
py.test.skip("Need ctypes for that test")
assert ctypes.CDLL(neweci.libraries[0]).get() == 42
assert not neweci.separate_module_sources
assert not neweci.separate_module_files
示例8: test_platforms
def test_platforms(self):
from pypy.translator.platform import Platform
class Maemo(Platform):
def __init__(self, cc=None):
self.cc = cc
eci = ExternalCompilationInfo(platform=Maemo())
eci2 = ExternalCompilationInfo()
assert eci != eci2
assert hash(eci) != hash(eci2)
assert repr(eci) != repr(eci2)
py.test.raises(Exception, eci2.merge, eci)
assert eci.merge(eci).platform == Maemo()
assert (ExternalCompilationInfo(platform=Maemo(cc='xxx')) !=
ExternalCompilationInfo(platform=Maemo(cc='yyy')))
assert (repr(ExternalCompilationInfo(platform=Maemo(cc='xxx'))) !=
repr(ExternalCompilationInfo(platform=Maemo(cc='yyy'))))
示例9: test_from_compiler_flags
def test_from_compiler_flags(self):
flags = ('-I/some/include/path -I/other/include/path '
'-DMACRO1 -D_MACRO2=baz -?1 -!2')
eci = ExternalCompilationInfo.from_compiler_flags(flags)
assert eci.pre_include_bits == ('#define MACRO1 1',
'#define _MACRO2 baz')
assert eci.includes == ()
assert eci.include_dirs == ('/some/include/path',
'/other/include/path')
assert eci.compile_extra == ('-?1', '-!2')
示例10: __init__
def __init__(self, translator, entrypoint, config, gcpolicy=None):
self.translator = translator
self.entrypoint = entrypoint
self.entrypoint_name = self.entrypoint.func_name
self.originalentrypoint = entrypoint
self.config = config
self.gcpolicy = gcpolicy # for tests only, e.g. rpython/memory/
if gcpolicy is not None and gcpolicy.requires_stackless:
config.translation.stackless = True
self.eci = ExternalCompilationInfo()
示例11: test_merge
def test_merge(self):
e1 = ExternalCompilationInfo(
pre_include_bits = ['1'],
includes = ['x.h'],
post_include_bits = ['p1']
)
e2 = ExternalCompilationInfo(
pre_include_bits = ['2'],
includes = ['x.h', 'y.h'],
post_include_bits = ['p2'],
)
e3 = ExternalCompilationInfo(
pre_include_bits = ['3'],
includes = ['y.h', 'z.h'],
post_include_bits = ['p1', 'p3']
)
e = e1.merge(e2, e3)
assert e.pre_include_bits == ('1', '2', '3')
assert e.includes == ('x.h', 'y.h', 'z.h')
assert e.post_include_bits == ('p1', 'p2', 'p3')
示例12: log
log(cmdline)
err = os.system(cmdline)
if err:
raise Exception("gcc command failed")
do("g++ -g -c '%s' -o '%s' `%s --cppflags`" % (cname, o1name, llvm_config))
do("g++ -g -c '%s' -o '%s' `%s --cppflags`" % (cppname, o2name, llvm_config))
do("g++ -g -shared '%s' '%s' -o '%s'" % (o1name, o2name, libname) +
" `%s --cflags --ldflags --libs jit engine`" % llvm_config)
ctypes_compilation_info = ExternalCompilationInfo(
library_dirs = [dirname],
libraries = ['pypy_cache_llvm'],
)
compilation_info = ExternalCompilationInfo.from_linker_flags(
os.popen("%s --ldflags --libs jit engine" % llvm_config, 'r').read())
compilation_info = compilation_info.merge(ExternalCompilationInfo(
link_extra = [o1name, o2name],
use_cpp_linker = True,
))
compilation_info._with_ctypes = ctypes_compilation_info
_teardown = None
def set_teardown_function(fn):
global _teardown
_teardown = fn
def teardown_now():
示例13: test_from_config_tool
def test_from_config_tool(self):
sdlconfig = py.path.local.sysfind('sdl-config')
if not sdlconfig:
py.test.skip("sdl-config not installed")
eci = ExternalCompilationInfo.from_config_tool('sdl-config')
assert 'SDL' in eci.libraries
示例14: ExternalCompilationInfo
import sys
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rpython.tool import rffi_platform as platform
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rlib.rsdl import RSDL
if sys.platform == 'darwin':
eci = ExternalCompilationInfo(
includes = ['SDL_mixer.h'],
frameworks = ['SDL_mixer'],
include_dirs = ['/Library/Frameworks/SDL_Mixer.framework/Headers']
)
else:
eci = ExternalCompilationInfo(
includes=['SDL_mixer.h'],
libraries=['SDL_mixer'],
)
eci = eci.merge(RSDL.eci)
eci = eci.merge(eci)
eci = eci.merge(eci)
ChunkPtr = lltype.Ptr(lltype.ForwardReference())
class CConfig:
_compilation_info_ = eci
Chunk = platform.Struct('Mix_Chunk', [('allocated', rffi.INT),
('abuf', RSDL.Uint8P),
('alen', RSDL.Uint32),
示例15: CBuilder
class CBuilder(object):
c_source_filename = None
_compiled = False
modulename = None
def __init__(self, translator, entrypoint, config, gcpolicy=None):
self.translator = translator
self.entrypoint = entrypoint
self.entrypoint_name = self.entrypoint.func_name
self.originalentrypoint = entrypoint
self.config = config
self.gcpolicy = gcpolicy # for tests only, e.g. rpython/memory/
if gcpolicy is not None and gcpolicy.requires_stackless:
config.translation.stackless = True
self.eci = ExternalCompilationInfo()
def build_database(self):
translator = self.translator
gcpolicyclass = self.get_gcpolicyclass()
if self.config.translation.gcrootfinder == "asmgcc":
if not self.standalone:
raise NotImplementedError("--gcrootfinder=asmgcc requires standalone")
if self.config.translation.stackless:
if not self.standalone:
raise Exception("stackless: only for stand-alone builds")
from pypy.translator.stackless.transform import StacklessTransformer
stacklesstransformer = StacklessTransformer(
translator, self.originalentrypoint,
stackless_gc=gcpolicyclass.requires_stackless)
self.entrypoint = stacklesstransformer.slp_entry_point
else:
stacklesstransformer = None
db = LowLevelDatabase(translator, standalone=self.standalone,
gcpolicyclass=gcpolicyclass,
stacklesstransformer=stacklesstransformer,
thread_enabled=self.config.translation.thread,
sandbox=self.config.translation.sandbox)
self.db = db
# give the gc a chance to register interest in the start-up functions it
# need (we call this for its side-effects of db.get())
list(db.gcpolicy.gc_startup_code())
# build entrypoint and eventually other things to expose
pf = self.getentrypointptr()
pfname = db.get(pf)
self.c_entrypoint_name = pfname
db.complete()
self.collect_compilation_info(db)
return db
have___thread = None
def collect_compilation_info(self, db):
# we need a concrete gcpolicy to do this
self.eci = self.eci.merge(ExternalCompilationInfo(
libraries=db.gcpolicy.gc_libraries()))
all = []
for node in self.db.globalcontainers():
eci = getattr(node, 'compilation_info', None)
if eci:
all.append(eci)
self.eci = self.eci.merge(*all)
def get_gcpolicyclass(self):
if self.gcpolicy is None:
name = self.config.translation.gctransformer
if self.config.translation.gcrootfinder == "stackless":
name = "%s+stacklessgc" % (name,)
elif self.config.translation.gcrootfinder == "llvmgc":
name = "%s+llvmgcroot" % (name,)
elif self.config.translation.gcrootfinder == "asmgcc":
name = "%s+asmgcroot" % (name,)
return gc.name_to_gcpolicy[name]
return self.gcpolicy
# use generate_source(defines=DEBUG_DEFINES) to force the #definition
# of the macros that enable debugging assertions
DEBUG_DEFINES = {'RPY_ASSERT': 1,
'RPY_LL_ASSERT': 1}
def generate_source(self, db=None, defines={}):
assert self.c_source_filename is None
translator = self.translator
if db is None:
db = self.build_database()
pf = self.getentrypointptr()
pfname = db.get(pf)
if self.modulename is None:
self.modulename = uniquemodulename('testing')
modulename = self.modulename
targetdir = udir.ensure(modulename, dir=1)
#.........这里部分代码省略.........