[ASan] add llvm_tools_dir to lit.site.cfg for ASan and add it to PATH

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@161411 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/lit_tests/lit.site.cfg.in b/lib/asan/lit_tests/lit.site.cfg.in
index 2eb9615..f438570 100644
--- a/lib/asan/lit_tests/lit.site.cfg.in
+++ b/lib/asan/lit_tests/lit.site.cfg.in
@@ -3,7 +3,16 @@
 
 config.target_triple = "@TARGET_TRIPLE@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.clang = "@LLVM_BINARY_DIR@/bin/clang"
 
+# LLVM tools dir can be passed in lit parameters, so try to
+# apply substitution.
+try:
+  config.llvm_tools_dir = config.llvm_tools_dir % lit.params
+except KeyError,e:
+  key, = e.args
+  lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key))
+
 # Let the main config do the real work.
 lit.load_config(config, "@ASAN_SOURCE_DIR@/lit_tests/lit.cfg")
diff --git a/lib/lit.common.cfg b/lib/lit.common.cfg
index 725156b..16ba076 100644
--- a/lib/lit.common.cfg
+++ b/lib/lit.common.cfg
@@ -35,6 +35,13 @@
   if name in config.environment:
     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.fatal("Invalid llvm_tools_dir config attribute: %r" % llvm_tools_dir)
+path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
+config.environment['PATH'] = path
+
 # Define %clang substitution to use in test RUN lines.
 config.substitutions.append( ("%clang ", (" " + config.clang + " ")) )