Esempio n. 1
0
def init_settings(cfg):
    if 'PyPy' in sys.version:
        return {}
    settings = cfg['build_ext']
    if cfg['libzmq_extension']:
        settings = bundled_settings()
    else:
        settings = settings_from_prefix(CONFIG['zmq_prefix'])
    
    if 'have_sys_un_h' not in cfg:
        try:
            compile_and_run(pjoin("build", "sock_un"),
                pjoin('buildutils', 'check_sys_un.c'),
                **settings
            )
        except Exception as e:
            warn("No sys/un.h, IPC_PATH_MAX_LEN will be undefined: %s" % e)
            cfg['have_sys_un_h'] = False
        else:
            cfg['have_sys_un_h'] = True
        
        save_config('buildconf', cfg)
    
    if cfg['have_sys_un_h']:
        settings['define_macros'] = [('HAVE_SYS_UN_H', 1)]
    
    settings.setdefault('define_macros', [])
    
    # include internal directories
    settings.setdefault('include_dirs', [])
    settings['include_dirs'] += [pjoin('zmq', sub) for sub in ('utils','core','devices')]

    return settings
Esempio n. 2
0
 def run(self):
     if self.zmq == "bundled":
         self.config = self.bundle_libzmq_extension()
         line()
         return
     
     config = None
     
     # When cross-compiling and zmq is given explicitly, we can't testbuild
     # (as we can't testrun the binary), we assume things are allright.
     if CROSSCOMPILE:
         self.config = dict(vers=ZMQVER)
         return
     
     # There is no available default on Windows, so start with fallback unless
     # zmq was given explicitly.
     if self.zmq is None and sys.platform.startswith("win"):
         config = self.fallback_on_bundled()
         self.zmq = "bundled"
     
     if config is None:
         # first try with given config or defaults
         try:
             config = self.test_build(self.zmq, self.settings)
         except Exception:
             etype, evalue, tb = sys.exc_info()
             # print the error as distutils would if we let it raise:
             print ("\nerror: %s\n" % evalue)
     
     # try fallback on /usr/local on *ix
     if config is None and self.zmq is None and not sys.platform.startswith('win'):
         print ("Failed with default libzmq, trying again with /usr/local")
         time.sleep(1)
         zmq = '/usr/local'
         settings = init_settings(zmq)
         try:
             config = self.test_build(zmq, settings)
         except Exception:
             etype, evalue, tb = sys.exc_info()
             # print the error as distutils would if we let it raise:
             print ("\nerror: %s\n" % evalue)
         else:
             # if we get here the second run succeeded, so we need to update compiler
             # settings for the extensions with /usr/local prefix
             self.zmq = zmq
             for ext in self.distribution.ext_modules:
                 for attr,value in settings.items():
                     setattr(ext, attr, value)
     
     # finally, fallback on bundled
     if config is None and self.zmq is None:
         config = self.fallback_on_bundled()
         self.zmq = "bundled"
     
     save_config('configure', config)
     self.config = config
     line()
Esempio n. 3
0
    def run(self):
        if self.zmq == "bundled":
            self.config = self.bundle_libzmq_extension()
            line()
            return

        config = None

        # There is no available default on Windows, so start with fallback unless
        # zmq was given explicitly.
        if self.zmq is None and sys.platform.startswith("win"):
            config = self.fallback_on_bundled()
            self.zmq = "bundled"

        if config is None:
            # first try with given config or defaults
            try:
                config = self.test_build(self.zmq, self.settings)
            except Exception:
                etype, evalue, tb = sys.exc_info()
                # print the error as distutils would if we let it raise:
                print("\nerror: %s\n" % evalue)

        # try fallback on /usr/local on *ix
        if config is None and self.zmq is None and not sys.platform.startswith(
                'win'):
            print("Failed with default libzmq, trying again with /usr/local")
            time.sleep(1)
            zmq = '/usr/local'
            settings = settings_from_prefix(zmq)
            try:
                config = self.test_build(zmq, settings)
            except Exception:
                etype, evalue, tb = sys.exc_info()
                # print the error as distutils would if we let it raise:
                print("\nerror: %s\n" % evalue)
            else:
                # if we get here the second run succeeded, so we need to update compiler
                # settings for the extensions with /usr/local prefix
                self.zmq = zmq
                for ext in self.distribution.ext_modules:
                    for attr, value in settings.items():
                        setattr(ext, attr, value)

        # finally, fallback on bundled
        if config is None and self.zmq is None:
            config = self.fallback_on_bundled()
            self.zmq = "bundled"

        save_config('configure', config)
        self.config = config
        line()
Esempio n. 4
0
File: setup.py Progetto: fwph/pyzmq
 def save_config(self, name, cfg):
     """write config to JSON"""
     save_config(name, cfg, self.build_base)
     # write to zmq.utils.[name].json
     save_config(name, cfg, os.path.join('zmq', 'utils'))
     # also write to build_lib, because we might be run after copying to
     # build_lib has already happened.
     build_lib_utils = os.path.join(self.build_lib, 'zmq', 'utils')
     if os.path.exists(build_lib_utils):
         save_config(name, cfg, build_lib_utils)
