Merge r182726:

Improve support for compiler-rt tests in CMake build.

Now compiler-rt tests run correctly if compiler-rt is checked out into
arbitrary directory (not necessarily projects/compiler-rt).
Patch by Greg Fitzgerald!



git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_33@183180 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/lit_tests/Unit/lit.cfg b/lib/asan/lit_tests/Unit/lit.cfg
index 243eb7f..e24361b 100644
--- a/lib/asan/lit_tests/Unit/lit.cfg
+++ b/lib/asan/lit_tests/Unit/lit.cfg
@@ -11,9 +11,8 @@
   return attr_value
 
 # Setup attributes common for all compiler-rt projects.
-llvm_src_root = get_required_attr(config, 'llvm_src_root')
-compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
-                                        "compiler-rt", "lib",
+compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root')
+compiler_rt_lit_unit_cfg = os.path.join(compiler_rt_src_root, "lib",
                                         "lit.common.unit.cfg")
 lit.load_config(config, compiler_rt_lit_unit_cfg)
 
diff --git a/lib/asan/lit_tests/Unit/lit.site.cfg.in b/lib/asan/lit_tests/Unit/lit.site.cfg.in
index 07584a6..315d24d 100644
--- a/lib/asan/lit_tests/Unit/lit.site.cfg.in
+++ b/lib/asan/lit_tests/Unit/lit.site.cfg.in
@@ -3,6 +3,7 @@
 
 config.target_triple = "@TARGET_TRIPLE@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
 config.asan_binary_dir = "@ASAN_BINARY_DIR@"
 
diff --git a/lib/asan/lit_tests/lit.cfg b/lib/asan/lit_tests/lit.cfg
index 7875281..5daecd9 100644
--- a/lib/asan/lit_tests/lit.cfg
+++ b/lib/asan/lit_tests/lit.cfg
@@ -2,6 +2,14 @@
 
 import os
 
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if not attr_value:
+    lit.fatal("No attribute %r in test configuration! You may need to run "
+              "tests from your build directory or add this attribute "
+              "to lit.site.cfg " % attr_name)
+  return attr_value
+
 # Setup config name.
 config.name = 'AddressSanitizer'
 
@@ -30,14 +38,6 @@
   if not llvm_config:
     DisplayNoConfigMessage()
 
-  # Validate that llvm-config points to the same source tree.
-  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
-  asan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                    "lib", "asan", "lit_tests")
-  if (os.path.realpath(asan_test_src_root) !=
-      os.path.realpath(config.test_source_root)):
-    DisplayNoConfigMessage()
-
   # Find out the presumed location of generated site config.
   llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
   asan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
@@ -49,8 +49,9 @@
   raise SystemExit
 
 # Setup attributes common for all compiler-rt projects.
-compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                   "lib", "lit.common.cfg")
+compiler_rt_src_root = get_required_attr(config, "compiler_rt_src_root")
+compiler_rt_lit_cfg = os.path.join(compiler_rt_src_root, "lib",
+                                   "lit.common.cfg")
 if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):
   lit.fatal("Can't find common compiler-rt lit config at: %r"
             % compiler_rt_lit_cfg)
diff --git a/lib/asan/lit_tests/lit.site.cfg.in b/lib/asan/lit_tests/lit.site.cfg.in
index cf43930..a57a8fb 100644
--- a/lib/asan/lit_tests/lit.site.cfg.in
+++ b/lib/asan/lit_tests/lit.site.cfg.in
@@ -5,6 +5,7 @@
 config.host_os = "@HOST_OS@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.clang = "@LLVM_BINARY_DIR@/bin/clang"
 
diff --git a/lib/msan/lit_tests/Unit/lit.cfg b/lib/msan/lit_tests/Unit/lit.cfg
index afb30e0..ee379d0 100644
--- a/lib/msan/lit_tests/Unit/lit.cfg
+++ b/lib/msan/lit_tests/Unit/lit.cfg
@@ -11,9 +11,8 @@
   return attr_value
 
 # Setup attributes common for all compiler-rt projects.
-llvm_src_root = get_required_attr(config, 'llvm_src_root')
-compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
-                                        "compiler-rt", "lib",
+compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root')
+compiler_rt_lit_unit_cfg = os.path.join(compiler_rt_src_root, "lib",
                                         "lit.common.unit.cfg")
 lit.load_config(config, compiler_rt_lit_unit_cfg)
 
diff --git a/lib/msan/lit_tests/Unit/lit.site.cfg.in b/lib/msan/lit_tests/Unit/lit.site.cfg.in
index 4ae84c4..a91f671 100644
--- a/lib/msan/lit_tests/Unit/lit.site.cfg.in
+++ b/lib/msan/lit_tests/Unit/lit.site.cfg.in
@@ -3,6 +3,7 @@
 
 config.target_triple = "@TARGET_TRIPLE@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
 config.msan_binary_dir = "@MSAN_BINARY_DIR@"
 
