# -*- Python -*-

import os

# Setup config name.
config.name = 'UndefinedBehaviorSanitizer'

# Setup source root.
config.test_source_root = os.path.dirname(__file__)

def DisplayNoConfigMessage():
  lit.fatal("No site specific configuration available! " +
            "Try running your test from the build tree or running " +
            "make check-ubsan")

# Figure out LLVM source root.
llvm_src_root = getattr(config, 'llvm_src_root', None)
if llvm_src_root is None:
  # We probably haven't loaded the site-specific configuration: the user
  # is likely trying to run a test file directly, and the site configuration
  # wasn't created by the build system or we're performing an out-of-tree build.
  ubsan_site_cfg = lit.params.get('ubsan_site_config', None)
  if ubsan_site_cfg and os.path.exists(ubsan_site_cfg):
    lit.load_config(config, ubsan_site_cfg)
    raise SystemExit

  # Try to guess the location of site-specific configuration using llvm-config
  # util that can point where the build tree is.
  llvm_config = lit.util.which("llvm-config", config.environment["PATH"])
  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",
                                "lib", "ubsan", "lit_tests", "lit.site.cfg")
  if not ubsan_site_cfg or not os.path.exists(ubsan_site_cfg):
    DisplayNoConfigMessage()

  lit.load_config(config, ubsan_site_cfg)
  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")
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)
lit.load_config(config, compiler_rt_lit_cfg)

# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']

# UndefinedBehaviorSanitizer tests are currently supported on
# Linux and Darwin only.
if config.host_os not in ['Linux', 'Darwin']:
  config.unsupported = True
