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