[lit] Split TestingConfig.frompath() into separate ctor and load methods.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 9 Aug 2013 00:36:58 +0000 (00:36 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 9 Aug 2013 00:36:58 +0000 (00:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188038 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/LitConfig.py
utils/lit/lit/TestingConfig.py
utils/lit/lit/discovery.py

index 6e669d58b51cc1a89dac2b3d6d87775f05004bea..bcaea13042a101ebe6214c5786cdc4e0407244de 100644 (file)
@@ -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'"""
index 8c619e15fc0b5f8d48fa65e1ad990d615670ae17..a122b78e2eec07e3daf3e74b573e5f3295af218e 100644 (file)
@@ -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 = '<unnamed>',
+                             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 = '<unnamed>',
-                                   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,
index c5f48a69c91d1f0a48cfc3c413b55b1fe4dde775..26882fe8ce54e23c2b24583af8200f6b1627fa85 100644 (file)
@@ -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)