[pytango] 28/483: move build to a proper function; add --strip-lib option to build

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit ebc432cc0577ae6120e446964e56761bce1afed5
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Tue May 3 17:21:46 2011 +0000

    move build to a proper function; add --strip-lib option to build
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@16776 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 setup.py | 583 ++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 297 insertions(+), 286 deletions(-)

diff --git a/setup.py b/setup.py
index 665eb83..e44de5f 100644
--- a/setup.py
+++ b/setup.py
@@ -27,10 +27,16 @@ import platform
 import imp
 
 from distutils.core import setup, Extension
+from distutils.cmd import Command
+from distutils.command.build import build as dftbuild
+from distutils.command.build_ext import build_ext as dftbuild_ext
+from distutils.command.install import install as dftinstall
+from distutils.unixccompiler import UnixCCompiler
 import distutils.sysconfig
 
 try:
     import sphinx
+    from sphinx.setup_command import BuildDoc
 except:
     sphinx = None
 
@@ -42,6 +48,12 @@ try:
 except:
     IPython = None
 
+try:
+    import numpy
+except Exception, e:
+    numpy = None
+
+
 def abspath(*path):
     """A method to determine absolute path for a given relative path to the
     directory where this setup.py script is located"""
@@ -55,272 +67,44 @@ def get_release_info():
     release = imp.load_module(name, *data)
     return release.Release
 
-Release = get_release_info()
-
-BOOST_ROOT = OMNI_ROOT = TANGO_ROOT = NUMPY_ROOT = '/usr'
-
-TANGO_ROOT = os.environ.get('TANGO_ROOT', TANGO_ROOT)
-OMNI_ROOT  = os.environ.get('OMNI_ROOT', OMNI_ROOT)
-BOOST_ROOT = os.environ.get('BOOST_ROOT', BOOST_ROOT)
-NUMPY_ROOT = os.environ.get('NUMPY_ROOT', NUMPY_ROOT)
-
-# if there is no numpy then for sure disable usage of it in PyTango
-
-numpy_capi_available = os.path.isdir(os.path.join(NUMPY_ROOT, 'include','numpy'))
-
-numpy_available = False
-try:
-    import numpy
-    numpy_available = True
-except Exception, e:
-    pass
-
-print '-- Compilation information -------------------------------------------'
-print 'Build %s %s' % (Release.name, Release.version_long)
-print 'Using Python %s' % distutils.sysconfig.get_python_version()
-print '\tinclude: %s' % distutils.sysconfig.get_python_inc()
-print '\tlibrary: %s' % distutils.sysconfig.get_python_lib()
-print 'Using omniORB from %s' % OMNI_ROOT
-print 'Using Tango from %s' % TANGO_ROOT
-print 'Using boost python from %s' % BOOST_ROOT
-if numpy_available:
-    if numpy_capi_available:
-        print 'Using numpy %s' % numpy.version.version
-        print '\tinclude: %s' % os.path.join(NUMPY_ROOT, 'include','numpy')
-    else:
-        print 'NOT using numpy (numpy available but C source is not)'
-else:
-    print 'NOT using numpy (it is not available)'
-print '----------------------------------------------------------------------'
-
-author = Release.authors['Coutinho']
-
-please_debug = False
-
-packages = [
-    'PyTango',
-    'PyTango.ipython',
-]
-
-py_modules = []
-
-provides = [
-    'PyTango',
-]
-
-requires = [
-    'boost_python (>=1.33)',
-    'numpy (>=1.1)'
-]
-
-package_data = {
-    'PyTango' : []
-}
-
-data_files = []
-
-classifiers = [
-    'Development Status :: 5 - Production/Stable',
-    'Environment :: Other Environment',
-    'Intended Audience :: Developers',
-    'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
-    'Natural Language :: English',
-    'Operating System :: Microsoft :: Windows',
-    'Operating System :: POSIX',
-    'Operating System :: POSIX :: Linux',
-    'Operating System :: Unix',
-    'Programming Language :: Python',
-    'Topic :: Scientific/Engineering',
-    'Topic :: Software Development :: Libraries',
-]
-
 def uniquify(seq):
     no_dups = []
     [ no_dups.append(i) for i in seq if not no_dups.count(i) ]
     return no_dups
 
