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 2928 2008/04/29 22:44:09 knight"
30
31 import SCons.compat
32
33 import os
34 import re
35 import string
36 import StringIO
37 import sys
38 import traceback
39 import types
40
41 import SCons.Action
42 import SCons.Builder
43 import SCons.Errors
44 import SCons.Job
45 import SCons.Node.FS
46 import SCons.Taskmaster
47 import SCons.Util
48 import SCons.Warnings
49 import SCons.Conftest
50
51 from SCons.Debug import Trace
52
53
54 SCons.Conftest.LogInputFiles = 0
55 SCons.Conftest.LogErrorMessages = 0
56
57
58 build_type = None
59 build_types = ['clean', 'help']
60
64
65
66 dryrun = 0
67
68 AUTO=0
69 FORCE=1
70 CACHE=2
71 cache_mode = AUTO
72
74 """Set the Configure cache mode. mode must be one of "auto", "force",
75 or "cache"."""
76 global cache_mode
77 if mode == "auto":
78 cache_mode = AUTO
79 elif mode == "force":
80 cache_mode = FORCE
81 elif mode == "cache":
82 cache_mode = CACHE
83 else:
84 raise ValueError, "SCons.SConf.SetCacheMode: Unknown mode " + mode
85
86 progress_display = SCons.Util.display
91
92 SConfFS = None
93
94 _ac_build_counter = 0
95 _ac_config_logs = {}
96 _ac_config_hs = {}
97 sconf_global = None
98
100 t = open(str(target[0]), "w")
101 defname = re.sub('[^A-Za-z0-9_]', '_', string.upper(str(target[0])))
102 t.write("""#ifndef %(DEFNAME)s_SEEN
103 #define %(DEFNAME)s_SEEN
104
105 """ % {'DEFNAME' : defname})
106 t.write(source[0].get_contents())
107 t.write("""
108 #endif /* %(DEFNAME)s_SEEN */
109 """ % {'DEFNAME' : defname})
110 t.close()
111
113 return "scons: Configure: creating " + str(target[0])
114
125
128 SCons.Warnings.enableWarningClass(SConfWarning)
129
130
134
144
150
151
157 return (str(target[0]) + ' <-\n |' +
158 string.replace( source[0].get_contents(),
159 '\n', "\n |" ) )
160
161
162 BooleanTypes = [types.IntType]
163 if hasattr(types, 'BooleanType'): BooleanTypes.append(types.BooleanType)
164
166 """
167 Special build info for targets of configure tests. Additional members
168 are result (did the builder succeed last time?) and string, which
169 contains messages of the original build phase.
170 """
171 result = None
172 string = None
173
177
178
180 """
181 'Sniffer' for a file-like writable object. Similar to the unix tool tee.
182 """
184 self.orig = orig
185 self.s = StringIO.StringIO()
186
188 if self.orig:
189 self.orig.write(str)
190 self.s.write(str)
191
193 for l in lines:
194 self.write(l + '\n')
195
197 """
198 Return everything written to orig since the Streamer was created.
199 """
200 return self.s.getvalue()
201
203 if self.orig:
204 self.orig.flush()
205 self.s.flush()
206
207
209 """
210 This is almost the same as SCons.Script.BuildTask. Handles SConfErrors
211 correctly and knows about the current cache_mode.
212 """
216
218 """
219 Logs the original builder messages, given the SConfBuildInfo instance
220 bi.
221 """
222 if not isinstance(bi, SConfBuildInfo):
223 SCons.Warnings.warn(SConfWarning,
224 "The stored build information has an unexpected class: %s" % bi.__class__)
225 else:
226 self.display("The original builder output was:\n" +
227 string.replace(" |" + str(bi.string),
228 "\n", "\n |"))
229
231
232
233 exc_type = self.exc_info()[0]
234 if issubclass(exc_type, SConfError):
235 raise
236 elif issubclass(exc_type, SCons.Errors.BuildError):
237
238 pass
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