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) target_filepath.parent.mkdir(parents=True, exist_ok=True)
if self.__dist_zip is not None: 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: def push_file(self, filepath: Path, arcname: Path) -> None:
"""Mirror an existing file into both sinks. """Mirror an existing file into both sinks.
@@ -63,7 +63,7 @@ class Archiver:
shutil.copy(filepath, target_filepath) shutil.copy(filepath, target_filepath)
if self.__dist_zip is not None: 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: def push_text(self, text: str, arcname: Path) -> None:
"""Mirror in-memory text into both sinks. """Mirror in-memory text into both sinks.
@@ -79,7 +79,7 @@ class Archiver:
f.write(text) f.write(text)
if self.__dist_zip is not None: 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": def __enter__(self) -> "Archiver":
"""Enter the context and return this archiver as the bound target.""" """Enter the context and return this archiver as the bound target."""
+33 -45
View File
@@ -1,5 +1,6 @@
import sys import sys
import logging import logging
from typing import Iterator
from pathlib import Path from pathlib import Path
from dataclasses import dataclass from dataclasses import dataclass
from re import Pattern, compile from re import Pattern, compile
@@ -66,13 +67,15 @@ class FileCopyInfo:
"""The path of destination file relative to the install directory""" """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 extractor = ctx.extractor
metadata = ctx.metadata metadata = ctx.metadata
project_root = Path(extractor.get_project_dir()) project_root = Path(extractor.get_project_dir())
rv: list[FileCopyInfo] = []
for header in metadata.headers: 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) to_path = Path("include") / Path(header.to_path)
if _is_glob_pattern(header.from_path): if _is_glob_pattern(header.from_path):
(common_prefix, glob_residue) = _extract_common_prefix(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: # YYC MARK:
# Built ``subpath`` is prefix with ``new_project_root`` # Built ``subpath`` is prefix with ``new_project_root``
relative_subpath = subpath.relative_to(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: else:
rv.append( yield FileCopyInfo(
FileCopyInfo( project_root / header.from_path, to_path / header.from_path
project_root / header.from_path, to_path / header.from_path
)
) )
return tuple(rv)
def _generate_dll_artifact_name(name: str) -> str: def _generate_dll_artifact_name(name: str) -> str:
match sys.platform: match sys.platform:
@@ -110,32 +109,25 @@ def _generate_lib_artifact_name(name: str) -> str:
return f"{name}.dll.lib" return f"{name}.dll.lib"
def resolve_lib_copy(ctx: ArtifactContext) -> tuple[FileCopyInfo, ...]: def resolve_lib_copy(ctx: ArtifactContext) -> Iterator[FileCopyInfo]:
extractor = ctx.extractor extractor = ctx.extractor
target_directory = extractor.get_target_directory() / "release" target_directory = extractor.get_target_directory() / "release"
target_name = extractor.get_target_name() target_name = extractor.get_target_name()
rv: list[FileCopyInfo] = []
# copy artifact for redist # copy artifact for redist
dll_artifact_filename = _generate_dll_artifact_name(target_name) dll_artifact_filename = _generate_dll_artifact_name(target_name)
rv.append( yield FileCopyInfo(
FileCopyInfo( target_directory / dll_artifact_filename,
target_directory / dll_artifact_filename, Path("bin" if sys.platform == "win32" else "lib") / dll_artifact_filename,
Path("bin" if sys.platform == "win32" else "lib") / dll_artifact_filename,
)
) )
# copy artifact for linking only on windows # copy artifact for linking only on windows
if sys.platform == "win32": if sys.platform == "win32":
lib_artifact_filename = _generate_lib_artifact_name(target_name) lib_artifact_filename = _generate_lib_artifact_name(target_name)
rv.append( yield FileCopyInfo(
FileCopyInfo( target_directory / lib_artifact_filename,
target_directory / lib_artifact_filename, Path("lib") / lib_artifact_filename,
Path("lib") / lib_artifact_filename,
)
) )
return tuple(rv)
@dataclass(frozen=True) @dataclass(frozen=True)
class TextCopyInfo: class TextCopyInfo:
@@ -156,7 +148,7 @@ def _sanitize_name(name: str) -> str:
return new_name return new_name
def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]: def resolve_cmake_copy(ctx: ArtifactContext) -> Iterator[TextCopyInfo]:
extractor = ctx.extractor extractor = ctx.extractor
metadata = ctx.metadata metadata = ctx.metadata
target_name = extractor.get_target_name() target_name = extractor.get_target_name()
@@ -182,29 +174,27 @@ def resolve_cmake_copy(ctx: ArtifactContext) -> tuple[TextCopyInfo, ...]:
) )
render = CMakeRender(properties) render = CMakeRender(properties)
# return infos # return infos
return ( yield TextCopyInfo(
TextCopyInfo( render.render_config(),
render.render_config(), Path(
Path( "lib",
"lib", "cmake",
"cmake", cmake_target_name,
cmake_target_name, f"{cmake_target_name}Config.cmake",
f"{cmake_target_name}Config.cmake",
),
), ),
TextCopyInfo( )
render.render_config_version(), yield TextCopyInfo(
Path( render.render_config_version(),
"lib", Path(
"cmake", "lib",
cmake_target_name, "cmake",
f"{cmake_target_name}ConfigVersion.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 extractor = ctx.extractor
metadata = ctx.metadata metadata = ctx.metadata
target_name = extractor.get_target_name() 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() pkgconfig_name, pkgconfig_description, target_name, extractor.get_version()
) )
render = PkgConfigRender(properties) render = PkgConfigRender(properties)
return ( yield TextCopyInfo(render.render(), Path("lib", "pkgconfig", f"{pkgconfig_id}.pc"))
TextCopyInfo(render.render(), Path("lib", "pkgconfig", f"{pkgconfig_id}.pc")),
)