-#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
-# include directories
-#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
-
-include_dirs = [ os.path.abspath('src') ]
-
-_tango_root_inc = os.path.join(TANGO_ROOT, 'include')
-include_dirs.append(_tango_root_inc)
-
-# $TANGO_ROOT/include/tango exists since tango 7.2.0
-# we changed the PyTango code include statements from:
-# #include <tango.h> to:
-# #include <tango/tango.h>
-# However tango itself complains that it doesn't know his own header files
-# if we don't add the $TANGO_ROOT/include/tango directory to the path. So we do it
-# here
-_tango_root_inc = os.path.join(_tango_root_inc, 'tango')
-if os.path.isdir(_tango_root_inc):
-    include_dirs.append(_tango_root_inc)
-
-include_dirs.extend([
-    os.path.join(OMNI_ROOT, 'include'),
-    os.path.join(NUMPY_ROOT, 'include'),
-])
-
-#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
-# library directories
-#-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
-
-libraries = [
-        'tango',
-        'log4tango',
-    ]
-
-extra_compile_args = []
-
-extra_link_args = []
-
-macros = []
-
-if not numpy_available or not numpy_capi_available:
-    macros.append( ('DISABLE_PYTANGO_NUMPY', None) )
-
-library_dirs = [
-    os.path.join(TANGO_ROOT, 'lib'),
-    os.path.join(BOOST_ROOT, 'lib'),
-]
-
-if os.name == 'nt':
-    include_dirs += [ BOOST_ROOT ]
-
-    if please_debug:
-        libraries += [
-            #'libboost_python-vc80-mt-1_38', Boost in windows autodetects the
-            #proper library to link itself with...
-            'omniORB414d_rt',
-            'omniDynamic414d_rt',
-            'omnithread34d_rt',
-            'COS414d_rt',
-        ]
-        extra_compile_args += []
-        extra_link_args += ['/DEBUG']
-        macros += [ ('_DEBUG', None) ]
-    else:
-        libraries += [
-            #'libboost_python-vc80-mt-1_38', Boost in windows autodetects the
-            #proper library to link itself with...
-            'omniORB414_rt',
-            'omniDynamic414_rt',
-            'omnithread34_rt',
-            'COS414_rt',
-        ]
-
-    library_dirs += [ os.path.join(OMNI_ROOT, 'lib', 'x86_win32') ]
-    
-    extra_compile_args += [
-        '/EHsc'
-    ]
-
-    extra_link_args += []
-
-    macros += [
-        #('_WINDOWS', None),
-        #('_USRDLL', None),
-        #('_TANGO_LIB', None),
-        #('JPG_USE_ASM', None),
-        ('LOG4TANGO_HAS_DLL', None),
-        ('TANGO_HAS_DLL', None),
-        ('WIN32', None),
-    ]
-
-else:
-    if please_debug:
-        extra_compile_args += ['-g', '-O0']
-        extra_link_args += ['-g' , '-O0']
-    
-    include_dirs += [ os.path.join(BOOST_ROOT, 'include') ]
-    
-    libraries += [
-        'pthread',
-        'rt',
-        'dl',
-        'omniORB4',
-        'omniDynamic4',
-        'omnithread',
-        'COS4',
-    ]
-
-    # when building with multiple version of python on debian we need
-    # to link against boost_python-py25/-py26 etc...
-    pyver = "py" + "".join(map(str, platform.python_version_tuple()[:2]))
-    dist = platform.dist()[0].lower()
-    if dist in ['debian']:
-        libraries.append('boost_python-' + pyver)
-    else:
-        libraries.append('boost_python')
-
-    library_dirs += [ os.path.join(OMNI_ROOT, 'lib') ]
-
-
-    # Note for PyTango developers:
-    # Compilation time can be greatly reduced by compiling the file
-    # src/precompiled_header.hpp as src/precompiled_header.hpp.gch
-    # and then uncommenting this line. Someday maybe this will be
-    # automated...
-    extra_compile_args += [
-#        '-includesrc/precompiled_header.hpp',
-    ]
-
-    #if not please_debug:
-    #    extra_compile_args += [ '-g0' ]
-
-    extra_link_args += [
-        '-Wl,-h',
-        '-Wl,--strip-all',
-    ]
+def has_c_numpy():
+    NUMPY_ROOT = os.environ.get('NUMPY_ROOT', '/usr')
+    return os.path.isdir(os.path.join(NUMPY_ROOT, 'include','numpy'))
 
