From 038271ce61ad31d812b7f5365aa06c2d548f3368 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 9 Aug 2013 00:36:58 +0000 Subject: [PATCH] [lit] Split TestingConfig.frompath() into separate ctor and load methods. llvm-svn: 188038 --- utils/lit/lit/LitConfig.py | 3 +- utils/lit/lit/TestingConfig.py | 98 ++++++++++++++++++---------------- utils/lit/lit/discovery.py | 8 +-- 3 files changed, 58 insertions(+), 51 deletions(-) diff --git a/utils/lit/lit/LitConfig.py b/utils/lit/lit/LitConfig.py index 6e669d58b51..bcaea13042a 100644 --- a/utils/lit/lit/LitConfig.py +++ b/utils/lit/lit/LitConfig.py @@ -72,7 +72,8 @@ class LitConfig: path.""" if self.debug: self.note('load_config from %r' % path) - return lit.TestingConfig.TestingConfig.frompath(path, config, self) + config.load_from_path(path, self) + return config def getBashPath(self): """getBashPath - Get the path to 'bash'""" diff --git a/utils/lit/lit/TestingConfig.py b/utils/lit/lit/TestingConfig.py index 8c619e15fc0..a122b78e2ee 100644 --- a/utils/lit/lit/TestingConfig.py +++ b/utils/lit/lit/TestingConfig.py @@ -9,55 +9,60 @@ class TestingConfig: """ @staticmethod - def frompath(path, config, litConfig): + def fromdefaults(litConfig): """ - frompath(path, config, litConfig, mustExist) -> TestingConfig + fromdefaults(litConfig -> TestingConfig + + Create a TestingConfig object with default values. + """ + # Set the environment based on the command line arguments. + environment = { + 'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''), + 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''), + 'PATH' : os.pathsep.join(litConfig.path + + [os.environ.get('PATH','')]), + 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''), + 'TERM' : os.environ.get('TERM',''), + 'LLVM_DISABLE_CRASH_REPORT' : '1', + } + + if sys.platform == 'win32': + environment.update({ + 'INCLUDE' : os.environ.get('INCLUDE',''), + 'PATHEXT' : os.environ.get('PATHEXT',''), + 'PYTHONUNBUFFERED' : '1', + 'TEMP' : os.environ.get('TEMP',''), + 'TMP' : os.environ.get('TMP',''), + }) + + # Set the default available features based on the LitConfig. + available_features = [] + if litConfig.useValgrind: + available_features.append('valgrind') + if litConfig.valgrindLeakCheck: + available_features.append('vg_leak') + + return TestingConfig(None, + name = '', + suffixes = set(), + test_format = None, + environment = environment, + substitutions = [], + unsupported = False, + test_exec_root = None, + test_source_root = None, + excludes = [], + available_features = available_features, + pipefail = True) + + def load_from_path(self, path, litConfig): + """ + load_from_path(path, litConfig) Load the configuration module at the provided path into the given config - object (or create a new one if None is provided) and return the config. + object. """ - if config is None: - # Set the environment based on the command line arguments. - environment = { - 'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''), - 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''), - 'PATH' : os.pathsep.join(litConfig.path + - [os.environ.get('PATH','')]), - 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''), - 'TERM' : os.environ.get('TERM',''), - 'LLVM_DISABLE_CRASH_REPORT' : '1', - } - - if sys.platform == 'win32': - environment.update({ - 'INCLUDE' : os.environ.get('INCLUDE',''), - 'PATHEXT' : os.environ.get('PATHEXT',''), - 'PYTHONUNBUFFERED' : '1', - 'TEMP' : os.environ.get('TEMP',''), - 'TMP' : os.environ.get('TMP',''), - }) - - # Set the default available features based on the LitConfig. - available_features = [] - if litConfig.useValgrind: - available_features.append('valgrind') - if litConfig.valgrindLeakCheck: - available_features.append('vg_leak') - - config = TestingConfig(None, - name = '', - suffixes = set(), - test_format = None, - environment = environment, - substitutions = [], - unsupported = False, - test_exec_root = None, - test_source_root = None, - excludes = [], - available_features = available_features, - pipefail = True) - # Load the config script data. f = open(path) try: @@ -68,7 +73,7 @@ class TestingConfig: # Execute the config script to initialize the object. cfg_globals = dict(globals()) - cfg_globals['config'] = config + cfg_globals['config'] = self cfg_globals['lit'] = litConfig cfg_globals['__file__'] = path try: @@ -90,8 +95,7 @@ class TestingConfig: 'unable to parse config file %r, traceback: %s' % ( path, traceback.format_exc())) - config.finish(litConfig) - return config + self.finish(litConfig) def __init__(self, parent, name, suffixes, test_format, environment, substitutions, unsupported, diff --git a/utils/lit/lit/discovery.py b/utils/lit/lit/discovery.py index c5f48a69c91..26882fe8ce5 100644 --- a/utils/lit/lit/discovery.py +++ b/utils/lit/lit/discovery.py @@ -38,11 +38,12 @@ def getTestSuite(item, litConfig, cache): ts, relative = search(parent) return (ts, relative + (base,)) - # We found a config file, load it. + # We found a test suite, create a new config for it and load it. if litConfig.debug: litConfig.note('loading suite config %r' % cfgpath) - cfg = TestingConfig.frompath(cfgpath, None, litConfig) + cfg = TestingConfig.fromdefaults(litConfig) + cfg.load_from_path(cfgpath, litConfig) source_root = os.path.realpath(cfg.test_source_root or path) exec_root = os.path.realpath(cfg.test_exec_root or path) return Test.TestSuite(cfg.name, source_root, exec_root, cfg), () @@ -91,7 +92,8 @@ def getLocalConfig(ts, path_in_suite, litConfig, cache): config = parent.clone() if litConfig.debug: litConfig.note('loading local config %r' % cfgpath) - return TestingConfig.frompath(cfgpath, config, litConfig) + config.load_from_path(cfgpath, litConfig) + return config def search(path_in_suite): key = (ts, path_in_suite)