Example #1
0
def fastcomp(code):
    with tmpdir() as d:
        with chdir(d):
            open('foo.cpp','w').write(code)
            os.system('g++ foo.cpp -shared -o foo.so -fPIC')
            lib = ctypes.cdll.LoadLibrary('foo.so')
            return lib
 def buildlib(self, libfile, sources=(), depdirs = (), include_paths = (),
                  define_symbols = (), undefine_symbols = (), extra_opts = (),
                  working_dir = None, export_dirs = (), cmd=(), force_rebuild=False, extra_mappers=()):
     if working_dir is None:
         raise Exception("Must specify working_dir.")
     if isinstance(sources, basestring):
         sources = [sources]
     if not export_dirs and working_dir:
         export_dirs = (working_dir,)
     export_dirs = allabs(export_dirs)
     depdirs = allabs(list(depdirs) + list(self.depdirs))
     include_paths = allabs(list(include_paths) + list(self.include_paths))
     define_symbols = list(define_symbols) + list(self.define_symbols)
     undefine_symbols = list(undefine_symbols) + list(self.undefine_symbols)
     extra_opts = list(extra_opts) + list(self.extra_opts)
     type_mappers = list(extra_mappers) + list(self.type_mappers)
     if working_dir is None:
         working_dir = self.working_dir
     else:
         working_dir = os.path.abspath(working_dir)
     with chdir(working_dir):
         if force_rebuild and os.path.exists(libfile):
              shutil.mv(libfile, libfile+'.bkp')
         if cmd:
             return self.dumb_get(libfile, cmd, depdirs)
         else:
             return self.smart_get(libfile, sources, depdirs, include_paths,
                              define_symbols, undefine_symbols, extra_opts,
                              working_dir, export_dirs, type_mappers=type_mappers)
Example #3
0
def _ensure_imagedb():
    '''Compile imagedb if it's not already here '''
    imagedb_prog = os.path.join(here,'imagedb')
    if not os.path.exists(imagedb_prog):
        logger.info("imagedb executable is not present, making it")
        with nested(chdir(here), replacedict(os.environ, PLATFORM=os.uname()[0])):
            PIPE = subprocess.PIPE
            proc = subprocess.Popen(["make"], stdout = PIPE, stderr = PIPE)
            if proc.wait():
                errormsg = proc.stderr.read()
                msg = "Unable to build imagedb executable - Error was:\n {errormsg}".format(**locals())
                logger.error(msg)
                raise IOError(msg)
    return imagedb_prog
 def buildlib(self,
              libfile,
              sources=(),
              depdirs=(),
              include_paths=(),
              define_symbols=(),
              undefine_symbols=(),
              extra_opts=(),
              working_dir=None,
              export_dirs=(),
              cmd=(),
              force_rebuild=False,
              extra_mappers=()):
     if working_dir is None:
         raise Exception("Must specify working_dir.")
     if isinstance(sources, basestring):
         sources = [sources]
     if not export_dirs and working_dir:
         export_dirs = (working_dir, )
     export_dirs = allabs(export_dirs)
     depdirs = allabs(list(depdirs) + list(self.depdirs))
     include_paths = allabs(list(include_paths) + list(self.include_paths))
     define_symbols = list(define_symbols) + list(self.define_symbols)
     undefine_symbols = list(undefine_symbols) + list(self.undefine_symbols)
     extra_opts = list(extra_opts) + list(self.extra_opts)
     type_mappers = list(extra_mappers) + list(self.type_mappers)
     if working_dir is None:
         working_dir = self.working_dir
     else:
         working_dir = os.path.abspath(working_dir)
     with chdir(working_dir):
         if force_rebuild and os.path.exists(libfile):
             shutil.mv(libfile, libfile + '.bkp')
         if cmd:
             return self.dumb_get(libfile, cmd, depdirs)
         else:
             return self.smart_get(libfile,
                                   sources,
                                   depdirs,
                                   include_paths,
                                   define_symbols,
                                   undefine_symbols,
                                   extra_opts,
                                   working_dir,
                                   export_dirs,
                                   type_mappers=type_mappers)