from pathlib import Path


def name2ncc_path(name: str, src_dir: Path, extension: str):
    """Resolve a NCC data archive path from a kernel name."""
    path = src_dir / f"{name}{extension}"
    if path.is_file():
        return path

    # Some of the benchmark sources are dataset dependent. This is reflected by
    # the dataset name being concatenated to the path.
    name_components = name.split("-")

    new_name = "-".join(name_components[:-1])
    path = src_dir / f"{new_name}{extension}"
    if path.is_file():
        return path

    new_name = "-".join(name_components[:-1]) + "_" + name_components[-1]
    path = src_dir / f"{new_name}{extension}"
    if path.is_file():
        return path

    raise FileNotFoundError(f"No OpenCL source found for {name}")