43
43
variable. It should contain a comma separated list.
44
44
"""
45
45
import CmpRuns
46
+ import SATestUtils
46
47
47
48
import os
48
49
import csv
53
54
import time
54
55
import plistlib
55
56
import argparse
56
- from subprocess import check_call , check_output , CalledProcessError
57
+ from subprocess import check_call , CalledProcessError
57
58
import multiprocessing
58
59
59
60
#------------------------------------------------------------------------------
60
61
# Helper functions.
61
62
#------------------------------------------------------------------------------
62
63
63
64
64
- def which (command , paths = None ):
65
- """which(command, [paths]) - Look up the given command in the paths string
66
- (or the PATH environment variable, if unspecified)."""
67
-
68
- if paths is None :
69
- paths = os .environ .get ('PATH' , '' )
70
-
71
- # Check for absolute match first.
72
- if os .path .exists (command ):
73
- return command
74
-
75
- # Would be nice if Python had a lib function for this.
76
- if not paths :
77
- paths = os .defpath
78
-
79
- # Get suffixes to search.
80
- # On Cygwin, 'PATHEXT' may exist but it should not be used.
81
- if os .pathsep == ';' :
82
- pathext = os .environ .get ('PATHEXT' , '' ).split (';' )
83
- else :
84
- pathext = ['' ]
85
-
86
- # Search the paths...
87
- for path in paths .split (os .pathsep ):
88
- for ext in pathext :
89
- p = os .path .join (path , command + ext )
90
- if os .path .exists (p ):
91
- return p
92
-
93
- return None
94
-
95
-
96
- class flushfile (object ):
97
- """
98
- Wrapper to flush the output after every print statement.
99
- """
100
- def __init__ (self , f ):
101
- self .f = f
102
-
103
- def write (self , x ):
104
- self .f .write (x )
105
- self .f .flush ()
106
-
107
-
108
- sys .stdout = flushfile (sys .stdout )
65
+ sys .stdout = SATestUtils .flushfile (sys .stdout )
109
66
110
67
111
68
def getProjectMapPath ():
@@ -137,7 +94,7 @@ def getSBOutputDirName(IsReferenceBuild):
137
94
if 'CC' in os .environ :
138
95
Clang = os .environ ['CC' ]
139
96
else :
140
- Clang = which ("clang" , os .environ ['PATH' ])
97
+ Clang = SATestUtils . which ("clang" , os .environ ['PATH' ])
141
98
if not Clang :
142
99
print "Error: cannot find 'clang' in PATH"
143
100
sys .exit (- 1 )
@@ -215,37 +172,15 @@ def runCleanupScript(Dir, PBuildLogFile):
215
172
"""
216
173
Cwd = os .path .join (Dir , PatchedSourceDirName )
217
174
ScriptPath = os .path .join (Dir , CleanupScript )
218
- runScript (ScriptPath , PBuildLogFile , Cwd )
175
+ SATestUtils . runScript (ScriptPath , PBuildLogFile , Cwd )
219
176
220
177
221
178
def runDownloadScript (Dir , PBuildLogFile ):
222
179
"""
223
180
Run the script to download the project, if it exists.
224
181
"""
225
182
ScriptPath = os .path .join (Dir , DownloadScript )
226
- runScript (ScriptPath , PBuildLogFile , Dir )
227
-
228
-
229
- def runScript (ScriptPath , PBuildLogFile , Cwd ):
230
- """
231
- Run the provided script if it exists.
232
- """
233
- if os .path .exists (ScriptPath ):
234
- try :
235
- if Verbose == 1 :
236
- print " Executing: %s" % (ScriptPath ,)
237
- check_call ("chmod +x '%s'" % ScriptPath , cwd = Cwd ,
238
- stderr = PBuildLogFile ,
239
- stdout = PBuildLogFile ,
240
- shell = True )
241
- check_call ("'%s'" % ScriptPath , cwd = Cwd ,
242
- stderr = PBuildLogFile ,
243
- stdout = PBuildLogFile ,
244
- shell = True )
245
- except :
246
- print "Error: Running %s failed. See %s for details." % (
247
- ScriptPath , PBuildLogFile .name )
248
- sys .exit (- 1 )
183
+ SATestUtils .runScript (ScriptPath , PBuildLogFile , Dir )
249
184
250
185
251
186
def downloadAndPatch (Dir , PBuildLogFile ):
@@ -343,28 +278,6 @@ def runScanBuild(Dir, SBOutputDir, PBuildLogFile):
343
278
raise
344
279
345
280
346
- def hasNoExtension (FileName ):
347
- (Root , Ext ) = os .path .splitext (FileName )
348
- return (Ext == "" )
349
-
350
-
351
- def isValidSingleInputFile (FileName ):
352
- (Root , Ext ) = os .path .splitext (FileName )
353
- return Ext in (".i" , ".ii" , ".c" , ".cpp" , ".m" , "" )
354
-
355
-
356
- def getSDKPath (SDKName ):
357
- """
358
- Get the path to the SDK for the given SDK name. Returns None if
359
- the path cannot be determined.
360
- """
361
- if which ("xcrun" ) is None :
362
- return None
363
-
364
- Cmd = "xcrun --sdk " + SDKName + " --show-sdk-path"
365
- return check_output (Cmd , shell = True ).rstrip ()
366
-
367
-
368
281
def runAnalyzePreprocessed (Dir , SBOutputDir , Mode ):
369
282
"""
370
283
Run analysis on a set of preprocessed files.
@@ -378,7 +291,7 @@ def runAnalyzePreprocessed(Dir, SBOutputDir, Mode):
378
291
379
292
# For now, we assume the preprocessed files should be analyzed
380
293
# with the OS X SDK.
381
- SDKPath = getSDKPath ("macosx" )
294
+ SDKPath = SATestUtils . getSDKPath ("macosx" )
382
295
if SDKPath is not None :
383
296
CmdPrefix += "-isysroot " + SDKPath + " "
384
297
@@ -398,9 +311,9 @@ def runAnalyzePreprocessed(Dir, SBOutputDir, Mode):
398
311
Failed = False
399
312
400
313
# Only run the analyzes on supported files.
401
- if ( hasNoExtension (FileName ) ):
314
+ if SATestUtils . hasNoExtension (FileName ):
402
315
continue
403
- if ( not isValidSingleInputFile (FileName ) ):
316
+ if not SATestUtils . isValidSingleInputFile (FileName ):
404
317
print "Error: Invalid single input file %s." % (FullFileName ,)
405
318
raise Exception ()
406
319
@@ -563,14 +476,6 @@ def checkBuild(SBOutputDir):
563
476
sys .exit (- 1 )
564
477
565
478
566
- class Discarder (object ):
567
- """
568
- Auxiliary object to discard stdout.
569
- """
570
- def write (self , text ):
571
- pass # do nothing
572
-
573
-
574
479
def runCmpResults (Dir , Strictness = 0 ):
575
480
"""
576
481
Compare the warnings produced by scan-build.
@@ -624,7 +529,7 @@ def runCmpResults(Dir, Strictness=0):
624
529
# Discard everything coming out of stdout
625
530
# (CmpRun produces a lot of them).
626
531
OLD_STDOUT = sys .stdout
627
- sys .stdout = Discarder ()
532
+ sys .stdout = SATestUtils . Discarder ()
628
533
# Scan the results, delete empty plist files.
629
534
NumDiffs , ReportsInRef , ReportsInNew = \
630
535
CmpRuns .dumpScanBuildResultsDiff (RefDir , NewDir , Opts , False )
@@ -694,13 +599,6 @@ def testProject(ID, ProjectBuildMode, IsReferenceBuild=False, Strictness=0):
694
599
return TestsPassed
695
600
696
601
697
- def isCommentCSVLine (Entries ):
698
- """
699
- Treat CSV lines starting with a '#' as a comment.
700
- """
701
- return len (Entries ) > 0 and Entries [0 ].startswith ("#" )
702
-
703
-
704
602
def projectFileHandler ():
705
603
return open (getProjectMapPath (), "rb" )
706
604
@@ -712,7 +610,7 @@ def iterateOverProjects(PMapFile):
712
610
"""
713
611
PMapFile .seek (0 )
714
612
for I in csv .reader (PMapFile ):
715
- if (isCommentCSVLine (I )):
613
+ if (SATestUtils . isCommentCSVLine (I )):
716
614
continue
717
615
yield I
718
616
@@ -722,10 +620,10 @@ def validateProjectFile(PMapFile):
722
620
Validate project file.
723
621
"""
724
622
for I in iterateOverProjects (PMapFile ):
725
- if ( len (I ) != 2 ) :
623
+ if len (I ) != 2 :
726
624
print "Error: Rows in the ProjectMapFile should have 2 entries."
727
625
raise Exception ()
728
- if ( not (( I [1 ] == "0" ) | ( I [ 1 ] == "1" ) | ( I [ 1 ] == "2" )) ):
626
+ if I [1 ] not in ( '0' , '1' , '2' ):
729
627
print "Error: Second entry in the ProjectMapFile should be 0" \
730
628
" (single file), 1 (project), or 2(single file c++11)."
731
629
raise Exception ()
@@ -763,4 +661,5 @@ def testAll(IsReferenceBuild=False, Strictness=0):
763
661
764
662
TestsPassed = testAll (IsReference , Strictness )
765
663
if not TestsPassed :
664
+ print "ERROR: Tests failed."
766
665
sys .exit (- 1 )
0 commit comments