Remove support for Tcl test format since nobody uses it
[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 LitFormats 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, ignoreStdErr, debug, isWindows,
23                  params):
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.ignoreStdErr = ignoreStdErr
34         self.debug = debug
35         self.isWindows = bool(isWindows)
36         self.params = dict(params)
37         self.bashPath = None
38
39         self.numErrors = 0
40         self.numWarnings = 0
41
42         self.valgrindArgs = []
43         if self.useValgrind:
44             self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
45                                  '--tool=memcheck', '--trace-children=yes',
46                                  '--error-exitcode=123']
47             if self.valgrindLeakCheck:
48                 self.valgrindArgs.append('--leak-check=full')
49             else:
50                 # The default is 'summary'.
51                 self.valgrindArgs.append('--leak-check=no')
52             self.valgrindArgs.extend(self.valgrindUserArgs)
53
54
55     def load_config(self, config, path):
56         """load_config(config, path) - Load a config object from an alternate
57         path."""
58         from TestingConfig import TestingConfig
59         if self.debug:
60             self.note('load_config from %r' % path)
61         return TestingConfig.frompath(path, config.parent, self,
62                                       mustExist = True,
63                                       config = config)
64
65     def getBashPath(self):
66         """getBashPath - Get the path to 'bash'"""
67         import os, Util
68
69         if self.bashPath is not None:
70             return self.bashPath
71
72         self.bashPath = Util.which('bash', os.pathsep.join(self.path))
73         if self.bashPath is None:
74             # Check some known paths.
75             for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
76                 if os.path.exists(path):
77                     self.bashPath = path
78                     break
79
80         if self.bashPath is None:
81             self.warning("Unable to find 'bash'.")
82             self.bashPath = ''
83
84         return self.bashPath
85
86     def getToolsPath(self, dir, paths, tools):
87         import os, Util
88         if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
89             if not Util.checkToolsPath(dir, tools):
90                 return None
91         else:
92             dir = Util.whichTools(tools, paths)
93
94         # bash
95         self.bashPath = Util.which('bash', dir)
96         if self.bashPath is None:
97             self.note("Unable to find 'bash.exe'.")
98             self.bashPath = ''
99
100         return dir
101
102     def _write_message(self, kind, message):
103         import inspect, os, sys
104
105         # Get the file/line where this message was generated.
106         f = inspect.currentframe()
107         # Step out of _write_message, and then out of wrapper.
108         f = f.f_back.f_back
109         file,line,_,_,_ = inspect.getframeinfo(f)
110         location = '%s:%d' % (os.path.basename(file), line)
111
112         print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
113                                                 kind, message)
114
115     def note(self, message):
116         self._write_message('note', message)
117
118     def warning(self, message):
119         self._write_message('warning', message)
120         self.numWarnings += 1
121
122     def error(self, message):
123         self._write_message('error', message)
124         self.numErrors += 1
125
126     def fatal(self, message):
127         import sys
128         self._write_message('fatal', message)
129         sys.exit(2)