-    macros += []
-
-include_dirs = uniquify(include_dirs)
-library_dirs = uniquify(library_dirs)
-
-_cppfiles_exclude = []
-_cppfiles  = [ os.path.join('src',fname) for fname in os.listdir('src') if fname.endswith('.cpp') and not fname in _cppfiles_exclude]
-_cppfiles += [ os.path.join('src','server',fname) for fname in os.listdir(os.path.join('src','server')) if fname.endswith('.cpp') and not fname in _cppfiles_exclude]
-
-_pytango = Extension(name               = '_PyTango',
-                     sources            = _cppfiles,
-                     include_dirs       = include_dirs,
-                     library_dirs       = library_dirs,
-                     libraries          = libraries,
-                     define_macros      = macros,
-                     extra_compile_args = extra_compile_args,
-                     extra_link_args    = extra_link_args,
-                     language           = 'c++',
-                     depends            = []
-                     )
-
-#from setuptools import Command
-from distutils.cmd import Command
-from distutils.command.build import build as dftbuild
-from distutils.command.build_ext import build_ext as dftbuild_ext
-from distutils.command.install import install as dftinstall
-from distutils.unixccompiler import UnixCCompiler
+def has_numpy(with_src=True):
+    ret = numpy is not None
+    if with_src:
+        ret &= has_c_numpy()
+    return ret
 
 class build(dftbuild):
     
     user_options = dftbuild.user_options + \
         [('with-pytango3', None, "distribute PyTango3 module"),
-         ('without-spock', None, "spock IPython extension")]
+         ('without-spock', None, "spock IPython extension"),
+         ('strip-lib', None, "strips the shared library of debugging symbols (Unix like systems only)"), ]
     
-    boolean_options = dftbuild.boolean_options + ['with-pytango3', 'without-spock']
+    boolean_options = dftbuild.boolean_options + ['with-pytango3', 'without-spock', 'strip-lib']
     
     def initialize_options (self):
         dftbuild.initialize_options(self)
         self.with_pytango3 = None
         self.without_spock = None
+        self.strip_lib = None
     
     def finalize_options(self):
         dftbuild.finalize_options(self)
         
     def run(self):
+        if numpy is None:
+            self.warn('NOT using numpy: it is not available')
+        elif not has_c_numpy():
+            self.warn("NOT using numpy: numpy available but C source is not")
         if self.with_pytango3:
             self.distribution.packages.append('PyTango3')
         
@@ -328,6 +112,22 @@ class build(dftbuild):
             self.distribution.py_modules.append('IPython.Extensions.ipy_profile_spock')
             
         dftbuild.run(self)
+        
+        if self.strip_lib:
+            if os.name == 'posix':
+                has_objcopy = os.system("type objcopy") == 0
+                if has_objcopy:
+                    d = abspath(self.build_lib, "PyTango")
+                    orig_dir = os.path.abspath(os.curdir)
+                    so = "_PyTango.so"
+                    dbg = so + ".debug"
+                    try:
+                        os.chdir(d)
+                        os.system("objcopy --only-keep-debug %s %s" % (so, dbg))
+                        os.system("objcopy --strip-debug --strip-unneeded %s" % (so,))
+                        os.system("objcopy --add-gnu-debuglink=%s %s" % (dbg, so))
+                    finally:
+                        os.chdir(orig_dir)
 
     def has_doc(self):
         if sphinx is None: return False
@@ -336,7 +136,6 @@ class build(dftbuild):
 
     sub_commands = dftbuild.sub_commands + [('build_doc', has_doc),]
 
-cmdclass = {'build' : build }
 
 class build_ext(dftbuild_ext): 
     
@@ -348,23 +147,18 @@ class build_ext(dftbuild_ext):
             #self.compiler.compiler_so = " ".join(compiler_pars)
         dftbuild_ext.build_extensions(self)
 
-cmdclass['build_ext'] = build_ext
-
-if sphinx:
-    from sphinx.setup_command import BuildDoc
 
-    class build_doc(BuildDoc):
-        
-        def run(self):
-            # make sure the python path is pointing to the newly built
-            # code so that the documentation is built on this and not a
-            # previously installed version
-            build = self.get_finalized_command('build')
-            sys.path.insert(0, os.path.abspath(build.build_lib))
-            sphinx.setup_command.BuildDoc.run(self)
-            sys.path.pop(0)
+class build_doc(BuildDoc):
     
-    cmdclass['build_doc'] = build_doc
+    def run(self):
+        # make sure the python path is pointing to the newly built
+        # code so that the documentation is built on this and not a
+        # previously installed version
+        
+        build = self.get_finalized_command('build')
+        sys.path.insert(0, os.path.abspath(build.build_lib))
+        sphinx.setup_command.BuildDoc.run(self)
+        sys.path.pop(0)
 
 
 class install_html(Command):
