[llvm] r188038 - [lit] Split TestingConfig.frompath() into separate ctor and load methods.

Daniel Dunbar daniel at zuster.org
Thu Aug 8 17:36:58 PDT 2013


Author: ddunbar
Date: Thu Aug  8 19:36:58 2013
New Revision: 188038

URL: http://llvm.org/viewvc/llvm-project?rev=188038&view=rev
Log:
[lit] Split TestingConfig.frompath() into separate ctor and load methods.

Modified:
    llvm/trunk/utils/lit/lit/LitConfig.py
    llvm/trunk/utils/lit/lit/TestingConfig.py
    llvm/trunk/utils/lit/lit/discovery.py

Modified: llvm/trunk/utils/lit/lit/LitConfig.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/LitConfig.py?rev=188038&r1=188037&r2=188038&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/LitConfig.py (original)
+++ llvm/trunk/utils/lit/lit/LitConfig.py Thu Aug  8 19:36:58 2013
@@ -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'"""

Modified: llvm/trunk/utils/lit/lit/TestingConfig.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/TestingConfig.py?rev=188038&r1=188037&r2=188038&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/TestingConfig.py (original)
+++ llvm/trunk/utils/lit/lit/TestingConfig.py Thu Aug  8 19:36:58 2013
@@ -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,

Modified: llvm/trunk/utils/lit/lit/discovery.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/discovery.py?rev=188038&r1=188037&r2=188038&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/discovery.py (original)
+++ llvm/trunk/utils/lit/lit/discovery.py Thu Aug  8 19:36:58 2013
@@ -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, li
         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)





More information about the llvm-commits mailing list