Compare commits

...
2 Commits
Author SHA1 Message Date
yyc12345 a72a685c84 refactor: update packer artifact functions return type 2026-08-05 14:43:23 +08:00
yyc12345 c28f08b75d fix: fix packer archiver splittor issue 2026-08-05 14:38:34 +08:00
2 changed files with 36 additions and 48 deletions
+3 -3
View File
@@ -48,7 +48,7 @@ class Archiver:
target_filepath.parent.mkdir(parents=True, exist_ok=True)
if self.__dist_zip is not None:
self.__dist_zip.mkdir(str(arcname))
self.__dist_zip.mkdir(arcname.as_posix())
def push_file(self, filepath: Path, arcname: Path) -> None:
"""Mirror an existing file into both sinks.
@@ -63,7 +63,7 @@ class Archiver:
shutil.copy(filepath, target_filepath)
if self.__dist_zip is not None:
self.__dist_zip.write(filepath, arcname)
self.__dist_zip.write(filepath, arcname.as_posix())
def push_text(self, text: str, arcname: Path) -> None:
"""Mirror in-memory text into both sinks.
@@ -79,7 +79,7 @@ class Archiver:
f.write(text)
if self.__dist_zip is not None:
self.__dist_zip.writestr(str(arcname), text)
self.__dist_zip.writestr(arcname.as_posix(), text)
def __enter__(self) -> "Archiver":
"""Enter the context and return this archiver as the bound target."""
+33 -45
View File
@@ -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,16 +85,12 @@ 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(
project_root / header.from_path, to_path / header.from_path
)
yield FileCopyInfo(
project_root / header.from_path, to_path / header.from_path
)
return tuple(rv)
def _generate_dll_artifact_name(name: str) -> str:
match sys.platform:
@@ -110,32 +109,25 @@ 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(
target_directory / dll_artifact_filename,
Path("bin" if sys.platform == "win32" else "lib") / dll_artifact_filename,
)
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(
target_directory / lib_artifact_filename,
Path("lib") / lib_artifact_filename,
)
yield FileCopyInfo(
target_directory / lib_artifact_filename,
Path("lib") / lib_artifact_filename,
)
return tuple(rv)
@dataclass(frozen=True)
class TextCopyInfo:
@@ -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,29 +174,27 @@ def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
)
render = CMakeRender(properties)
# return infos
return (
TextCopyInfo(
render.render_config(),
Path(
"lib",
"cmake",
cmake_target_name,
f"{cmake_target_name}Config.cmake",
),
yield TextCopyInfo(
render.render_config(),
Path(
"lib",
"cmake",
cmake_target_name,
f"{cmake_target_name}Config.cmake",
),
TextCopyInfo(
render.render_config_version(),
Path(
"lib",
"cmake",
cmake_target_name,
f"{cmake_target_name}ConfigVersion.cmake",
),
)
yield TextCopyInfo(
render.render_config_version(),
Path(
"lib",
"cmake",
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"))