[lit] Remove dead ignoreStdError argument.
[oota-llvm.git] / utils / lit / lit / LitConfig.py
1 class LitConfig:
2     """LitConfig - Configuration data for a 'lit' test runner instance, shared
3     across all tests.
4
5     The LitConfig object is also used to communicate with client configuration
6     files, it is always passed in as the global variable 'lit' so that
7     configuration files can access common functionality and internal components
8     easily.
9     """
10
11     # Provide access to Test module.
12     import Test
13
14     # Provide access to built-in formats.
15     import TestFormats as formats
16
17     # Provide access to built-in utility functions.
18     import Util as util
19
20     def __init__(self, progname, path, quiet,
21                  useValgrind, valgrindLeakCheck, valgrindArgs,
22                  noExecute, debug, isWindows,
23                  params, config_prefix = None):
24         # The name of the test runner.
25         self.progname = progname
26         # The items to add to the PATH environment variable.
27         self.path = list(map(str, path))
28         self.quiet = bool(quiet)
29         self.useValgrind = bool(useValgrind)
30         self.valgrindLeakCheck = bool(valgrindLeakCheck)
31         self.valgrindUserArgs = list(valgrindArgs)
32         self.noExecute = noExecute
33         self.debug = debug
34         self.isWindows = bool(isWindows)
35         self.params = dict(params)
36         self.bashPath = None
37
38         # Configuration files to look for when discovering test suites.
39         self.config_prefix = config_prefix or 'lit'
40         self.config_name = '%s.cfg' % (self.config_prefix,)
41         self.site_config_name = '%s.site.cfg' % (self.config_prefix,)
42         self.local_config_name = '%s.local.cfg' % (self.config_prefix,)
43
44         self.numErrors = 0
45         self.numWarnings = 0
46
47         self.valgrindArgs = []
48         if self.useValgrind:
49             self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
50                                  '--tool=memcheck', '--trace-children=yes',
51                                  '--error-exitcode=123']
52             if self.valgrindLeakCheck:
53                 self.valgrindArgs.append('--leak-check=full')
54             else:
55                 # The default is 'summary'.
56                 self.valgrindArgs.append('--leak-check=no')
57             self.valgrindArgs.extend(self.valgrindUserArgs)
58
59
60     def load_config(self, config, path):
61         """load_config(config, path) - Load a config object from an alternate
62         path."""
63         from TestingConfig import TestingConfig
64         if self.debug:
65             self.note('load_config from %r' % path)
66         return TestingConfig.frompath(path, config.parent, self,
67                                       mustExist = True,
68                                       config = config)
69
70     def getBashPath(self):
71         """getBashPath - Get the path to 'bash'"""
72         import os, Util
73
74         if self.bashPath is not None:
75             return self.bashPath
76
77         self.bashPath = Util.which('bash', os.pathsep.join(self.path))
78         if self.bashPath is None:
79             # Check some known paths.
80             for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
81                 if os.path.exists(path):
82                     self.bashPath = path
83                     break
84
85         if self.bashPath is None:
86             self.warning("Unable to find 'bash'.")
87             self.bashPath = ''
88
89         return self.bashPath
90
91     def getToolsPath(self, dir, paths, tools):
92         import os, Util
93         if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
94             if not Util.checkToolsPath(dir, tools):
95                 return None
96         else:
97             dir = Util.whichTools(tools, paths)
98
99         # bash
100         self.bashPath = Util.which('bash', dir)
101         if self.bashPath is None:
102             self.note("Unable to find 'bash.exe'.")
103             self.bashPath = ''
104
105         return dir
106
107     def _write_message(self, kind, message):
108         import inspect, os, sys
109
110         # Get the file/line where this message was generated.
111         f = inspect.currentframe()
112         # Step out of _write_message, and then out of wrapper.
113         f = f.f_back.f_back
114         file,line,_,_,_ = inspect.getframeinfo(f)
115         location = '%s:%d' % (os.path.basename(file), line)
116
117         print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
118                                                 kind, message)
119
120     def note(self, message):
121         self._write_message('note', message)
122
123     def warning(self, message):
124         self._write_message('warning', message)
125         self.numWarnings += 1
126
127     def error(self, message):
128         self._write_message('error', message)
129         self.numErrors += 1
130
131     def fatal(self, message):
132         import sys
133         self._write_message('fatal', message)
134         sys.exit(2)