import os
import platform
import re
import subprocess
import tempfile
import lit.formats
import lit.util
from lit.llvm import llvm_config
from lit.llvm.subst import ToolSubst
from lit.llvm.subst import FindTool
config.name = "TORCH_MLIR"
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
config.suffixes = [".mlir", ".py", ".runlit"]
config.test_source_root = os.path.dirname(__file__)
config.test_exec_root = os.path.join(config.torch_mlir_obj_root, "test")
config.substitutions.append(("%PATH%", config.environment["PATH"]))
config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
config.excludes = [
"Inputs",
"Examples",
"CMakeLists.txt",
"README.txt",
"LICENSE.txt",
"lit.cfg.py",
"lit.site.cfg.py",
]
config.test_source_root = os.path.dirname(__file__)
config.test_exec_root = os.path.join(config.torch_mlir_obj_root, "test")
config.standalone_tools_dir = os.path.join(config.torch_mlir_obj_root, "bin")
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
llvm_config.with_environment(
"PATH", os.path.join(config.llvm_build_dir, "bin"), append_path=True
)
if "asan" in config.available_features and "Linux" in config.host_os:
_asan_rt = (
subprocess.check_output(
[
config.host_cxx.strip(),
f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
]
)
.decode("utf-8")
.strip()
)
config.python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
config.environment["ASAN_OPTIONS"] = "detect_leaks=0"
elif "Windows" in config.host_os:
config.python_executable = '"%s"' % (config.python_executable)
tool_dirs = [
config.standalone_tools_dir,
config.llvm_tools_dir,
config.torch_mlir_obj_root,
]
tools = [
"torch-mlir-opt",
ToolSubst("%PYTHON", config.python_executable, unresolved="ignore"),
]
llvm_config.add_tool_substitutions(tools, tool_dirs)
if config.enable_bindings_python:
llvm_config.with_environment(
"PYTHONPATH",
[
os.path.join(config.torch_mlir_python_packages_dir, "torch_mlir"),
],
append_path=True,
)