lit: Fix exclude dirs functionality.
[oota-llvm.git] / utils / 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
32         if os.path.exists(path):
33             # FIXME: Improve detection and error reporting of errors in the
34             # config file.
35             f = open(path)
36             cfg_globals = dict(globals())
37             cfg_globals['config'] = config
38             cfg_globals['lit'] = litConfig
39             cfg_globals['__file__'] = path
40             try:
41                 exec f in cfg_globals
42             except SystemExit,status:
43                 # We allow normal system exit inside a config file to just
44                 # return control without error.
45                 if status.args:
46                     raise
47             f.close()
48         elif mustExist:
49             litConfig.fatal('unable to load config from %r ' % path)
50
51         config.finish(litConfig)
52         return config
53
54     def __init__(self, parent, name, suffixes, test_format,
55                  environment, substitutions, unsupported, on_clone,
56                  test_exec_root, test_source_root, excludes):
57         self.parent = parent
58         self.name = str(name)
59         self.suffixes = set(suffixes)
60         self.test_format = test_format
61         self.environment = dict(environment)
62         self.substitutions = list(substitutions)
63         self.unsupported = unsupported
64         self.on_clone = on_clone
65         self.test_exec_root = test_exec_root
66         self.test_source_root = test_source_root
67         self.excludes = set(excludes)
68
69     def clone(self, path):
70         # FIXME: Chain implementations?
71         #
72         # FIXME: Allow extra parameters?
73         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
74                             self.environment, self.substitutions,
75                             self.unsupported, self.on_clone,
76                             self.test_exec_root, self.test_source_root,
77                             self.excludes)
78         if cfg.on_clone:
79             cfg.on_clone(self, cfg, path)
80         return cfg
81
82     def finish(self, litConfig):
83         """finish() - Finish this config object, after loading is complete."""
84
85         self.name = str(self.name)
86         self.suffixes = set(self.suffixes)
87         self.environment = dict(self.environment)
88         self.substitutions = list(self.substitutions)
89         if self.test_exec_root is not None:
90             # FIXME: This should really only be suite in test suite config
91             # files. Should we distinguish them?
92             self.test_exec_root = str(self.test_exec_root)
93         if self.test_source_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_source_root = str(self.test_source_root)
97         self.excludes = set(self.excludes)