d6f2a4dc7111a473de8dcf601a98fc6fa65518c4
[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                                    conditions = {})
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, conditions):
59         self.parent = parent
60         self.name = str(name)
61         self.suffixes = set(suffixes)
62         self.test_format = test_format
63         self.environment = dict(environment)
64         self.substitutions = list(substitutions)
65         self.unsupported = unsupported
66         self.on_clone = on_clone
67         self.test_exec_root = test_exec_root
68         self.test_source_root = test_source_root
69         self.excludes = set(excludes)
70         self.conditions = dict(conditions)
71
72     def clone(self, path):
73         # FIXME: Chain implementations?
74         #
75         # FIXME: Allow extra parameters?
76         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
77                             self.environment, self.substitutions,
78                             self.unsupported, self.on_clone,
79                             self.test_exec_root, self.test_source_root,
80                             self.excludes, self.conditions)
81         if cfg.on_clone:
82             cfg.on_clone(self, cfg, path)
83         return cfg
84
85     def finish(self, litConfig):
86         """finish() - Finish this config object, after loading is complete."""
87
88         self.name = str(self.name)
89         self.suffixes = set(self.suffixes)
90         self.environment = dict(self.environment)
91         self.substitutions = list(self.substitutions)
92         if self.test_exec_root is not None:
93             # FIXME: This should really only be suite in test suite config
94             # files. Should we distinguish them?
95             self.test_exec_root = str(self.test_exec_root)
96         if self.test_source_root is not None:
97             # FIXME: This should really only be suite in test suite config
98             # files. Should we distinguish them?
99             self.test_source_root = str(self.test_source_root)
100         self.excludes = set(self.excludes)