Esempio n. 5
0
 def save_config(self, name, cfg):
     """write config to JSON"""
     save_config(name, cfg, self.build_base)
     # write to zmq.utils.[name].json
     save_config(name, cfg, os.path.join('zmq', 'utils'))
     # also write to build_lib, because we might be run after copying to
     # build_lib has already happened.
     build_lib_utils = os.path.join(self.build_lib, 'zmq', 'utils')
     if os.path.exists(build_lib_utils):
         save_config(name, cfg, build_lib_utils)
 def save_config(self, name, cfg):
     """write config to JSON"""
     save_config(name, cfg, self.build_base)
Esempio n. 7
0
    def bundle_libzmq_extension(self):
        bundledir = "bundled"
        if self.distribution.ext_modules[0].name == 'zmq.libzmq':
            # I've already been run
            return
        
        line()
        print ("Using bundled libzmq")
        
        # fetch sources for libzmq extension:
        if not os.path.exists(bundledir):
            os.makedirs(bundledir)
        if not sys.platform.startswith(('darwin', 'freebsd', 'win')):
            fetch_uuid(bundledir)
        
        fetch_libzmq(bundledir)
        
        stage_platform_hpp(pjoin(bundledir, 'zeromq'))
        
        # construct the Extension:
        
        ext = Extension(
            'zmq.libzmq',
            sources = [pjoin('buildutils', 'initlibzmq.c')] + 
                        glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')),
            include_dirs = [
                pjoin(bundledir, 'zeromq', 'include'),
            ],
        )
        
        if sys.platform.startswith('win'):
            # include defines from zeromq msvc project:
            ext.define_macros.append(('FD_SETSIZE', 1024))
            
            # When compiling the C++ code inside of libzmq itself, we want to
            # avoid "warning C4530: C++ exception handler used, but unwind
            # semantics are not enabled. Specify /EHsc".

            ext.extra_compile_args.append('/EHsc')

            # And things like sockets come from libraries that must be named.

            ext.libraries.append('rpcrt4')
            ext.libraries.append('ws2_32')
        elif not sys.platform.startswith(('darwin', 'freebsd')):
            # add uuid as both `uuid/uuid.h` and `uuid.h`:
            ext.include_dirs.append(pjoin(bundledir, 'uuid'))
            ext.include_dirs.append(bundledir)
            ext.sources.extend(glob(pjoin(bundledir, 'uuid', '*.c')))

            ext.libraries.append('rt')
        
        # insert the extension:
        self.distribution.ext_modules.insert(0, ext)
        
        # update other extensions, with bundled settings
        settings = init_settings("bundled")
        
        for ext in self.distribution.ext_modules[1:]:
            for attr, value in settings.items():
                setattr(ext, attr, value)
        
        save_config("buildconf", dict(zmq="bundled"))
        
        return dict(vers=bundled_version, settings=settings)
Esempio n. 8
0
    def bundle_libzmq_extension(self):
        bundledir = "bundled"
        if self.distribution.ext_modules[0].name == 'zmq.libzmq':
            # I've already been run
            return
        
        line()
        print ("Using bundled libzmq")
        
        # fetch sources for libzmq extension:
        if not os.path.exists(bundledir):
            os.makedirs(bundledir)
        if not sys.platform.startswith(('darwin', 'freebsd', 'win')):
            fetch_uuid(bundledir)
        
        fetch_libzmq(bundledir)
        
        stage_platform_hpp(pjoin(bundledir, 'zeromq'))
        
        # construct the Extension:
        
        ext = Extension(
            'zmq.libzmq',
            sources = [pjoin('buildutils', 'initlibzmq.c')] + 
                        glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')),
            include_dirs = [
                pjoin(bundledir, 'zeromq', 'include'),
            ],
        )
        
        if sys.platform.startswith('win'):
            # include defines from zeromq msvc project:
            ext.define_macros.append(('FD_SETSIZE', 1024))
            
            # When compiling the C++ code inside of libzmq itself, we want to
            # avoid "warning C4530: C++ exception handler used, but unwind
            # semantics are not enabled. Specify /EHsc".
            if self.compiler_type == 'msvc':
                ext.extra_compile_args.append('/EHsc')
            elif self.compiler_type == 'mingw32':
                ext.define_macros.append(('ZMQ_HAVE_MINGW32', 1))

            # And things like sockets come from libraries that must be named.

            ext.libraries.append('rpcrt4')
            ext.libraries.append('ws2_32')
        elif not sys.platform.startswith(('darwin', 'freebsd')):
            # add uuid as both `uuid/uuid.h` and `uuid.h`:
            ext.include_dirs.append(pjoin(bundledir, 'uuid'))
            ext.include_dirs.append(bundledir)
            ext.sources.extend(glob(pjoin(bundledir, 'uuid', '*.c')))

            ext.libraries.append('rt')
        
        # insert the extension:
        self.distribution.ext_modules.insert(0, ext)
        
        # update other extensions, with bundled settings
        settings = init_settings("bundled")
        
        for ext in self.distribution.ext_modules[1:]:
            for attr, value in settings.items():
                setattr(ext, attr, value)
        
        save_config("buildconf", dict(zmq="bundled"))
        
        return dict(vers=bundled_version, settings=settings)
