refactor: update packer artifact functions return type
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
import logging
|
||||
from typing import Iterator
|
||||
from pathlib import Path
|
||||
from dataclasses import dataclass
|
||||
from re import Pattern, compile
|
||||
@@ -66,13 +67,15 @@ class FileCopyInfo:
|
||||
"""The path of destination file relative to the install directory"""
|
||||
|
||||
|
||||
def resolve_include_copy(ctx: ArtifactContext) -> tuple[FileCopyInfo, ...]:
|
||||
def resolve_include_copy(ctx: ArtifactContext) -> Iterator[FileCopyInfo]:
|
||||
extractor = ctx.extractor
|
||||
metadata = ctx.metadata
|
||||
project_root = Path(extractor.get_project_dir())
|
||||
rv: list[FileCopyInfo] = []
|
||||
|
||||
for header in metadata.headers:
|
||||
logging.debug(
|
||||
"Resolving header copy rule: %s -> %s", header.from_path, header.to_path
|
||||
)
|
||||
to_path = Path("include") / Path(header.to_path)
|
||||
if _is_glob_pattern(header.from_path):
|
||||
(common_prefix, glob_residue) = _extract_common_prefix(header.from_path)
|
||||
@@ -82,15 +85,11 @@ def resolve_include_copy(ctx: ArtifactContext) -> tuple[FileCopyInfo, ...]:
|
||||
# YYC MARK:
|
||||
# Built ``subpath`` is prefix with ``new_project_root``
|
||||
relative_subpath = subpath.relative_to(new_project_root)
|
||||
rv.append(FileCopyInfo(subpath, to_path / relative_subpath))
|
||||
yield FileCopyInfo(subpath, to_path / relative_subpath)
|
||||
else:
|
||||
rv.append(
|
||||
FileCopyInfo(
|
||||
yield FileCopyInfo(
|
||||
project_root / header.from_path, to_path / header.from_path
|
||||
)
|
||||
)
|
||||
|
||||
return tuple(rv)
|
||||
|
||||
|
||||
def _generate_dll_artifact_name(name: str) -> str:
|
||||
@@ -110,31 +109,24 @@ def _generate_lib_artifact_name(name: str) -> str:
|
||||
return f"{name}.dll.lib"
|
||||
|
||||
|
||||
def resolve_lib_copy(ctx: ArtifactContext) -> tuple[FileCopyInfo, ...]:
|
||||
def resolve_lib_copy(ctx: ArtifactContext) -> Iterator[FileCopyInfo]:
|
||||
extractor = ctx.extractor
|
||||
target_directory = extractor.get_target_directory() / "release"
|
||||
target_name = extractor.get_target_name()
|
||||
rv: list[FileCopyInfo] = []
|
||||
|
||||
# copy artifact for redist
|
||||
dll_artifact_filename = _generate_dll_artifact_name(target_name)
|
||||
rv.append(
|
||||
FileCopyInfo(
|
||||
yield FileCopyInfo(
|
||||
target_directory / dll_artifact_filename,
|
||||
Path("bin" if sys.platform == "win32" else "lib") / dll_artifact_filename,
|
||||
)
|
||||
)
|
||||
# copy artifact for linking only on windows
|
||||
if sys.platform == "win32":
|
||||
lib_artifact_filename = _generate_lib_artifact_name(target_name)
|
||||
rv.append(
|
||||
FileCopyInfo(
|
||||
yield FileCopyInfo(
|
||||
target_directory / lib_artifact_filename,
|
||||
Path("lib") / lib_artifact_filename,
|
||||
)
|
||||
)
|
||||
|
||||
return tuple(rv)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -156,7 +148,7 @@ def _sanitize_name(name: str) -> str:
|
||||
return new_name
|
||||
|
||||
|
||||
def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
|
||||
def resolve_cmake_copy(ctx: ArtifactContext) -> Iterator[TextCopyInfo]:
|
||||
extractor = ctx.extractor
|
||||
metadata = ctx.metadata
|
||||
target_name = extractor.get_target_name()
|
||||
@@ -182,8 +174,7 @@ def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
|
||||
)
|
||||
render = CMakeRender(properties)
|
||||
# return infos
|
||||
return (
|
||||
TextCopyInfo(
|
||||
yield TextCopyInfo(
|
||||
render.render_config(),
|
||||
Path(
|
||||
"lib",
|
||||
@@ -191,8 +182,8 @@ def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
|
||||
cmake_target_name,
|
||||
f"{cmake_target_name}Config.cmake",
|
||||
),
|
||||
),
|
||||
TextCopyInfo(
|
||||
)
|
||||
yield TextCopyInfo(
|
||||
render.render_config_version(),
|
||||
Path(
|
||||
"lib",
|
||||
@@ -200,11 +191,10 @@ def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
|
||||
cmake_target_name,
|
||||
f"{cmake_target_name}ConfigVersion.cmake",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def resolve_pkgconfig_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
|
||||
def resolve_pkgconfig_copy(ctx: ArtifactContext) -> Iterator[TextCopyInfo]:
|
||||
extractor = ctx.extractor
|
||||
metadata = ctx.metadata
|
||||
target_name = extractor.get_target_name()
|
||||
@@ -227,6 +217,4 @@ def resolve_pkgconfig_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
|
||||
pkgconfig_name, pkgconfig_description, target_name, extractor.get_version()
|
||||
)
|
||||
render = PkgConfigRender(properties)
|
||||
return (
|
||||
TextCopyInfo(render.render(), Path("lib", "pkgconfig", f"{pkgconfig_id}.pc")),
|
||||
)
|
||||
yield TextCopyInfo(render.render(), Path("lib", "pkgconfig", f"{pkgconfig_id}.pc"))
|
||||
|
||||
Reference in New Issue
Block a user