Skip to content

feat: Parse the CMake file-api during configuration #1016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/scikit_build_core/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
from typing import TYPE_CHECKING, Any

from . import __version__
from ._compat.builtins import ExceptionGroup
from ._logging import logger
from ._shutil import Run
from .errors import CMakeConfigError, CMakeNotFoundError, FailedLiveProcessError
from .file_api.query import stateless_query
from .file_api.reply import load_reply_dir
from .program_search import Program, best_program, get_cmake_program, get_cmake_programs

if TYPE_CHECKING:
Expand All @@ -25,6 +28,7 @@
from packaging.version import Version

from ._compat.typing import Self
from .file_api.model.index import Index

__all__ = ["CMake", "CMaker"]

Expand Down Expand Up @@ -83,6 +87,8 @@
init_cache_file: Path = dataclasses.field(init=False, default=Path())
env: dict[str, str] = dataclasses.field(init=False, default_factory=os.environ.copy)
single_config: bool = not sysconfig.get_platform().startswith("win")
file_api: Index | None = None
_file_api_query: Path = dataclasses.field(init=False)

def __post_init__(self) -> None:
self.init_cache_file = self.build_dir / "CMakeInit.txt"
Expand All @@ -97,6 +103,8 @@
msg = f"build directory {self.build_dir} must be a (creatable) directory"
raise CMakeConfigError(msg)

# TODO: This could be stateful instead
self._file_api_query = stateless_query(self.build_dir)
skbuild_info = self.build_dir / ".skbuild-info.json"
stale = False

Expand Down Expand Up @@ -253,6 +261,13 @@
msg = "CMake configuration failed"
raise FailedLiveProcessError(msg) from None

try:
if self._file_api_query.exists():
self.file_api = load_reply_dir(self._file_api_query)
except ExceptionGroup as exc:
logger.warning("Could not parse CMake file-api")
logger.debug(str(exc))

Check warning on line 269 in src/scikit_build_core/cmake.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/cmake.py#L267-L269

Added lines #L267 - L269 were not covered by tests

def _compute_build_args(
self,
*,
Expand Down
Loading