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