Move the default back to pipefail. I accidentally reverted it before.
[oota-llvm.git] / utils / lit / lit / TestingConfig.py
1 import os
2 import sys
3
4 class TestingConfig:
5     """"
6     TestingConfig - Information on the tests inside a suite.
7     """
8
9     @staticmethod
10     def frompath(path, parent, litConfig, mustExist, config = None):
11         if config is None:
12             # Set the environment based on the command line arguments.
13             environment = {
14                 'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''),
15                 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''),
16                 'PATH' : os.pathsep.join(litConfig.path +
17                                          [os.environ.get('PATH','')]),
18                 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
19                 'TERM' : os.environ.get('TERM',''),
20                 'LLVM_DISABLE_CRASH_REPORT' : '1',
21                 }
22
23             if sys.platform == 'win32':
24                 environment.update({
25                         'INCLUDE' : os.environ.get('INCLUDE',''),
26                         'PATHEXT' : os.environ.get('PATHEXT',''),
27                         'PYTHONUNBUFFERED' : '1',
28                         'TEMP' : os.environ.get('TEMP',''),
29                         'TMP' : os.environ.get('TMP',''),
30                         })
31
32             # Set the default available features based on the LitConfig.
33             available_features = []
34             if litConfig.useValgrind:
35                 available_features.append('valgrind')
36                 if litConfig.valgrindLeakCheck:
37                     available_features.append('vg_leak')
38
39             config = TestingConfig(parent,
40                                    name = '<unnamed>',
41                                    suffixes = set(),
42                                    test_format = None,
43                                    environment = environment,
44                                    substitutions = [],
45                                    unsupported = False,
46                                    on_clone = None,
47                                    test_exec_root = None,
48                                    test_source_root = None,
49                                    excludes = [],
50                                    available_features = available_features,
51                                    pipefail = True)
52
53         if os.path.exists(path):
54             # FIXME: Improve detection and error reporting of errors in the
55             # config file.
56             f = open(path)
57             cfg_globals = dict(globals())
58             cfg_globals['config'] = config
59             cfg_globals['lit'] = litConfig
60             cfg_globals['__file__'] = path
61             try:
62                 exec f in cfg_globals
63                 if litConfig.debug:
64                     litConfig.note('... loaded config %r' % path)
65             except SystemExit,status:
66                 # We allow normal system exit inside a config file to just
67                 # return control without error.
68                 if status.args:
69                     raise
70             f.close()
71         else:
72             if mustExist:
73                 litConfig.fatal('unable to load config from %r ' % path)
74             elif litConfig.debug:
75                 litConfig.note('... config not found  - %r' %path)
76
77         config.finish(litConfig)
78         return config
79
80     def __init__(self, parent, name, suffixes, test_format,
81                  environment, substitutions, unsupported, on_clone,
82                  test_exec_root, test_source_root, excludes,
83                  available_features, pipefail):
84         self.parent = parent
85         self.name = str(name)
86         self.suffixes = set(suffixes)
87         self.test_format = test_format
88         self.environment = dict(environment)
89         self.substitutions = list(substitutions)
90         self.unsupported = unsupported
91         self.on_clone = on_clone
92         self.test_exec_root = test_exec_root
93         self.test_source_root = test_source_root
94         self.excludes = set(excludes)
95         self.available_features = set(available_features)
96         self.pipefail = pipefail
97
98     def clone(self, path):
99         # FIXME: Chain implementations?
100         #
101         # FIXME: Allow extra parameters?
102         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
103                             self.environment, self.substitutions,
104                             self.unsupported, self.on_clone,
105                             self.test_exec_root, self.test_source_root,
106                             self.excludes, self.available_features,
107                             self.pipefail)
108         if cfg.on_clone:
109             cfg.on_clone(self, cfg, path)
110         return cfg
111
112     def finish(self, litConfig):
113         """finish() - Finish this config object, after loading is complete."""
114
115         self.name = str(self.name)
116         self.suffixes = set(self.suffixes)
117         self.environment = dict(self.environment)
118         self.substitutions = list(self.substitutions)
119         if self.test_exec_root is not None:
120             # FIXME: This should really only be suite in test suite config
121             # files. Should we distinguish them?
122             self.test_exec_root = str(self.test_exec_root)
123         if self.test_source_root is not None:
124             # FIXME: This should really only be suite in test suite config
125             # files. Should we distinguish them?
126             self.test_source_root = str(self.test_source_root)
127         self.excludes = set(self.excludes)
128
129     @property
130     def root(self):
131         """root attribute - The root configuration for the test suite."""
132         if self.parent is None:
133             return self
134         else:
135             return self.parent.root
136