]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/test/collect_debug_info.py
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / tools / build / test / collect_debug_info.py
CommitLineData
7c673cae
FG
1#!/usr/bin/python
2
3# Copyright 2012 Jurko Gospodnetic
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7# Temporarily enabled dummy test that always fails and is used to collect
8# extra debugging information from Boost Build test runner sites.
9
10import BoostBuild
11
12import os
13import re
14import sys
15
16
17###############################################################################
18#
19# Public interface.
20#
21###############################################################################
22
23def collectDebugInfo():
24 t = _init()
25
26 global tag
27
28 tag = "Python version"
29 try:
30 _info(sys.version)
31 except:
32 _info_exc()
33
34 tag = "Python platform"
35 try:
36 _info(sys.platform)
37 except:
38 _info_exc()
39
40 tag = "Boost Jam/Build version"
41 try:
42 _infoX(_getJamVersionInfo(t))
43 except:
44 _info_exc()
45
46 #_collectDebugInfo_environ()
47
48 # Report prepared annotations.
49 t.fail_test(1, dump_difference=False, dump_stdio=False, dump_stack=False)
50
51
52###############################################################################
53#
54# Private interface.
55#
56###############################################################################
57
58varSeparator = "###$^%~~~"
59
60
61def _collect(results, prefix, name, t):
62 results.append("%s - %s - os.getenv(): %r" % (prefix, name, os.getenv(
63 name)))
64 results.append("%s - %s - os.environ.get(): %r" % (prefix, name,
65 os.environ.get(name)))
66 external_values = _getExternalValues(t, name)
67 results.append("%s - %s - external: %r" % (prefix, name,
68 external_values[name]))
69
70
71def _collectDebugInfo_environ(t):
92f5a8d4 72 dummyVars = ["WOOF_WOOFIE_%d" % x for x in range(4)]
7c673cae
FG
73 global tag
74
75 tag = "XXX in os.environ"
76 try:
77 def f(name):
78 return "%s: %s" % (name, name in os.environ)
79 _infoX(f(x) for x in dummyVars)
80 except:
81 _info_exc()
82
83 tag = "os.environ[XXX]"
84 try:
85 def f(name):
86 try:
87 result = os.environ[name]
88 except:
89 result = _str_exc()
90 return "%s: %r" % (name, result)
91 _infoX(f(x) for x in dummyVars)
92 except:
93 _info_exc()
94
95 tag = "os.environ.get(XXX)"
96 try:
97 def f(name):
98 return "%s: %r" % (name, os.environ.get(name))
99 _infoX(f(x) for x in dummyVars)
100 except:
101 _info_exc()
102
103 tag = "os.getenv(XXX)"
104 try:
105 def f(name):
106 return "%s: %r" % (name, os.getenv(name))
107 _infoX(f(x) for x in dummyVars)
108 except:
109 _info_exc()
110
111 name = dummyVars[0]
112 value = "foo"
113 tag = "os.putenv(%s) to %r" % (name, value)
114 try:
115 results = []
116 _collect(results, "before", name, t)
117 os.putenv(name, value)
118 _collect(results, "after", name, t)
119 _infoX(results)
120 except:
121 _info_exc()
122
123 name = dummyVars[1]
124 value = "bar"
125 tag = "os.environ[%s] to %r" % (name, value)
126 try:
127 results = []
128 _collect(results, "before", name, t)
129 os.environ[name] = value
130 _collect(results, "after", name, t)
131 _infoX(results)
132 except:
133 _info_exc()
134
135 name = dummyVars[1]
136 value = "baz"
137 tag = "os.putenv(%s) to %r" % (name, value)
138 try:
139 results = []
140 _collect(results, "before", name, t)
141 os.putenv(name, value)
142 _collect(results, "after", name, t)
143 _infoX(results)
144 except:
145 _info_exc()
146
147 name = dummyVars[1]
148 value = ""
149 tag = "os.putenv(%s) to %r" % (name, value)
150 try:
151 results = []
152 _collect(results, "before", name, t)
153 os.putenv(name, value)
154 _collect(results, "after", name, t)
155 _infoX(results)
156 except:
157 _info_exc()
158
159 name = dummyVars[2]
160 value = "foo"
161 tag = "os.unsetenv(%s) from %r" % (name, value)
162 try:
163 results = []
164 os.environ[name] = value
165 _collect(results, "before", name, t)
166 os.unsetenv(name)
167 _collect(results, "after", name, t)
168 _infoX(results)
169 except:
170 _info_exc()
171
172 name = dummyVars[2]
173 value = "foo"
174 tag = "del os.environ[%s] from %r" % (name, value)
175 try:
176 results = []
177 os.environ[name] = value
178 _collect(results, "before", name, t)
179 del os.environ[name]
180 _collect(results, "after", name, t)
181 _infoX(results)
182 except:
183 _info_exc()
184
185 name = dummyVars[2]
186 value = "foo"
187 tag = "os.environ.pop(%s) from %r" % (name, value)
188 try:
189 results = []
190 os.environ[name] = value
191 _collect(results, "before", name, t)
192 os.environ.pop(name)
193 _collect(results, "after", name, t)
194 _infoX(results)
195 except:
196 _info_exc()
197
198 name = dummyVars[2]
199 value1 = "foo"
200 value2 = ""
201 tag = "os.environ[%s] to %r from %r" % (name, value2, value1)
202 try:
203 results = []
204 os.environ[name] = value1
205 _collect(results, "before", name, t)
206 os.environ[name] = value2
207 _collect(results, "after", name, t)
208 _infoX(results)
209 except:
210 _info_exc()
211
212 name = dummyVars[3]
213 value = '""'
214 tag = "os.environ[%s] to %r" % (name, value)
215 try:
216 results = []
217 _collect(results, "before", name, t)
218 os.environ[name] = value
219 _collect(results, "after", name, t)
220 _infoX(results)
221 except:
222 _info_exc()
223
224
225def _getExternalValues(t, *args):
226 t.run_build_system(["---var-name=%s" % x for x in args])
227 result = dict()
228 for x in args:
229 m = re.search(r"^\*\*\*ENV\*\*\* %s: '(.*)' \*\*\*$" % x, t.stdout(),
230 re.MULTILINE)
231 if m:
232 result[x] = m.group(1)
233 else:
234 result[x] = None
235 return result
236
237
238def _getJamVersionInfo(t):
239 result = []
240
241 # JAM version variables.
242 t.run_build_system(["---version"])
243 for m in re.finditer(r"^\*\*\*VAR\*\*\* ([^:]*): (.*)\*\*\*$", t.stdout(),
244 re.MULTILINE):
245 name = m.group(1)
246 value = m.group(2)
247 if not value:
248 value = []
249 elif value[-1] == ' ':
250 value = value[:-1].split(varSeparator)
251 else:
252 value = "!!!INVALID!!! - '%s'" % value
253 result.append("%s = %s" % (name, value))
254 result.append("")
255
256 # bjam -v output.
257 t.run_build_system(["-v"])
258 result.append("--- output for 'bjam -v' ---")
259 result.append(t.stdout())
260
261 # bjam --version output.
262 t.run_build_system(["--version"], status=1)
263 result.append("--- output for 'bjam --version' ---")
264 result.append(t.stdout())
265
266 return result
267
268
269def _init():
270 toolsetName = "__myDummyToolset__"
271
272 t = BoostBuild.Tester(["toolset=%s" % toolsetName], pass_toolset=False,
273 use_test_config=False)
274
275 # Prepare a dummy toolset so we do not get errors in case the default one
276 # is not found.
277 t.write(toolsetName + ".jam", """\
278import feature ;
279feature.extend toolset : %s ;
280rule init ( ) { }
281""" % toolsetName )
282
283 # Python version of the same dummy toolset.
284 t.write(toolsetName + ".py", """\
285from b2.build import feature
286feature.extend('toolset', ['%s'])
287def init(): pass
288""" % toolsetName )
289
290 t.write("jamroot.jam", """\
291import os ;
292.argv = [ modules.peek : ARGV ] ;
293local names = [ MATCH ^---var-name=(.*) : $(.argv) ] ;
294for x in $(names)
295{
296 value = [ os.environ $(x) ] ;
297 ECHO ***ENV*** $(x): '$(value)' *** ;
298}
299if ---version in $(.argv)
300{
301 for x in JAMVERSION JAM_VERSION JAMUNAME JAM_TIMESTAMP_RESOLUTION OS
302 {
303 v = [ modules.peek : $(x) ] ;
304 ECHO ***VAR*** $(x): "$(v:J=%s)" *** ;
305 }
306}
307""" % varSeparator)
308
309 return t
310
311
312def _info(*values):
313 values = list(values) + [""]
314 BoostBuild.annotation(tag, "\n".join(str(x) for x in values))
315
316
317def _infoX(values):
318 _info(*values)
319
320
321def _info_exc():
322 _info(_str_exc())
323
324
325def _str_exc():
326 exc_type, exc_value = sys.exc_info()[0:2]
327 if exc_type is None:
328 exc_type_name = "None"
329 else:
330 exc_type_name = exc_type.__name__
331 return "*** EXCEPTION *** %s - %s ***" % (exc_type_name, exc_value)
332
333
334###############################################################################
335#
336# main()
337# ------
338#
339###############################################################################
340
341collectDebugInfo()