llvm.org GIT mirror llvm / 6c749c5
[lit] Split TestingConfig.frompath() into separate ctor and load methods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188038 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 6 years ago
3 changed file(s) with 58 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
7171 path."""
7272 if self.debug:
7373 self.note('load_config from %r' % path)
74 return lit.TestingConfig.TestingConfig.frompath(path, config, self)
74 config.load_from_path(path, self)
75 return config
7576
7677 def getBashPath(self):
7778 """getBashPath - Get the path to 'bash'"""
88 """
99
1010 @staticmethod
11 def frompath(path, config, litConfig):
11 def fromdefaults(litConfig):
1212 """
13 frompath(path, config, litConfig, mustExist) -> TestingConfig
13 fromdefaults(litConfig -> TestingConfig
14
15 Create a TestingConfig object with default values.
16 """
17 # Set the environment based on the command line arguments.
18 environment = {
19 'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''),
20 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''),
21 'PATH' : os.pathsep.join(litConfig.path +
22 [os.environ.get('PATH','')]),
23 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
24 'TERM' : os.environ.get('TERM',''),
25 'LLVM_DISABLE_CRASH_REPORT' : '1',
26 }
27
28 if sys.platform == 'win32':
29 environment.update({
30 'INCLUDE' : os.environ.get('INCLUDE',''),
31 'PATHEXT' : os.environ.get('PATHEXT',''),
32 'PYTHONUNBUFFERED' : '1',
33 'TEMP' : os.environ.get('TEMP',''),
34 'TMP' : os.environ.get('TMP',''),
35 })
36
37 # Set the default available features based on the LitConfig.
38 available_features = []
39 if litConfig.useValgrind:
40 available_features.append('valgrind')
41 if litConfig.valgrindLeakCheck:
42 available_features.append('vg_leak')
43
44 return TestingConfig(None,
45 name = '',
46 suffixes = set(),
47 test_format = None,
48 environment = environment,
49 substitutions = [],
50 unsupported = False,
51 test_exec_root = None,
52 test_source_root = None,
53 excludes = [],
54 available_features = available_features,
55 pipefail = True)
56
57 def load_from_path(self, path, litConfig):
58 """
59 load_from_path(path, litConfig)
1460
1561 Load the configuration module at the provided path into the given config
16 object (or create a new one if None is provided) and return the config.
62 object.
1763 """
18
19 if config is None:
20 # Set the environment based on the command line arguments.
21 environment = {
22 'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''),
23 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''),
24 'PATH' : os.pathsep.join(litConfig.path +
25 [os.environ.get('PATH','')]),
26 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
27 'TERM' : os.environ.get('TERM',''),
28 'LLVM_DISABLE_CRASH_REPORT' : '1',
29 }
30
31 if sys.platform == 'win32':
32 environment.update({
33 'INCLUDE' : os.environ.get('INCLUDE',''),
34 'PATHEXT' : os.environ.get('PATHEXT',''),
35 'PYTHONUNBUFFERED' : '1',
36 'TEMP' : os.environ.get('TEMP',''),
37 'TMP' : os.environ.get('TMP',''),
38 })
39
40 # Set the default available features based on the LitConfig.
41 available_features = []
42 if litConfig.useValgrind:
43 available_features.append('valgrind')
44 if litConfig.valgrindLeakCheck:
45 available_features.append('vg_leak')
46
47 config = TestingConfig(None,
48 name = '',
49 suffixes = set(),
50 test_format = None,
51 environment = environment,
52 substitutions = [],
53 unsupported = False,
54 test_exec_root = None,
55 test_source_root = None,
56 excludes = [],
57 available_features = available_features,
58 pipefail = True)
5964
6065 # Load the config script data.
6166 f = open(path)
6772
6873 # Execute the config script to initialize the object.
6974 cfg_globals = dict(globals())
70 cfg_globals['config'] = config
75 cfg_globals['config'] = self
7176 cfg_globals['lit'] = litConfig
7277 cfg_globals['__file__'] = path
7378 try:
8994 'unable to parse config file %r, traceback: %s' % (
9095 path, traceback.format_exc()))
9196
92 config.finish(litConfig)
93 return config
97 self.finish(litConfig)
9498
9599 def __init__(self, parent, name, suffixes, test_format,
96100 environment, substitutions, unsupported,
3737 ts, relative = search(parent)
3838 return (ts, relative + (base,))
3939
40 # We found a config file, load it.
40 # We found a test suite, create a new config for it and load it.
4141 if litConfig.debug:
4242 litConfig.note('loading suite config %r' % cfgpath)
4343
44 cfg = TestingConfig.frompath(cfgpath, None, litConfig)
44 cfg = TestingConfig.fromdefaults(litConfig)
45 cfg.load_from_path(cfgpath, litConfig)
4546 source_root = os.path.realpath(cfg.test_source_root or path)
4647 exec_root = os.path.realpath(cfg.test_exec_root or path)
4748 return Test.TestSuite(cfg.name, source_root, exec_root, cfg), ()
9091 config = parent.clone()
9192 if litConfig.debug:
9293 litConfig.note('loading local config %r' % cfgpath)
93 return TestingConfig.frompath(cfgpath, config, litConfig)
94 config.load_from_path(cfgpath, litConfig)
95 return config
9496
9597 def search(path_in_suite):
9698 key = (ts, path_in_suite)