# (C) Copyright IBM 2023.
#
# This code is part of Qiskit.
#
# This code is licensed under the Apache License, Version 2.0 with LLVM
# Exceptions. You may obtain a copy of this license in the LICENSE.txt
# file in the root directory of this source tree.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

#
# QSS Compiler
# ============
# This file is used to configure both the QSS compiler core test suite
# as well test suites for specific targets.

# flake8: noqa

import os

import lit.formats
import lit.util

from lit.llvm import llvm_config

# Configuration file for the 'lit' test runner.

config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)

# suffixes: A list of file extensions to treat as test files.
config.suffixes = [".mlir", ".qasm", ".tst"]

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"])

llvm_config.use_default_substitutions()

# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
# subdirectories contain auxiliary inputs for various tests in their parent
# directories.
config.excludes = ["Inputs", "Examples", "CMakeLists.txt", "README.txt", "LICENSE.txt"]

# TODO pull from "virtual env" *activate.py?" "buildenv.py?"
config.environment["QSSC_RESOURCES"] = os.path.join(config.qss_compiler_obj_root, "resources")

config.qss_compiler_tools_dir = os.path.join(config.qss_compiler_obj_root, "bin")

# Tweak the PATH to include the tools dir.
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)

# Add substitutions for all files in QSS compiler tools directory.
tools = os.listdir(config.qss_compiler_tools_dir)
llvm_config.add_tool_substitutions(tools, [config.qss_compiler_tools_dir])

llvm_config.feature_config(
    [("--assertion-mode", {"ON": "asserts"}), ("--build-mode", {"[Dd][Ee][Bb][Uu][Gg]": "debug"})]
)
