[compiler-rt] r313270 - [lit] Force site configs to be run before source-tree configs

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 09:47:59 PDT 2017


Author: zturner
Date: Thu Sep 14 09:47:58 2017
New Revision: 313270

URL: http://llvm.org/viewvc/llvm-project?rev=313270&view=rev
Log:
[lit] Force site configs to be run before source-tree configs

This patch simplifies LLVM's lit infrastructure by enforcing an ordering
that a site config is always run before a source-tree config.

A significant amount of the complexity from lit config files arises from
the fact that inside of a source-tree config file, we don't yet know if
the site config has been run.  However it is *always* required to run
a site config first, because it passes various variables down through
CMake that the main config depends on.  As a result, every config
file has to do a bunch of magic to try to reverse-engineer the location
of the site config file if they detect (heuristically) that the site
config file has not yet been run.

This patch solves the problem by emitting a mapping from source tree
config file to binary tree site config file in llvm-lit.py. Then, during
discovery when we find a config file, we check to see if we have a
target mapping for it, and if so we use that instead.

This mechanism is generic enough that it does not affect external users
of lit. They will just not have a config mapping defined, and everything
will work as normal.

On the other hand, for us it allows us to make many simplifications:

* We are guaranteed that a site config will be executed first
* Inside of a main config, we no longer have to assume that attributes
  might not be present and use getattr everywhere.
* We no longer have to pass parameters such as --param llvm_site_config=<path>
  on the command line.
* It is future-proof, meaning you don't have to edit llvm-lit.in to add
  support for new projects.
* All of the duplicated logic of trying various fallback mechanisms of
  finding a site config from the main config are now gone.

One potentially noteworthy thing that was required to implement this
change is that whereas the ninja check targets previously used the first
method to spawn lit, they now use the second. In particular, you can no
longer run lit.py against the source tree while specifying the various
`foo_site_config=<path>` parameters.  Instead, you need to run
llvm-lit.py.

Differential Revision: https://reviews.llvm.org/D37756

Modified:
    compiler-rt/trunk/test/lit.common.cfg
    compiler-rt/trunk/test/profile/lit.cfg
    compiler-rt/trunk/unittests/lit.common.unit.cfg

Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=313270&r1=313269&r2=313270&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Thu Sep 14 09:47:58 2017
@@ -73,10 +73,9 @@ for name in possibly_dangerous_env_vars:
     del config.environment[name]
 
 # Tweak PATH to include llvm tools dir.
-llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
-if (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)):
-  lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
-path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
+if (not config.llvm_tools_dir) or (not os.path.exists(config.llvm_tools_dir)):
+  lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % config.llvm_tools_dir)
+path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
 config.environment['PATH'] = path
 
 # Help MSVS link.exe find the standard libraries.
@@ -193,7 +192,7 @@ if config.host_os == 'Darwin':
 else:
   config.substitutions.append( ("%macos_min_target_10_11", "") )
 
-sancovcc_path = os.path.join(llvm_tools_dir, "sancov") 
+sancovcc_path = os.path.join(config.llvm_tools_dir, "sancov")
 if os.path.exists(sancovcc_path):
   config.available_features.add("has_sancovcc")
   config.substitutions.append( ("%sancovcc ", sancovcc_path) )
@@ -254,7 +253,7 @@ try:
       stdout = subprocess.PIPE,
       env=config.environment)
 except OSError:
-  print("Could not find llvm-config in " + llvm_tools_dir)
+  print("Could not find llvm-config in " + config.llvm_tools_dir)
   exit(42)
 
 if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):

Modified: compiler-rt/trunk/test/profile/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/lit.cfg?rev=313270&r1=313269&r2=313270&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/lit.cfg (original)
+++ compiler-rt/trunk/test/profile/lit.cfg Thu Sep 14 09:47:58 2017
@@ -22,17 +22,6 @@ if hasattr(config, 'profile_lit_binary_d
         config.profile_lit_binary_dir is not None:
     config.test_exec_root = os.path.join(config.profile_lit_binary_dir, config.name)
 
-# If the above check didn't work, we're probably in the source tree.  Use some
-# magic to re-execute from the build tree.
-if config.test_exec_root is None:
-    # The magic relies on knowing compilerrt_site_basedir.
-    compilerrt_basedir = lit_config.params.get('compilerrt_site_basedir', None)
-    if compilerrt_basedir:
-        site_cfg = os.path.join(compilerrt_basedir, 'profile', 'lit.site.cfg')
-        if os.path.exists(site_cfg):
-            lit_config.load_config(config, site_cfg)
-            raise SystemExit
-
 if config.host_os in ['Linux']:
   extra_link_flags = ["-ldl"]
 else:

Modified: compiler-rt/trunk/unittests/lit.common.unit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/unittests/lit.common.unit.cfg?rev=313270&r1=313269&r2=313270&view=diff
==============================================================================
--- compiler-rt/trunk/unittests/lit.common.unit.cfg (original)
+++ compiler-rt/trunk/unittests/lit.common.unit.cfg Thu Sep 14 09:47:58 2017
@@ -16,7 +16,7 @@ config.test_format = lit.formats.GoogleT
 config.suffixes = []
 
 # Tweak PATH to include llvm tools dir.
-llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
+llvm_tools_dir = config.llvm_tools_dir
 if (not llvm_tools_dir) or (not os.path.exists(llvm_tools_dir)):
   lit_config.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
 path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))




More information about the llvm-commits mailing list