From: Daniel Dunbar Date: Fri, 9 Aug 2013 00:36:58 +0000 (+0000) Subject: [lit] Split TestingConfig.frompath() into separate ctor and load methods. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6c749c5fbc94a9f133ed05e389aab4309f187684;p=oota-llvm.git [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 --- 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,54 +9,59 @@ class TestingConfig: """ @staticmethod - def frompath(path, config, litConfig): + def fromdefaults(litConfig): """ - frompath(path, config, litConfig, mustExist) -> TestingConfig + fromdefaults(litConfig -> TestingConfig - 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. + 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) - 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 configuration module at the provided path into the given config + object. + """ # Load the config script data. f = open(path) @@ -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)