Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/tools/test_generate_cmake_presets_validate_compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

import tools.generate_cmake_presets as presets


def test_generate_presets_rejects_missing_cuda_compiler(monkeypatch):
monkeypatch.setattr(presets, "CUDA_HOME", None)
monkeypatch.setattr(presets, "which", lambda name: None)
monkeypatch.setattr("builtins.input", lambda prompt: "/missing/nvcc")

with pytest.raises(FileNotFoundError, match="/missing/nvcc"):
presets.generate_presets(force_overwrite=True)
2 changes: 2 additions & 0 deletions tools/generate_cmake_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False)
"path to nvcc (e.g., /usr/local/cuda/bin/nvcc): "
)
nvcc_path = nvcc_path_input.strip()
if not nvcc_path or not os.path.exists(nvcc_path):
raise FileNotFoundError(f"CUDA compiler not found: {nvcc_path}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using os.path.exists only checks if the path exists, which could be True even if the user accidentally provides a directory path (e.g., /usr/local/cuda/bin/) instead of the actual compiler executable. To prevent CMake from failing later with a cryptic error, use os.path.isfile to ensure the path points to a file.

Suggested change
if not nvcc_path or not os.path.exists(nvcc_path):
raise FileNotFoundError(f"CUDA compiler not found: {nvcc_path}")
if not nvcc_path or not os.path.isfile(nvcc_path):
raise FileNotFoundError(f"CUDA compiler not found: {nvcc_path}")

print(f"Using NVCC path: {nvcc_path}")

# Detect Python executable
Expand Down