root/trunk/support.py

Revision 110, 3.5 kB (checked in by KirkMcDonald, 1 year ago)

* trunk compiles again
* iteration wrapping support temporarily disabled

Line 
1 __all__ = ('setup', 'Extension')
2
3 from celerid import patch_distutils # Cause distutils to be hot-patched.
4
5 from distutils.core import setup, Extension as std_Extension
6 from distutils.errors import DistutilsOptionError
7
8 class Extension(std_Extension):
9     def __init__(self, *args, **kwargs):
10         if 'define_macros' in kwargs or 'undef_macros' in kwargs:
11             raise DistutilsOptionError('D does not support macros, so the'
12                 ' "define_macros" and "undef_macros" arguments are not'
13                 ' supported.  Instead, consider using the "Version Condition"'
14                 ' and "Debug Condition" conditional compilation features'
15                 ' documented at http://www.digitalmars.com/d/version.html'
16                 '\n  Version flags can be passed to the compiler via the'
17                 ' "version_flags" keyword argument to DExtension; debug flags'
18                 ' via the "debug_flags" keyword argument.  For example, when'
19                 ' used with the DMD compiler,'
20                 '\n    DExtension(..., version_flags=["a", "b"])'
21                 '\nwill cause'
22                 '\n    -version=a -version=b'
23                 '\nto be passed to the compiler.'
24               )
25
26         # If the user has requested any version_flags or debug_flags, we use
27         # the distutils 'define_macros' keyword argument to carry them (they're
28         # later unpacked in the dcompiler module).
29         define_macros = []
30         if 'version_flags' in kwargs or 'debug_flags' in kwargs:
31             if 'version_flags' in kwargs:
32                 for flag in kwargs['version_flags']:
33                     define_macros.append((flag, 'version'))
34                 del kwargs['version_flags']
35
36             if 'debug_flags' in kwargs:
37                 for flag in kwargs['debug_flags']:
38                     define_macros.append((flag, 'debug'))
39                 del kwargs['debug_flags']
40
41         # Pass in the extension name so the compiler class can know it
42         if 'name' in kwargs:
43             define_macros.append((kwargs['name'], 'name'))
44         elif len(args) > 0:
45             define_macros.append((args[0], 'name'))
46
47         # Pass in the 'tango' flag, also
48         with_tango = kwargs.pop('tango', False)
49         if with_tango:
50             define_macros.append(('Pyd_with_Tango', 'version'))
51         kwargs['define_macros'] = define_macros
52
53         # Similarly, pass in with_pyd, &c, via define_macros.
54         if 'raw_only' in kwargs:
55             kwargs['with_pyd'] = False
56             kwargs['with_st'] = False
57             kwargs['with_meta'] = False
58             kwargs['with_main'] = False
59             del kwargs['raw_only']
60         with_pyd  = kwargs.pop('with_pyd', True)
61         with_st   = kwargs.pop('with_st', False) # 5/23/07 st off by default.
62         # StackThreads doesn't work with Tango at the moment.
63         if with_tango:
64             with_st = False
65         with_meta = kwargs.pop('with_meta', True)
66         with_main = kwargs.pop('with_main', True)
67         if with_pyd and not with_meta:
68             raise DistutilsOptionError(
69                 'Cannot specify with_meta=False while using Pyd. Specify'
70                 ' raw_only=True or with_pyd=False if you want to compile a raw Python/C'
71                 ' extension.'
72             )
73         if with_main and not with_pyd:
74             # The special PydMain function should only be used when using Pyd
75             with_main = False
76
77         define_macros.append(((with_pyd, with_st, with_meta, with_main), 'aux'))
78
79         std_Extension.__init__(self, *args, **kwargs)
Note: See TracBrowser for help on using the browser.