Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(part_handler): fetch correct target stage packages #721

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion craft_parts/executor/part_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def _fetch_stage_packages(self, *, step_info: StepInfo) -> Optional[List[str]]:
fetched_packages = packages.Repository.fetch_stage_packages(
cache_dir=step_info.cache_dir,
package_names=stage_packages,
arch=step_info.host_arch,
arch=step_info.target_arch,
base=step_info.base,
stage_packages_path=self._part.part_packages_dir,
)
Expand Down
26 changes: 22 additions & 4 deletions tests/unit/executor/test_part_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import logging
import os
import platform
from pathlib import Path
from typing import cast
from typing import Dict, cast
from unittest.mock import call

import pytest
Expand Down Expand Up @@ -697,7 +698,7 @@ def test_fetch_stage_packages_error(self, mocker, new_dir, partitions):
assert raised.value.package_name == "pkg1"

def test_pull_fetch_stage_packages_arch(self, mocker, new_dir, partitions):
"""Verify _run_pull fetches stage packages from the host architecture."""
"""Verify _run_pull fetches stage packages for the target architecture."""
getpkg = mocker.patch(
"craft_parts.packages.Repository.fetch_stage_packages",
return_value=["pkg1"],
Expand All @@ -706,7 +707,24 @@ def test_pull_fetch_stage_packages_arch(self, mocker, new_dir, partitions):
part = Part(
"foo", {"plugin": "nil", "stage-packages": ["pkg1"]}, partitions=partitions
)
info = ProjectInfo(application_name="test", cache_dir=new_dir)

_platform_machine_translations: Dict[str, str] = {
# Maps other possible ``platform.machine()`` values to the arch translations below.
"arm64": "aarch64",
"armv7hl": "armv7l",
"i386": "i686",
"amd64": "x86_64",
"x64": "x86_64",
}

machine = platform.machine()
host_arch = _platform_machine_translations.get(machine.lower(), machine)
target_arch = "aarch64"

if host_arch != "x86_64":
target_arch = "x86_64"

info = ProjectInfo(application_name="test", cache_dir=new_dir, arch=target_arch)
part_info = PartInfo(info, part)
ovmgr = OverlayManager(project_info=info, part_list=[part], base_layer_dir=None)
handler = PartHandler(
Expand All @@ -719,7 +737,7 @@ def test_pull_fetch_stage_packages_arch(self, mocker, new_dir, partitions):
base=mocker.ANY,
package_names=mocker.ANY,
stage_packages_path=mocker.ANY,
arch=part_info.host_arch,
arch=part_info.target_arch,
)

def test_fetch_stage_snaps(self, mocker, new_dir, partitions):
Expand Down
Loading