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