From c6cb4a4abda727e84738ef969c4cbea7ec302d17 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Mon, 27 Jan 2025 15:46:41 +0200 Subject: [PATCH] fix: force dry run build on task initialization for VCS packages Previously if package is VCS and version in PKGBUILD doesn't match to AUR one, then makepkg will update pkgbuild ignoring all previous pkgrel patches With this change during task init dry ryn process is always run for vcs packages --- src/ahriman/core/build_tools/task.py | 7 +++++-- src/ahriman/models/package.py | 2 -- tests/ahriman/core/build_tools/test_task.py | 15 +++++++++++++++ tests/ahriman/models/test_package.py | 3 --- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/ahriman/core/build_tools/task.py b/src/ahriman/core/build_tools/task.py index 6604c5d0..38fe741d 100644 --- a/src/ahriman/core/build_tools/task.py +++ b/src/ahriman/core/build_tools/task.py @@ -149,8 +149,11 @@ class Task(LazyLogging): str | None: current commit sha if available """ last_commit_sha = Sources.load(sources_dir, self.package, patches, self.paths) - if local_version is None: - return last_commit_sha # there is no local package or pkgrel increment is disabled + if self.package.is_vcs: # if package is VCS, then make sure to update PKGBUILD to the latest version + self.build(sources_dir, dry_run=True) + + if local_version is None: # there is no local package or pkgrel increment is disabled + return last_commit_sha # load fresh package loaded_package = Package.from_build(sources_dir, self.architecture, None) diff --git a/src/ahriman/models/package.py b/src/ahriman/models/package.py index c51eb2b6..ee1ca8df 100644 --- a/src/ahriman/models/package.py +++ b/src/ahriman/models/package.py @@ -432,8 +432,6 @@ class Package(LazyLogging): with self.suppress_logging(): # create fresh chroot environment, fetch sources and - automagically - update PKGBUILD task.init(paths.cache_for(self.base), [], None) - task.build(paths.cache_for(self.base), dry_run=True) - pkgbuild = Pkgbuild.from_file(paths.cache_for(self.base) / "PKGBUILD") return full_version(pkgbuild.get("epoch"), pkgbuild["pkgver"], pkgbuild["pkgrel"]) diff --git a/tests/ahriman/core/build_tools/test_task.py b/tests/ahriman/core/build_tools/test_task.py index 460819e9..34e81255 100644 --- a/tests/ahriman/core/build_tools/test_task.py +++ b/tests/ahriman/core/build_tools/test_task.py @@ -117,6 +117,21 @@ def test_init(task_ahriman: Task, mocker: MockerFixture) -> None: load_mock.assert_called_once_with(Path("ahriman"), task_ahriman.package, patches, task_ahriman.paths) +def test_init_vcs(task_ahriman: Task, mocker: MockerFixture) -> None: + """ + must copy tree instead of fetch + """ + task_ahriman.package.base += "-git" + mocker.patch("ahriman.models.package.Package.from_build", return_value=task_ahriman.package) + load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load", return_value="sha") + build_mock = mocker.patch("ahriman.core.build_tools.task.Task.build") + + local = Path("ahriman") + assert task_ahriman.init(local, [], None) == "sha" + load_mock.assert_called_once_with(local, task_ahriman.package, [], task_ahriman.paths) + build_mock.assert_called_once_with(local, dry_run=True) + + def test_init_bump_pkgrel(task_ahriman: Task, mocker: MockerFixture) -> None: """ must bump pkgrel if it is same as provided diff --git a/tests/ahriman/models/test_package.py b/tests/ahriman/models/test_package.py index e38e2298..a3815381 100644 --- a/tests/ahriman/models/test_package.py +++ b/tests/ahriman/models/test_package.py @@ -359,13 +359,10 @@ def test_actual_version_vcs(package_tpacpi_bat_git: Package, configuration: Conf mocker.patch("ahriman.models.pkgbuild.Pkgbuild.from_file", return_value=Pkgbuild.from_file(pkgbuild)) mocker.patch("pathlib.Path.glob", return_value=[Path("local")]) init_mock = mocker.patch("ahriman.core.build_tools.task.Task.init") - build_mock = mocker.patch("ahriman.core.build_tools.task.Task.build") unlink_mock = mocker.patch("pathlib.Path.unlink") assert package_tpacpi_bat_git.actual_version(configuration) == "3.1.r13.g4959b52-1" init_mock.assert_called_once_with(configuration.repository_paths.cache_for(package_tpacpi_bat_git.base), [], None) - build_mock.assert_called_once_with(configuration.repository_paths.cache_for(package_tpacpi_bat_git.base), - dry_run=True) unlink_mock.assert_called_once_with()