Fix lit failure on cmake-clang-x64_64-linux bot, apparently due to its having
[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                 'LLVM_DISABLE_CRASH_REPORT' : '1',
20                 }
21
22             if sys.platform == 'win32':
23                 environment.update({
24                         'INCLUDE' : os.environ.get('INCLUDE',''),
25                         'PATHEXT' : os.environ.get('PATHEXT',''),
26                         'PYTHONUNBUFFERED' : '1',
27                         'TEMP' : os.environ.get('TEMP',''),
28                         'TMP' : os.environ.get('TMP',''),
29                         })
30
31             config = TestingConfig(parent,
32                                    name = '<unnamed>',
33                                    suffixes = set(),
34                                    test_format = None,
35                                    environment = environment,
36                                    substitutions = [],
37                                    unsupported = False,
38                                    on_clone = None,
39                                    test_exec_root = None,
40                                    test_source_root = None,
41                                    excludes = [],
42                                    available_features = [])
43
44         if os.path.exists(path):
45             # FIXME: Improve detection and error reporting of errors in the
46             # config file.
47             f = open(path)
48             cfg_globals = dict(globals())
49             cfg_globals['config'] = config
50             cfg_globals['lit'] = litConfig
51             cfg_globals['__file__'] = path
52             try:
53                 exec f in cfg_globals
54                 if litConfig.debug:
55                     litConfig.note('... loaded config %r' % path)
56             except SystemExit,status:
57                 # We allow normal system exit inside a config file to just
58                 # return control without error.
59                 if status.args:
60                     raise
61             f.close()
62         else:
63             if mustExist:
64                 litConfig.fatal('unable to load config from %r ' % path)
65             elif litConfig.debug:
66                 litConfig.note('... config not found  - %r' %path)
67
68         config.finish(litConfig)
69         return config
70
71     def __init__(self, parent, name, suffixes, test_format,
72                  environment, substitutions, unsupported, on_clone,
73                  test_exec_root, test_source_root, excludes,
74                  available_features):
75         self.parent = parent
76         self.name = str(name)
77         self.suffixes = set(suffixes)
78         self.test_format = test_format
79         self.environment = dict(environment)
80         self.substitutions = list(substitutions)
81         self.unsupported = unsupported
82         self.on_clone = on_clone
83         self.test_exec_root = test_exec_root
84         self.test_source_root = test_source_root
85         self.excludes = set(excludes)
86         self.available_features = set(available_features)
87
88     def clone(self, path):
89         # FIXME: Chain implementations?
90         #
91         # FIXME: Allow extra parameters?
92         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
93                             self.environment, self.substitutions,
94                             self.unsupported, self.on_clone,
95                             self.test_exec_root, self.test_source_root,
96                             self.excludes, self.available_features)
97         if cfg.on_clone:
98             cfg.on_clone(self, cfg, path)
99         return cfg
100
101     def finish(self, litConfig):
102         """finish() - Finish this config object, after loading is complete."""
103
104         self.name = str(self.name)
105         self.suffixes = set(self.suffixes)
106         self.environment = dict(self.environment)
107         self.substitutions = list(self.substitutions)
108         if self.test_exec_root is not None:
109             # FIXME: This should really only be suite in test suite config
110             # files. Should we distinguish them?
111             self.test_exec_root = str(self.test_exec_root)
112         if self.test_source_root is not None:
113             # FIXME: This should really only be suite in test suite config
114             # files. Should we distinguish them?
115             self.test_source_root = str(self.test_source_root)
116         self.excludes = set(self.excludes)
117
118     @property
119     def root(self):
120         """root attribute - The root configuration for the test suite."""
121         if self.parent is None:
122             return self
123         else:
124             return self.parent.root
125