Teach lit's SyntaxCheckTest two new tricks:
[oota-llvm.git] / utils / 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 built-in formats.
12     import LitFormats as formats
13
14     # Provide access to built-in utility functions.
15     import Util as util
16
17     def __init__(self, progname, path, quiet,
18                  useValgrind, valgrindArgs,
19                  useTclAsSh,
20                  noExecute, debug, isWindows,
21                  params):
22         # The name of the test runner.
23         self.progname = progname
24         # The items to add to the PATH environment variable.
25         self.path = list(map(str, path))
26         self.quiet = bool(quiet)
27         self.useValgrind = bool(useValgrind)
28         self.valgrindArgs = list(valgrindArgs)
29         self.useTclAsSh = bool(useTclAsSh)
30         self.noExecute = noExecute
31         self.debug = debug
32         self.isWindows = bool(isWindows)
33         self.params = dict(params)
34         self.bashPath = None
35
36         self.numErrors = 0
37         self.numWarnings = 0
38
39     def load_config(self, config, path):
40         """load_config(config, path) - Load a config object from an alternate
41         path."""
42         from TestingConfig import TestingConfig
43         return TestingConfig.frompath(path, config.parent, self,
44                                       mustExist = True,
45                                       config = config)
46
47     def getBashPath(self):
48         """getBashPath - Get the path to 'bash'"""
49         import os, Util
50
51         if self.bashPath is not None:
52             return self.bashPath
53
54         self.bashPath = Util.which('bash', os.pathsep.join(self.path))
55         if self.bashPath is None:
56             # Check some known paths.
57             for path in ('/bin/bash', '/usr/bin/bash'):
58                 if os.path.exists(path):
59                     self.bashPath = path
60                     break
61
62         if self.bashPath is None:
63             self.warning("Unable to find 'bash', running Tcl tests internally.")
64             self.bashPath = ''
65
66         return self.bashPath
67
68     def _write_message(self, kind, message):
69         import inspect, os, sys
70
71         # Get the file/line where this message was generated.
72         f = inspect.currentframe()
73         # Step out of _write_message, and then out of wrapper.
74         f = f.f_back.f_back
75         file,line,_,_,_ = inspect.getframeinfo(f)
76         location = '%s:%d' % (os.path.basename(file), line)
77
78         print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
79                                                 kind, message)
80
81     def note(self, message):
82         self._write_message('note', message)
83
84     def warning(self, message):
85         self._write_message('warning', message)
86         self.numWarnings += 1
87
88     def error(self, message):
89         self._write_message('error', message)
90         self.numErrors += 1
91
92     def fatal(self, message):
93         import sys
94         self._write_message('fatal', message)
95         sys.exit(2)