fix: update packages properties after rebuild

This case leads to issue when it is impossible to update list of
implicit dependencies correctly in case of multi-packages
This commit is contained in:
Evgenii Alekseev 2024-12-24 15:13:18 +02:00
parent 0660c33de3
commit 286ff4bcef
5 changed files with 44 additions and 2 deletions

View File

@ -136,7 +136,7 @@ class PackageArchive:
dependencies, roots = self.depends_on_paths()
installed_packages = self.installed_packages()
# build list of packages, which contains both the package itself and (possible) debug packages
packages = list(self.package.packages) + [f"{package}-debug" for package in self.package.packages]
packages = list(self.package.packages) + [f"{self.package.base}-debug"]
# build initial map of file path -> packages containing this path
# in fact, keys will contain all libraries the package linked to and all directories it contains

View File

@ -62,6 +62,8 @@ class Executor(PackageInfo, Cleaner):
patches = self.reporter.package_patches_get(package.base, None)
commit_sha = task.init(local_path, patches, local_version)
built = task.build(local_path, PACKAGER=packager_id)
package.with_packages(built, self.pacman)
for src in built:
dst = self.paths.packages / src.name
shutil.move(src, dst)

View File

@ -568,3 +568,19 @@ class Package(LazyLogging):
dict[str, Any]: json-friendly dictionary
"""
return dataclass_view(self)
def with_packages(self, packages: list[Path], pacman: Pacman) -> None:
"""
replace packages descriptions with ones from archives
Args:
packages(Iterable[Path]): paths to package archives
pacman(Pacman): alpm wrapper instance
"""
self.packages = {} # reset state
for package in packages:
archive = self.from_archive(package, pacman)
if archive.base != self.base:
continue
self.packages.update(archive.packages)

View File

@ -29,9 +29,11 @@ def test_process_build(executor: Executor, package_ahriman: Package, passwd: Any
depends_on_mock = mocker.patch("ahriman.core.build_tools.package_archive.PackageArchive.depends_on",
return_value=Dependencies())
dependencies_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_dependencies_update")
with_packages_mock = mocker.patch("ahriman.models.package.Package.with_packages")
executor.process_build([package_ahriman], Packagers("packager"), bump_pkgrel=False)
init_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), None)
with_packages_mock.assert_called_once_with([Path(package_ahriman.base)], executor.pacman)
changes_mock.assert_called_once_with(package_ahriman.base)
depends_on_mock.assert_called_once_with()
dependencies_mock.assert_called_once_with(package_ahriman.base, Dependencies())

View File

@ -1,6 +1,8 @@
import copy
from pathlib import Path
from pytest_mock import MockerFixture
from unittest.mock import MagicMock
from unittest.mock import MagicMock, call as MockCall
from ahriman.core.alpm.pacman import Pacman
from ahriman.core.configuration import Configuration
@ -493,3 +495,23 @@ def test_build_status_pretty_print(package_ahriman: Package) -> None:
"""
assert package_ahriman.pretty_print()
assert isinstance(package_ahriman.pretty_print(), str)
def test_with_packages(package_ahriman: Package, package_python_schedule: Package, pacman: Pacman,
mocker: MockerFixture) -> None:
"""
must correctly replace packages descriptions
"""
paths = [Path("1"), Path("2")]
from_archive_mock = mocker.patch("ahriman.models.package.Package.from_archive", side_effect=[
package_ahriman, package_python_schedule
])
result = copy.deepcopy(package_ahriman)
package_ahriman.packages[package_ahriman.base].architecture = "i686"
result.with_packages(paths, pacman)
from_archive_mock.assert_has_calls([
MockCall(path, pacman) for path in paths
])
assert result.packages[result.base] == package_ahriman.packages[package_ahriman.base]