feat: support public/interface dependencies in packer
This commit is contained in:
@@ -14,6 +14,27 @@ from . import common
|
||||
from .. import utils
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CMakeDependency:
|
||||
"""One CMake dependency consumed by the renderer.
|
||||
|
||||
Carries the ``find_dependency`` package name and the link target wired into
|
||||
the imported target's ``INTERFACE_LINK_LIBRARIES``.
|
||||
"""
|
||||
|
||||
package: str
|
||||
"""Package name passed to ``find_dependency`` (e.g. ``ZLIB``)."""
|
||||
target: str
|
||||
"""Link target wired into ``INTERFACE_LINK_LIBRARIES`` (e.g. ``ZLIB::ZLIB``)."""
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Validate that ``package`` and ``target`` are non-empty strings."""
|
||||
if self.package == "":
|
||||
raise ValueError("bad cmake dependency package")
|
||||
if self.target == "":
|
||||
raise ValueError("bad cmake dependency target")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CMakeProperties:
|
||||
"""Inputs required to render the CMake package-configuration files.
|
||||
@@ -44,13 +65,16 @@ class CMakeProperties:
|
||||
|
||||
version: Version
|
||||
"""Version of the library. Must not carry a prerelease or build component."""
|
||||
dependencies: tuple[CMakeDependency, ...]
|
||||
"""CMake dependencies to ``find_dependency`` and link into the target
|
||||
(empty when none are declared)."""
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Validate the fields after construction.
|
||||
|
||||
:raises ValueError: if the namespace or target name contains characters
|
||||
outside the CMake name pattern, an artifact file name is empty, or
|
||||
the version carries a prerelease or build component (unsupported by
|
||||
outside the CMake name pattern, an artifact file name is empty, or the
|
||||
version carries a prerelease or build component (unsupported by
|
||||
CMake config-version files).
|
||||
"""
|
||||
if not utils.is_good_name(self.namespace_name):
|
||||
@@ -99,6 +123,7 @@ class CMakeRender:
|
||||
"target": self.__properties.target_name,
|
||||
"artifact_dll": self.__properties.artifact_dll,
|
||||
"artifact_lib": self.__properties.artifact_lib,
|
||||
"dependencies": self.__properties.dependencies,
|
||||
}
|
||||
return self.__render.render("XXXConfig.cmake.jinja", payload)
|
||||
|
||||
|
||||
@@ -42,13 +42,14 @@ class PkgConfigProperties:
|
||||
|
||||
version: Version
|
||||
"""Version of the library. Must not carry a prerelease or build component."""
|
||||
requires: tuple[str, ...]
|
||||
"""Public pkg-config dependencies (empty when none are declared)."""
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Validate the fields after construction.
|
||||
|
||||
:raises ValueError: if the name or description is blank, or the
|
||||
version carries a prerelease or build component (unsupported in
|
||||
pkg-config).
|
||||
:raises ValueError: if the name or description is blank, or the version
|
||||
carries a prerelease or build component (unsupported in pkg-config).
|
||||
"""
|
||||
if self.name == "" or not utils.is_good_sentence(self.name):
|
||||
raise ValueError("bad name (blank or has EOL chars) of pkg-config")
|
||||
@@ -89,5 +90,6 @@ class PkgConfigRender:
|
||||
"name": self.__properties.name,
|
||||
"description": self.__properties.description,
|
||||
"artifact": self.__properties.artifact,
|
||||
"requires": self.__properties.requires,
|
||||
}
|
||||
return self.__render.render("XXX.pc.jinja", payload)
|
||||
|
||||
Reference in New Issue
Block a user