llvm.org GIT mirror llvm / 49e5142
[lit] Eliminate mustExist parameter from TestingConfig.frompath(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188034 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 6 years ago
3 changed file(s) with 34 addition(s) and 37 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(
75 path, config, self, mustExist = True)
74 return lit.TestingConfig.TestingConfig.frompath(path, config, self)
7675
7776 def getBashPath(self):
7877 """getBashPath - Get the path to 'bash'"""
88 """
99
1010 @staticmethod
11 def frompath(path, config, litConfig, mustExist=True):
11 def frompath(path, config, litConfig):
1212 """
1313 frompath(path, config, litConfig, mustExist) -> TestingConfig
1414
5757 available_features = available_features,
5858 pipefail = True)
5959
60 if os.path.exists(path):
61 # FIXME: Improve detection and error reporting of errors in the
62 # config file.
63 f = open(path)
64 cfg_globals = dict(globals())
65 cfg_globals['config'] = config
66 cfg_globals['lit'] = litConfig
67 cfg_globals['__file__'] = path
68 try:
69 data = f.read()
70 if PY2:
71 exec("exec data in cfg_globals")
72 else:
73 exec(data, cfg_globals)
74 if litConfig.debug:
75 litConfig.note('... loaded config %r' % path)
76 except SystemExit:
77 e = sys.exc_info()[1]
78 # We allow normal system exit inside a config file to just
79 # return control without error.
80 if e.args:
81 raise
82 except:
83 import traceback
84 litConfig.fatal(
85 'unable to parse config file %r, traceback: %s' % (
86 path, traceback.format_exc()))
87 f.close()
88 else:
89 if mustExist:
90 litConfig.fatal('unable to load config from %r ' % path)
91 elif litConfig.debug:
92 litConfig.note('... config not found - %r' %path)
60 # Load the config script data.
61 f = open(path)
62 try:
63 data = f.read()
64 except:
65 litConfig.fatal('unable to load config file: %r' % (path,))
66 f.close()
67
68 # Execute the config script to initialize the object.
69 cfg_globals = dict(globals())
70 cfg_globals['config'] = config
71 cfg_globals['lit'] = litConfig
72 cfg_globals['__file__'] = path
73 try:
74 if PY2:
75 exec("exec data in cfg_globals")
76 else:
77 exec(data, cfg_globals)
78 if litConfig.debug:
79 litConfig.note('... loaded config %r' % path)
80 except SystemExit:
81 e = sys.exc_info()[1]
82 # We allow normal system exit inside a config file to just
83 # return control without error.
84 if e.args:
85 raise
86 except:
87 import traceback
88 litConfig.fatal(
89 'unable to parse config file %r, traceback: %s' % (
90 path, traceback.format_exc()))
9391
9492 config.finish(litConfig)
9593 return config
4141 if litConfig.debug:
4242 litConfig.note('loading suite config %r' % cfgpath)
4343
44 cfg = TestingConfig.frompath(cfgpath, None, litConfig, mustExist = True)
44 cfg = TestingConfig.frompath(cfgpath, None, litConfig)
4545 source_root = os.path.realpath(cfg.test_source_root or path)
4646 exec_root = os.path.realpath(cfg.test_exec_root or path)
4747 return Test.TestSuite(cfg.name, source_root, exec_root, cfg), ()