@@ -384,7 +178,6 @@ class install_html(Command):
         src_html_dir = abspath(build_doc.build_dir, 'html')
         self.copy_tree(src_html_dir, self.install_dir)
 
-cmdclass['install_html'] = install_html
 
 class install(dftinstall):
     
@@ -416,28 +209,246 @@ class install(dftinstall):
     sub_commands.append(('install_html', has_html))
 
 
-cmdclass['install'] = install
-
-dist = setup(
-    name             = 'PyTango',
-    version          = Release.version,
-    description      = Release.description,
-    long_description = Release.long_description,
-    author           = author[0],
-    author_email     = author[1],
-    url              = Release.url,
-    download_url     = Release.download_url,
-    platforms        = Release.platform,
-    license          = Release.license,
-    packages         = packages,
-    package_dir      = { 'PyTango' : 'PyTango', 'PyTango3' : 'PyTango3' },
-    py_modules       = py_modules,
-    classifiers      = classifiers,
-    package_data     = package_data,
-    data_files       = data_files,
-    provides         = provides,
-    keywords         = Release.keywords,
-    requires         = requires,
-    ext_package      = 'PyTango',
-    ext_modules      = [_pytango],
-    cmdclass         = cmdclass)
+def main():
+    BOOST_ROOT = OMNI_ROOT = TANGO_ROOT = NUMPY_ROOT = '/usr'
+
+    TANGO_ROOT = os.environ.get('TANGO_ROOT', TANGO_ROOT)
+    OMNI_ROOT  = os.environ.get('OMNI_ROOT', OMNI_ROOT)
+    BOOST_ROOT = os.environ.get('BOOST_ROOT', BOOST_ROOT)
+    NUMPY_ROOT = os.environ.get('NUMPY_ROOT', NUMPY_ROOT)
+    
+    Release = get_release_info()
+
+    author = Release.authors['Coutinho']
+
+    please_debug = False
+
+    packages = [
+        'PyTango',
+        'PyTango.ipython',
+    ]
+
+    py_modules = []
+
+    provides = [
+        'PyTango',
+    ]
+
+    requires = [
+        'boost_python (>=1.33)',
+        'numpy (>=1.1)'
+    ]
+
+    package_data = {
+        'PyTango' : []
+    }
+
+    data_files = []
+
+    classifiers = [
+        'Development Status :: 5 - Production/Stable',
+        'Environment :: Other Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
+        'Natural Language :: English',
+        'Operating System :: Microsoft :: Windows',
+        'Operating System :: POSIX',
+        'Operating System :: POSIX :: Linux',
+        'Operating System :: Unix',
+        'Programming Language :: Python',
+        'Topic :: Scientific/Engineering',
+        'Topic :: Software Development :: Libraries',
+    ]
+
+    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+    # include directories
+    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+
+    include_dirs = [ os.path.abspath('src') ]
+
+    _tango_root_inc = os.path.join(TANGO_ROOT, 'include')
+    include_dirs.append(_tango_root_inc)
+
+    # $TANGO_ROOT/include/tango exists since tango 7.2.0
+    # we changed the PyTango code include statements from:
+    # #include <tango.h> to:
+    # #include <tango/tango.h>
+    # However tango itself complains that it doesn't know his own header files
+    # if we don't add the $TANGO_ROOT/include/tango directory to the path. So we do it
+    # here
+    _tango_root_inc = os.path.join(_tango_root_inc, 'tango')
+    if os.path.isdir(_tango_root_inc):
+        include_dirs.append(_tango_root_inc)
+
+    include_dirs.extend([
+        os.path.join(OMNI_ROOT, 'include'),
+        os.path.join(NUMPY_ROOT, 'include'),
+    ])
+
+    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+    # library directories
+    #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
+
+    libraries = [
+            'tango',
+            'log4tango',
+        ]
+
+    extra_compile_args = []
+
+    extra_link_args = []
+
+    macros = []
+
+    if not has_numpy():
+        macros.append( ('DISABLE_PYTANGO_NUMPY', None) )
+
+    library_dirs = [
+        os.path.join(TANGO_ROOT, 'lib'),
+        os.path.join(BOOST_ROOT, 'lib'),
+    ]
+
+    if os.name == 'nt':
+        include_dirs += [ BOOST_ROOT ]
+
+        if please_debug:
+            libraries += [
+                #'libboost_python-vc80-mt-1_38', Boost in windows autodetects the
+                #proper library to link itself with...
+                'omniORB414d_rt',
+                'omniDynamic414d_rt',
+                'omnithread34d_rt',
+                'COS414d_rt',
+            ]
+            extra_compile_args += []
+            extra_link_args += ['/DEBUG']
+            macros += [ ('_DEBUG', None) ]
+        else:
+            libraries += [
+                #'libboost_python-vc80-mt-1_38', Boost in windows autodetects the
+                #proper library to link itself with...
+                'omniORB414_rt',
+                'omniDynamic414_rt',
+                'omnithread34_rt',
+                'COS414_rt',
+            ]
+
+        library_dirs += [ os.path.join(OMNI_ROOT, 'lib', 'x86_win32') ]
+        
+        extra_compile_args += [
+            '/EHsc'
+        ]
+
+        extra_link_args += []
+
+        macros += [
+            #('_WINDOWS', None),
+            #('_USRDLL', None),
+            #('_TANGO_LIB', None),
+            #('JPG_USE_ASM', None),
+            ('LOG4TANGO_HAS_DLL', None),
+            ('TANGO_HAS_DLL', None),
+            ('WIN32', None),
+        ]
+
+    else:
+        if please_debug:
+            extra_compile_args += ['-g', '-O0']
+            extra_link_args += ['-g' , '-O0']
+        
+        include_dirs += [ os.path.join(BOOST_ROOT, 'include') ]
+        
+        libraries += [
+            'pthread',
+            'rt',
+            'dl',
+            'omniORB4',
+            'omniDynamic4',
+            'omnithread',
+            'COS4',
+        ]
+
+        # when building with multiple version of python on debian we need
+        # to link against boost_python-py25/-py26 etc...
+        pyver = "py" + "".join(map(str, platform.python_version_tuple()[:2]))
+        dist = platform.dist()[0].lower()
+        if dist in ['debian']:
+            libraries.append('boost_python-' + pyver)
+        else:
+            libraries.append('boost_python')
+
+        library_dirs += [ os.path.join(OMNI_ROOT, 'lib') ]
+
+
+        # Note for PyTango developers:
+        # Compilation time can be greatly reduced by compiling the file
+        # src/precompiled_header.hpp as src/precompiled_header.hpp.gch
+        # and then uncommenting this line. Someday maybe this will be
+        # automated...
+        extra_compile_args += [
+    #        '-includesrc/precompiled_header.hpp',
+        ]
+
+        #if not please_debug:
+        #    extra_compile_args += [ '-g0' ]
+
+        extra_link_args += [
+            '-Wl,-h',
+            '-Wl,--strip-all',
+        ]
+
+        macros += []
+
+    include_dirs = uniquify(include_dirs)
+    library_dirs = uniquify(library_dirs)
+
+    _cppfiles_exclude = []
+    _cppfiles  = [ os.path.join('src',fname) for fname in os.listdir('src') if fname.endswith('.cpp') and not fname in _cppfiles_exclude]
+    _cppfiles += [ os.path.join('src','server',fname) for fname in os.listdir(os.path.join('src','server')) if fname.endswith('.cpp') and not fname in _cppfiles_exclude]
+
+    _pytango = Extension(
+        name               = '_PyTango',
+        sources            = _cppfiles,
+        include_dirs       = include_dirs,
+        library_dirs       = library_dirs,
+        libraries          = libraries,
+        define_macros      = macros,
+        extra_compile_args = extra_compile_args,
+        extra_link_args    = extra_link_args,
+        language           = 'c++',
+        depends            = [])
+
+    cmdclass = {'build'        : build,
+                'build_ext'    : build_ext,
+                'install_html' : install_html,
+                'install'      : install }
+    
+    if sphinx:
+        cmdclass['build_doc'] = build_doc
+
+    dist = setup(
+        name             = 'PyTango',
+        version          = Release.version,
+        description      = Release.description,
+        long_description = Release.long_description,
+        author           = author[0],
+        author_email     = author[1],
+        url              = Release.url,
+        download_url     = Release.download_url,
+        platforms        = Release.platform,
+        license          = Release.license,
+        packages         = packages,
+        package_dir      = { 'PyTango' : 'PyTango', 'PyTango3' : 'PyTango3' },
+        py_modules       = py_modules,
+        classifiers      = classifiers,
+        package_data     = package_data,
+        data_files       = data_files,
+        provides         = provides,
+        keywords         = Release.keywords,
+        requires         = requires,
+        ext_package      = 'PyTango',
+        ext_modules      = [_pytango],
+        cmdclass         = cmdclass)
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list