1 """SCons.SConf
2
3 Autoconf-like configuration support.
4 """
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 __revision__ = "src/engine/SCons/SConf.py 3765 2008/11/04 08:12:16 scons"
30
31 import os
32 import re
33 import string
34 import StringIO
35 import sys
36 import traceback
37 import types
38
39 import SCons.Action
40 import SCons.Builder
41 import SCons.Errors
42 import SCons.Job
43 import SCons.Node.FS
44 import SCons.Taskmaster
45 import SCons.Util
46 import SCons.Warnings
47 import SCons.Conftest
48
49 from SCons.Debug import Trace
50
51
52 SCons.Conftest.LogInputFiles = 0
53 SCons.Conftest.LogErrorMessages = 0
54
55
56 build_type = None
57 build_types = ['clean', 'help']
58
62
63
64 dryrun = 0
65
66 AUTO=0
67 FORCE=1
68 CACHE=2
69 cache_mode = AUTO
70
72 """Set the Configure cache mode. mode must be one of "auto", "force",
73 or "cache"."""
74 global cache_mode
75 if mode == "auto":
76 cache_mode = AUTO
77 elif mode == "force":
78 cache_mode = FORCE
79 elif mode == "cache":
80 cache_mode = CACHE
81 else:
82 raise ValueError, "SCons.SConf.SetCacheMode: Unknown mode " + mode
83
84 progress_display = SCons.Util.display
89
90 SConfFS = None
91
92 _ac_build_counter = 0
93 _ac_config_logs = {}
94 _ac_config_hs = {}
95 sconf_global = None
96
98 t = open(str(target[0]), "w")
99 defname = re.sub('[^A-Za-z0-9_]', '_', string.upper(str(target[0])))
100 t.write("""#ifndef %(DEFNAME)s_SEEN
101 #define %(DEFNAME)s_SEEN
102
103 """ % {'DEFNAME' : defname})
104 t.write(source[0].get_contents())
105 t.write("""
106 #endif /* %(DEFNAME)s_SEEN */
107 """ % {'DEFNAME' : defname})
108 t.close()
109
111 return "scons: Configure: creating " + str(target[0])
112
123
126 SCons.Warnings.enableWarningClass(SConfWarning)
127
128
132
142
148
149
155 return (str(target[0]) + ' <-\n |' +
156 string.replace( source[0].get_contents(),
157 '\n', "\n |" ) )
158
159
160 BooleanTypes = [types.IntType]
161 if hasattr(types, 'BooleanType'): BooleanTypes.append(types.BooleanType)
162
164 """
165 Special build info for targets of configure tests. Additional members
166 are result (did the builder succeed last time?) and string, which
167 contains messages of the original build phase.
168 """
169 result = None
170 string = None
171
175
176
178 """
179 'Sniffer' for a file-like writable object. Similar to the unix tool tee.
180 """
182 self.orig = orig
183 self.s = StringIO.StringIO()
184
186 if self.orig:
187 self.orig.write(str)
188 self.s.write(str)
189
191 for l in lines:
192 self.write(l + '\n')
193
195 """
196 Return everything written to orig since the Streamer was created.
197 """
198 return self.s.getvalue()
199
201 if self.orig:
202 self.orig.flush()
203 self.s.flush()
204
205
207 """
208 This is almost the same as SCons.Script.BuildTask. Handles SConfErrors
209 correctly and knows about the current cache_mode.
210 """
214
216 """
217 Logs the original builder messages, given the SConfBuildInfo instance
218 bi.
219 """
220 if not isinstance(bi, SConfBuildInfo):
221 SCons.Warnings.warn(SConfWarning,
222 "The stored build information has an unexpected class: %s" % bi.__class__)
223 else:
224 self.display("The original builder output was:\n" +
225 string.replace(" |" + str(bi.string),
226 "\n", "\n |"))
227
229
230
231 exc_type = self.exc_info()[0]
232 if issubclass(exc_type, SConfError):
233 raise
234 elif issubclass(exc_type, SCons.Errors.BuildError):
235
236
237
238 self.exc_clear()
239 else:
240 self.display('Caught exception while building "%s":\n' %
241 self.targets[0])
242 try:
243 excepthook = sys.excepthook
244 except AttributeError:
245
246 def excepthook(type, value, tb):
247 traceback.print_tb(tb)
248 print type, value
249 apply(excepthook, self.exc_info())
250 return SCons.Taskmaster.Task.failed(self)
251