Esempio n. 9
0
 def save_config(self, name, cfg):
     """write config to JSON"""
     save_config(name, cfg, self.build_base)
Esempio n. 10
0
 def run(self):
     if CONFIG['libzmq_extension']:
         self.config = self.bundle_libzmq_extension()
         save_config('configure', self.config)
         line()
         return
     
     # When cross-compiling and zmq is given explicitly, we can't testbuild
     # (as we can't testrun the binary), we assume things are alright.
     if CONFIG['skip_check_zmq'] or CROSSCOMPILE:
         warn("Skipping zmq version check")
         return
     
     config = None
     zmq_prefix = CONFIG['zmq_prefix']
     # There is no available default on Windows, so start with fallback unless
     # zmq was given explicitly, or libzmq extension was explicitly prohibited.
     if sys.platform.startswith("win") and \
         not CONFIG['no_libzmq_extension'] and \
         not zmq_prefix:
         config = self.fallback_on_bundled()
     
     if config is None:
         # first try with given config or defaults
         try:
             config = self.test_build(zmq_prefix, self.settings)
         except Exception:
             etype, evalue, tb = sys.exc_info()
             # print the error as distutils would if we let it raise:
             print ("\nerror: %s\n" % evalue)
     
     # try fallback on /usr/local on *ix
     if config is None and not zmq_prefix and not sys.platform.startswith('win'):
         print ("Failed with default libzmq, trying again with /usr/local")
         time.sleep(1)
         zmq_prefix = CONFIG['zmq_prefix'] = '/usr/local'
         settings = init_settings(CONFIG)
         try:
             config = self.test_build(zmq_prefix, settings)
         except Exception:
             etype, evalue, tb = sys.exc_info()
             # print the error as distutils would if we let it raise:
             print ("\nerror: %s\n" % evalue)
         else:
             # if we get here the second run succeeded, so we need to update compiler
             # settings for the extensions with /usr/local prefix
             save_config('buildconf', CONFIG)
             for ext in self.distribution.ext_modules:
                 for attr,value in settings.items():
                     setattr(ext, attr, value)
     
     # finally, fallback on bundled
     if config is None and CONFIG['no_libzmq_extension']:
         fatal("Falling back on bundled libzmq,"
         " but setup.cfg has explicitly prohibited building the libzmq extension."
         )
     
     if config is None:
         config = self.fallback_on_bundled()
     
     save_config('configure', config)
     self.config = config
     line()
Esempio n. 11
0
    def bundle_libzmq_extension(self):
        bundledir = "bundled"
        if "PyPy" in sys.version:
            fatal("Can't bundle libzmq as an Extension in PyPy (yet!)")
        ext_modules = self.distribution.ext_modules
        if ext_modules and ext_modules[0].name == 'zmq.libzmq':
            # I've already been run
            return
        
        line()
        print ("Using bundled libzmq")
        
        # fetch sources for libzmq extension:
        if not os.path.exists(bundledir):
            os.makedirs(bundledir)
        
        fetch_libzmq(bundledir)
        
        stage_platform_hpp(pjoin(bundledir, 'zeromq'))
        
        # construct the Extension:
        
        ext = Extension(
            'zmq.libzmq',
            sources = [pjoin('buildutils', 'initlibzmq.c')] + 
                        glob(pjoin(bundledir, 'zeromq', 'src', '*.cpp')),
            include_dirs = [
                pjoin(bundledir, 'zeromq', 'include'),
            ],
        )
        
        if sys.platform.startswith('win'):
            # include defines from zeromq msvc project:
            ext.define_macros.append(('FD_SETSIZE', 1024))
            
            # When compiling the C++ code inside of libzmq itself, we want to
            # avoid "warning C4530: C++ exception handler used, but unwind
            # semantics are not enabled. Specify /EHsc".
            if self.compiler_type == 'msvc':
                ext.extra_compile_args.append('/EHsc')
            elif self.compiler_type == 'mingw32':
                ext.define_macros.append(('ZMQ_HAVE_MINGW32', 1))

            # And things like sockets come from libraries that must be named.

            ext.libraries.extend(['rpcrt4', 'ws2_32', 'advapi32'])
        elif not sys.platform.startswith(('darwin', 'freebsd')):
            ext.include_dirs.append(bundledir)

            ext.libraries.append('rt')
        
        # insert the extension:
        self.distribution.ext_modules.insert(0, ext)
        
        # update other extensions, with bundled settings
        CONFIG['libzmq_extension'] = True
        settings = init_settings(CONFIG)
        
        for ext in self.distribution.ext_modules[1:]:
            for attr, value in settings.items():
                setattr(ext, attr, value)
        
        save_config("buildconf", CONFIG)
        
        return dict(vers=bundled_version, settings=settings)
Esempio n. 12
0
 def save_config(self, name, cfg):
     """write config to JSON"""
     save_config(name, cfg, self.build_base)
     save_config(name, cfg, os.path.join('zmq', 'utils'))