lit: Add support for 'REQUIRES: feature-one, feature-two, ...' in the
[oota-llvm.git] / utils / lit / lit / TestingConfig.py
1 import os
2
3 class TestingConfig:
4     """"
5     TestingConfig - Information on the tests inside a suite.
6     """
7
8     @staticmethod
9     def frompath(path, parent, litConfig, mustExist, config = None):
10         if config is None:
11             # Set the environment based on the command line arguments.
12             environment = {
13                 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''),
14                 'PATH' : os.pathsep.join(litConfig.path +
15                                          [os.environ.get('PATH','')]),
16                 'PATHEXT' : os.environ.get('PATHEXT',''),
17                 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
18                 'LLVM_DISABLE_CRT_DEBUG' : '1',
19                 }
20
21             config = TestingConfig(parent,
22                                    name = '<unnamed>',
23                                    suffixes = set(),
24                                    test_format = None,
25                                    environment = environment,
26                                    substitutions = [],
27                                    unsupported = False,
28                                    on_clone = None,
29                                    test_exec_root = None,
30                                    test_source_root = None,
31                                    excludes = [],
32                                    available_features = [])
33
34         if os.path.exists(path):
35             # FIXME: Improve detection and error reporting of errors in the
36             # config file.
37             f = open(path)
38             cfg_globals = dict(globals())
39             cfg_globals['config'] = config
40             cfg_globals['lit'] = litConfig
41             cfg_globals['__file__'] = path
42             try:
43                 exec f in cfg_globals
44             except SystemExit,status:
45                 # We allow normal system exit inside a config file to just
46                 # return control without error.
47                 if status.args:
48                     raise
49             f.close()
50         elif mustExist:
51             litConfig.fatal('unable to load config from %r ' % path)
52
53         config.finish(litConfig)
54         return config
55
56     def __init__(self, parent, name, suffixes, test_format,
57                  environment, substitutions, unsupported, on_clone,
58                  test_exec_root, test_source_root, excludes,
59                  available_features):
60         self.parent = parent
61         self.name = str(name)
62         self.suffixes = set(suffixes)
63         self.test_format = test_format
64         self.environment = dict(environment)
65         self.substitutions = list(substitutions)
66         self.unsupported = unsupported
67         self.on_clone = on_clone
68         self.test_exec_root = test_exec_root
69         self.test_source_root = test_source_root
70         self.excludes = set(excludes)
71         self.available_features = set(available_features)
72
73     def clone(self, path):
74         # FIXME: Chain implementations?
75         #
76         # FIXME: Allow extra parameters?
77         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
78                             self.environment, self.substitutions,
79                             self.unsupported, self.on_clone,
80                             self.test_exec_root, self.test_source_root,
81                             self.excludes, self.available_features)
82         if cfg.on_clone:
83             cfg.on_clone(self, cfg, path)
84         return cfg
85
86     def finish(self, litConfig):
87         """finish() - Finish this config object, after loading is complete."""
88
89         self.name = str(self.name)
90         self.suffixes = set(self.suffixes)
91         self.environment = dict(self.environment)
92         self.substitutions = list(self.substitutions)
93         if self.test_exec_root is not None:
94             # FIXME: This should really only be suite in test suite config
95             # files. Should we distinguish them?
96             self.test_exec_root = str(self.test_exec_root)
97         if self.test_source_root is not None:
98             # FIXME: This should really only be suite in test suite config
99             # files. Should we distinguish them?
100             self.test_source_root = str(self.test_source_root)
101         self.excludes = set(self.excludes)