16
16
#
17
17
18
18
import errno
19
+ import hashlib
19
20
import os
21
+ import platform
20
22
import re
21
23
import signal
22
24
import subprocess
27
29
# FIXME: Find a better place for this hack.
28
30
os .environ ['COLUMNS' ] = '0'
29
31
32
+ kSystemName = platform .system ()
33
+
30
34
class TestStatus :
31
35
Pass = 0
32
36
XFail = 1
@@ -109,6 +113,8 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
109
113
110
114
FILENAME = os .path .abspath (FILENAME )
111
115
SCRIPT = OUTPUT + '.script'
116
+ if kSystemName == 'Windows' :
117
+ SCRIPT += '.bat'
112
118
TEMPOUTPUT = OUTPUT + '.tmp'
113
119
114
120
substitutions = [('%s' ,SUBST ),
@@ -149,7 +155,12 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
149
155
outputFile = open (OUTPUT ,'w' )
150
156
p = None
151
157
try :
152
- p = subprocess .Popen (["/bin/sh" ,SCRIPT ],
158
+ if kSystemName == 'Windows' :
159
+ command = ['cmd' ,'/c' , SCRIPT ]
160
+ else :
161
+ command = ['/bin/sh' , SCRIPT ]
162
+
163
+ p = subprocess .Popen (command ,
153
164
cwd = os .path .dirname (FILENAME ),
154
165
stdin = subprocess .PIPE ,
155
166
stdout = subprocess .PIPE ,
@@ -170,7 +181,10 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
170
181
SCRIPT_STATUS = not SCRIPT_STATUS
171
182
172
183
if useValgrind :
173
- VG_OUTPUT = capture (['/bin/sh' ,'-c' ,'cat %s.*' % (VG_OUTPUT )])
184
+ if kSystemName == 'Windows' :
185
+ raise NotImplementedError ,'Cannot run valgrind on windows'
186
+ else :
187
+ VG_OUTPUT = capture (['/bin/sh' ,'-c' ,'cat %s.*' % (VG_OUTPUT )])
174
188
VG_STATUS = len (VG_OUTPUT )
175
189
else :
176
190
VG_STATUS = 0
@@ -200,16 +214,30 @@ def runOneTest(FILENAME, SUBST, OUTPUT, TESTNAME, CLANG, CLANGCC,
200
214
return TestStatus .Pass
201
215
202
216
def capture (args ):
203
- p = subprocess .Popen (args , stdout = subprocess .PIPE )
217
+ p = subprocess .Popen (args , stdout = subprocess .PIPE , stderr = subprocess . PIPE )
204
218
out ,_ = p .communicate ()
205
219
return out
206
220
207
221
def which (command ):
222
+ # Check for absolute match first.
223
+ if os .path .exists (command ):
224
+ return command
225
+
208
226
# Would be nice if Python had a lib function for this.
209
- res = capture (['which' ,command ])
210
- res = res .strip ()
211
- if res and os .path .exists (res ):
212
- return res
227
+ paths = os .environ .get ('PATH' )
228
+ if not paths :
229
+ paths = os .defpath
230
+
231
+ # Get suffixes to search.
232
+ pathext = os .environ .get ('PATHEXT' , '' ).split (os .pathsep )
233
+
234
+ # Search the paths...
235
+ for path in paths .split (os .pathsep ):
236
+ for ext in pathext :
237
+ p = os .path .join (path , command + ext )
238
+ if os .path .exists (p ):
239
+ return p
240
+
213
241
return None
214
242
215
243
def inferClang ():
@@ -240,7 +268,11 @@ def inferClangCC(clang):
240
268
241
269
# Otherwise try adding -cc since we expect to be looking in a build
242
270
# directory.
243
- clangcc = which (clang + '-cc' )
271
+ if clang .endswith ('.exe' ):
272
+ clangccName = clang [:- 4 ] + '-cc.exe'
273
+ else :
274
+ clangccName = clang + '-cc'
275
+ clangcc = which (clangccName )
244
276
if not clangcc :
245
277
# Otherwise ask clang.
246
278
res = capture ([clang , '-print-prog-name=clang-cc' ])
0 commit comments