diff --git a/lib/msan/lit_tests/lit.cfg b/lib/msan/lit_tests/lit.cfg
index e220c38..4238188 100644
--- a/lib/msan/lit_tests/lit.cfg
+++ b/lib/msan/lit_tests/lit.cfg
@@ -2,6 +2,14 @@
 
 import os
 
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if not attr_value:
+    lit.fatal("No attribute %r in test configuration! You may need to run "
+              "tests from your build directory or add this attribute "
+              "to lit.site.cfg " % attr_name)
+  return attr_value
+
 # Setup config name.
 config.name = 'MemorySanitizer'
 
@@ -30,14 +38,6 @@
   if not llvm_config:
     DisplayNoConfigMessage()
 
-  # Validate that llvm-config points to the same source tree.
-  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
-  msan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                    "lib", "msan", "lit_tests")
-  if (os.path.realpath(msan_test_src_root) !=
-      os.path.realpath(config.test_source_root)):
-    DisplayNoConfigMessage()
-
   # Find out the presumed location of generated site config.
   llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
   msan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
@@ -49,8 +49,9 @@
   raise SystemExit
 
 # Setup attributes common for all compiler-rt projects.
-compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                   "lib", "lit.common.cfg")
+compiler_rt_src_root = get_required_attr(config, "compiler_rt_src_root")
+compiler_rt_lit_cfg = os.path.join(compiler_rt_src_root, "lib",
+                                   "lit.common.cfg")
 if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):
   lit.fatal("Can't find common compiler-rt lit config at: %r"
             % compiler_rt_lit_cfg)
diff --git a/lib/msan/lit_tests/lit.site.cfg.in b/lib/msan/lit_tests/lit.site.cfg.in
index cc7c7a0..3b969e0 100644
--- a/lib/msan/lit_tests/lit.site.cfg.in
+++ b/lib/msan/lit_tests/lit.site.cfg.in
@@ -1,6 +1,7 @@
 config.target_triple = "@TARGET_TRIPLE@"
 config.host_os = "@HOST_OS@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.clang = "@LLVM_BINARY_DIR@/bin/clang"
diff --git a/lib/sanitizer_common/tests/lit.cfg b/lib/sanitizer_common/tests/lit.cfg
index d774753..303d56c 100644
--- a/lib/sanitizer_common/tests/lit.cfg
+++ b/lib/sanitizer_common/tests/lit.cfg
@@ -11,9 +11,8 @@
   return attr_value
 
 # Setup attributes common for all compiler-rt projects.
-llvm_src_root = get_required_attr(config, 'llvm_src_root')
-compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
-                                        "compiler-rt", "lib",
+compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root')
+compiler_rt_lit_unit_cfg = os.path.join(compiler_rt_src_root, "lib",
                                         "lit.common.unit.cfg")
 lit.load_config(config, compiler_rt_lit_unit_cfg)
 
diff --git a/lib/sanitizer_common/tests/lit.site.cfg.in b/lib/sanitizer_common/tests/lit.site.cfg.in
index ad0ff3c..50485aa 100644
--- a/lib/sanitizer_common/tests/lit.site.cfg.in
+++ b/lib/sanitizer_common/tests/lit.site.cfg.in
@@ -3,6 +3,7 @@
 
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
 
 try:
diff --git a/lib/tsan/lit_tests/Unit/lit.cfg b/lib/tsan/lit_tests/Unit/lit.cfg
index 6688697..0a0dbbf 100644
--- a/lib/tsan/lit_tests/Unit/lit.cfg
+++ b/lib/tsan/lit_tests/Unit/lit.cfg
@@ -11,9 +11,8 @@
   return attr_value
 
 # Setup attributes common for all compiler-rt projects.
-llvm_src_root = get_required_attr(config, 'llvm_src_root')
-compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
-                                        "compiler-rt", "lib",
+compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root')
+compiler_rt_lit_unit_cfg = os.path.join(compiler_rt_src_root, "lib",
                                         "lit.common.unit.cfg")
 lit.load_config(config, compiler_rt_lit_unit_cfg)
 
diff --git a/lib/tsan/lit_tests/Unit/lit.site.cfg.in b/lib/tsan/lit_tests/Unit/lit.site.cfg.in
index 420cdca..6eedc21 100644
--- a/lib/tsan/lit_tests/Unit/lit.site.cfg.in
+++ b/lib/tsan/lit_tests/Unit/lit.site.cfg.in
@@ -3,6 +3,7 @@
 
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
 
