NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

extension.py (4897B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\extension.py
      2 __revision__ = '$Id: extension.py 87602 2011-01-01 04:24:26Z richard.tew $'
      3 import os, string, sys
      4 from types import *
      5 try:
      6     import warnings
      7 except ImportError:
      8     warnings = None
      9 
     10 class Extension:
     11 
     12     def __init__(self, name, sources, include_dirs = None, define_macros = None, undef_macros = None, library_dirs = None, libraries = None, runtime_library_dirs = None, extra_objects = None, extra_compile_args = None, extra_link_args = None, export_symbols = None, swig_opts = None, depends = None, language = None, **kw):
     13         self.name = name
     14         self.sources = sources
     15         self.include_dirs = include_dirs or []
     16         self.define_macros = define_macros or []
     17         self.undef_macros = undef_macros or []
     18         self.library_dirs = library_dirs or []
     19         self.libraries = libraries or []
     20         self.runtime_library_dirs = runtime_library_dirs or []
     21         self.extra_objects = extra_objects or []
     22         self.extra_compile_args = extra_compile_args or []
     23         self.extra_link_args = extra_link_args or []
     24         self.export_symbols = export_symbols or []
     25         self.swig_opts = swig_opts or []
     26         self.depends = depends or []
     27         self.language = language
     28         if len(kw):
     29             L = kw.keys()
     30             L.sort()
     31             L = map(repr, L)
     32             msg = 'Unknown Extension options: ' + string.join(L, ', ')
     33             if warnings is not None:
     34                 warnings.warn(msg)
     35             else:
     36                 sys.stderr.write(msg + '\n')
     37 
     38 
     39 def read_setup_file(filename):
     40     from distutils.sysconfig import parse_makefile, expand_makefile_vars, _variable_rx
     41     from distutils.text_file import TextFile
     42     from distutils.util import split_quoted
     43     vars = parse_makefile(filename)
     44     file = TextFile(filename, strip_comments=1, skip_blanks=1, join_lines=1, lstrip_ws=1, rstrip_ws=1)
     45     try:
     46         extensions = []
     47         while 1:
     48             line = file.readline()
     49             if line is None:
     50                 break
     51             if _variable_rx.match(line):
     52                 continue
     53                 if line[0] == line[-1] == '*':
     54                     file.warn("'%s' lines not handled yet" % line)
     55                     continue
     56             line = expand_makefile_vars(line, vars)
     57             words = split_quoted(line)
     58             module = words[0]
     59             ext = Extension(module, [])
     60             append_next_word = None
     61             for word in words[1:]:
     62                 if append_next_word is not None:
     63                     append_next_word.append(word)
     64                     append_next_word = None
     65                     continue
     66                 suffix = os.path.splitext(word)[1]
     67                 switch = word[0:2]
     68                 value = word[2:]
     69                 if suffix in ('.c', '.cc', '.cpp', '.cxx', '.c++', '.m', '.mm'):
     70                     ext.sources.append(word)
     71                 elif switch == '-I':
     72                     ext.include_dirs.append(value)
     73                 elif switch == '-D':
     74                     equals = string.find(value, '=')
     75                     if equals == -1:
     76                         ext.define_macros.append((value, None))
     77                     else:
     78                         ext.define_macros.append((value[0:equals], value[equals + 2:]))
     79                 elif switch == '-U':
     80                     ext.undef_macros.append(value)
     81                 elif switch == '-C':
     82                     ext.extra_compile_args.append(word)
     83                 elif switch == '-l':
     84                     ext.libraries.append(value)
     85                 elif switch == '-L':
     86                     ext.library_dirs.append(value)
     87                 elif switch == '-R':
     88                     ext.runtime_library_dirs.append(value)
     89                 elif word == '-rpath':
     90                     append_next_word = ext.runtime_library_dirs
     91                 elif word == '-Xlinker':
     92                     append_next_word = ext.extra_link_args
     93                 elif word == '-Xcompiler':
     94                     append_next_word = ext.extra_compile_args
     95                 elif switch == '-u':
     96                     ext.extra_link_args.append(word)
     97                     if not value:
     98                         append_next_word = ext.extra_link_args
     99                 elif word == '-Xcompiler':
    100                     append_next_word = ext.extra_compile_args
    101                 elif switch == '-u':
    102                     ext.extra_link_args.append(word)
    103                     if not value:
    104                         append_next_word = ext.extra_link_args
    105                 elif suffix in ('.a', '.so', '.sl', '.o', '.dylib'):
    106                     ext.extra_objects.append(word)
    107                 else:
    108                     file.warn("unrecognized argument '%s'" % word)
    109 
    110             extensions.append(ext)
    111 
    112     finally:
    113         file.close()
    114 
    115     return extensions