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

tools: Add support for Alpine Linux #14382

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions conan/tools/system/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_default_tool(self):
elif os_name == "Windows" and self._conanfile.conf.get("tools.microsoft.bash:subsystem") == "msys2":
os_name = "msys2"
manager_mapping = {"apt-get": ["Linux", "ubuntu", "debian", "raspbian"],
"apk": ["alpine"],
"yum": ["pidora", "scientific", "xenserver", "amazon", "oracle", "amzn",
"almalinux", "rocky"],
"dnf": ["fedora", "rhel", "centos", "mageia"],
Expand Down Expand Up @@ -332,6 +333,25 @@ def __init__(self, conanfile, arch_names=None):
self._arch_separator = "-"


class Apk(_SystemPackageManagerTool):
tool_name = "apk"
install_command = "{sudo}{tool} add --no-cache {packages}"
update_command = "{sudo}{tool} update"
check_command = "{tool} info -e {package}"

def __init__(self, conanfile, _arch_names=None):
"""
Constructor method.
Note that *Apk* does not support architecture names since Alpine Linux does not support
multiarch. Therefore, the ``arch_names`` argument is ignored.

:param conanfile: the current recipe object. Always use ``self``.
"""
super(Apk, self).__init__(conanfile)
self._arch_names = {}
self._arch_separator = ""


class Zypper(_SystemPackageManagerTool):
tool_name = "zypper"
install_command = "{sudo}{tool} --non-interactive in {packages}"
Expand Down
12 changes: 8 additions & 4 deletions conans/test/integration/tools/system/package_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest
from unittest.mock import PropertyMock

from conan.tools.system.package_manager import Apt, Dnf, Yum, Brew, Pkg, PkgUtil, Chocolatey, Zypper, \
PacMan, _SystemPackageManagerTool
from conan.tools.system.package_manager import Apt, Apk, Dnf, Yum, Brew, Pkg, PkgUtil, Chocolatey, \
Zypper, PacMan, _SystemPackageManagerTool
from conans.errors import ConanException
from conans.model.conf import Conf
from conans.model.settings import Settings
Expand Down Expand Up @@ -58,6 +58,7 @@ def test_msys2():
("opensuse-leap", "zypper"),
("opensuse-next_version", "zypper"),
("freebsd", "pkg"),
("alpine", "apk"),
])
@pytest.mark.skipif(platform.system() != "Linux", reason="Only linux")
def test_package_manager_distro(distro, tool):
Expand Down Expand Up @@ -107,7 +108,7 @@ def test_apt_install_recommends(recommends, recommends_str):


@pytest.mark.parametrize("tool_class",
[Apt, Yum, Dnf, Brew, Pkg, PkgUtil, Chocolatey, PacMan, Zypper])
[Apk, Apt, Yum, Dnf, Brew, Pkg, PkgUtil, Chocolatey, PacMan, Zypper])
def test_tools_install_mode_check(tool_class):
conanfile = ConanFileMock()
conanfile.conf = Conf()
Expand All @@ -132,6 +133,7 @@ def fake_check(*args, **kwargs):

@pytest.mark.parametrize("tool_class, result",
[
(Apk, "apk update"),
(Apt, "apt-get update"),
(Yum, "yum check-update -y"),
(Dnf, "dnf check-update -y"),
Expand Down Expand Up @@ -198,6 +200,7 @@ def fake_run(command, win_bash=False, subsystem=None, env=None, ignore_errors=Fa

@pytest.mark.parametrize("tool_class, arch_host, result", [
# not cross-compile -> do not add host architecture
(Apk, 'x86_64', 'apk add --no-cache package1 package2'),
(Apt, 'x86_64', 'apt-get install -y --no-install-recommends package1 package2'),
(Yum, 'x86_64', 'yum install -y package1 package2'),
(Dnf, 'x86_64', 'dnf install -y package1 package2'),
Expand All @@ -221,7 +224,7 @@ def fake_run(command, win_bash=False, subsystem=None, env=None, ignore_errors=Fa
def test_tools_install_mode_install_different_archs(tool_class, arch_host, result):
conanfile = ConanFileMock()
conanfile.conf = Conf()
conanfile.settings = MockSettings({"arch": f"{arch_host}"})
conanfile.settings = MockSettings({"arch": arch_host})
conanfile.settings_build = MockSettings({"arch": "x86_64"})
conanfile.conf.define("tools.system.package_manager:tool", tool_class.tool_name)
conanfile.conf.define("tools.system.package_manager:mode", "install")
Expand Down Expand Up @@ -267,6 +270,7 @@ def fake_check(*args, **kwargs):


@pytest.mark.parametrize("tool_class, result", [
(Apk, 'apk info -e package'),
(Apt, 'dpkg-query -W -f=\'${Status}\' package | grep -q "ok installed"'),
(Yum, 'rpm -q package'),
(Dnf, 'rpm -q package'),
Expand Down