diff --git a/lib/tsan/lit_tests/lit.cfg b/lib/tsan/lit_tests/lit.cfg
index a2206cc..d483d2f 100644
--- a/lib/tsan/lit_tests/lit.cfg
+++ b/lib/tsan/lit_tests/lit.cfg
@@ -2,6 +2,14 @@
 
 import os
 
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if not attr_value:
+    lit.fatal("No attribute %r in test configuration! You may need to run "
+              "tests from your build directory or add this attribute "
+              "to lit.site.cfg " % attr_name)
+  return attr_value
+
 # Setup config name.
 config.name = 'ThreadSanitizer'
 
@@ -30,14 +38,6 @@
   if not llvm_config:
     DisplayNoConfigMessage()
 
-  # Validate that llvm-config points to the same source tree.
-  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
-  tsan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                    "lib", "tsan", "lit_tests")
-  if (os.path.realpath(tsan_test_src_root) !=
-      os.path.realpath(config.test_source_root)):
-    DisplayNoConfigMessage()
-
   # Find out the presumed location of generated site config.
   llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
   tsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
@@ -49,8 +49,9 @@
   raise SystemExit
 
 # Setup attributes common for all compiler-rt projects.
-compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                   "lib", "lit.common.cfg")
+compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root')
+compiler_rt_lit_cfg = os.path.join(compiler_rt_src_root, "lib",
+                                   "lit.common.cfg")
 if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)):
   lit.fatal("Can't find common compiler-rt lit config at: %r"
             % compiler_rt_lit_cfg)
diff --git a/lib/tsan/lit_tests/lit.site.cfg.in b/lib/tsan/lit_tests/lit.site.cfg.in
index b1c6ccf..07b521a 100644
--- a/lib/tsan/lit_tests/lit.site.cfg.in
+++ b/lib/tsan/lit_tests/lit.site.cfg.in
@@ -4,6 +4,7 @@
 config.clang = "@LLVM_BINARY_DIR@/bin/clang"
 config.host_os = "@HOST_OS@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.target_triple = "@TARGET_TRIPLE@"
 
diff --git a/lib/ubsan/lit_tests/lit.cfg b/lib/ubsan/lit_tests/lit.cfg
index 9fd3a1a..ea6ebdf 100644
--- a/lib/ubsan/lit_tests/lit.cfg
+++ b/lib/ubsan/lit_tests/lit.cfg
@@ -2,6 +2,14 @@
 
 import os
 
+def get_required_attr(config, attr_name):
+  attr_value = getattr(config, attr_name, None)
+  if not attr_value:
+    lit.fatal("No attribute %r in test configuration! You may need to run "
+              "tests from your build directory or add this attribute "
+              "to lit.site.cfg " % attr_name)
+  return attr_value
+
 # Setup config name.
 config.name = 'UndefinedBehaviorSanitizer'
 
@@ -30,14 +38,6 @@
   if not llvm_config:
     DisplayNoConfigMessage()
 
-  # Validate that llvm-config points to the same source tree.
-  llvm_src_root = lit.util.capture(["llvm-config", "--src-root"]).strip()
-  ubsan_test_src_root = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                     "lib", "ubsan", "lit_tests")
-  if (os.path.realpath(ubsan_test_src_root) !=
-      os.path.realpath(config.test_source_root)):
-    DisplayNoConfigMessage()
-
   # Find out the presumed location of generated site config.
   llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip()
   ubsan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt",
@@ -49,8 +49,9 @@
   raise SystemExit
 
 # Setup attributes common for all compiler-rt projects.
-compiler_rt_lit_cfg = os.path.join(llvm_src_root, "projects", "compiler-rt",
-                                   "lib", "lit.common.cfg")
+compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root')
+compiler_rt_lit_cfg = os.path.join(compiler_rt_src_root, "lib",
+                                   "lit.common.cfg")
 if not compiler_rt_lit_cfg or not os.path.exists(compiler_rt_lit_cfg):
   lit.fatal("Can't find common compiler-rt lit config at: %r"
             % compiler_rt_lit_cfg)
diff --git a/lib/ubsan/lit_tests/lit.site.cfg.in b/lib/ubsan/lit_tests/lit.site.cfg.in
index b1c6ccf..07b521a 100644
--- a/lib/ubsan/lit_tests/lit.site.cfg.in
+++ b/lib/ubsan/lit_tests/lit.site.cfg.in
@@ -4,6 +4,7 @@
 config.clang = "@LLVM_BINARY_DIR@/bin/clang"
 config.host_os = "@HOST_OS@"
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@"
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.target_triple = "@TARGET_TRIPLE@"