-
Notifications
You must be signed in to change notification settings - Fork 1.1k
package_manager version support added #18517
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
Merged
memsharded
merged 19 commits into
conan-io:develop2
from
davidsanfal:feature/package_manager_version#17744
Aug 29, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d2432e6
package_manager version support added
davidsanfal f3fb7c0
check_version_command added
davidsanfal 5aca88b
wip
davidsanfal efb8b67
wip
davidsanfal 8ee42e5
apt check version updated
davidsanfal cc2c68a
wip
davidsanfal 459cfd9
wip
davidsanfal 08292d1
test updated
davidsanfal 3920d99
Update conan/tools/system/package_manager.py
davidsanfal 83a306e
Update conan/tools/system/package_manager.py
davidsanfal 385a982
wip
davidsanfal 60342a5
wip
davidsanfal 04e0fd5
wip
davidsanfal f923d8c
wip
davidsanfal 75a6af7
wip
davidsanfal da7c875
wip
davidsanfal 34802ed
wip
davidsanfal 4e797e4
wip
davidsanfal 45cc3d1
wip
davidsanfal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,47 @@ def fake_check(*args, **kwargs): | |
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, arch_host, result", [ | ||
# Install host package and not cross-compile -> do not add host architecture | ||
(Apk, 'x86_64', 'apk add --no-cache package1=0.1 package2=0.2'), | ||
(Apt, 'x86_64', 'apt-get install -y --no-install-recommends package1=0.1 package2=0.2'), | ||
(Yum, 'x86_64', 'yum install -y package1-0.1 package2-0.2'), | ||
(Dnf, 'x86_64', 'dnf install -y package1-0.1 package2-0.2'), | ||
(Brew, 'x86_64', 'brew install [email protected] [email protected]'), | ||
(Pkg, 'x86_64', 'pkg install -y package1-0.1 package2-0.2'), | ||
(PkgUtil, 'x86_64', 'pkgutil --install --yes [email protected] [email protected]'), | ||
(Chocolatey, 'x86_64', 'choco install --yes package1 --version 0.1 package2 --version 0.2'), | ||
(PacMan, 'x86_64', 'pacman -S --noconfirm package1 package2'), | ||
(Zypper, 'x86_64', 'zypper --non-interactive in package1=0.1 package2=0.2'), | ||
# Install host package and cross-compile -> add host architecture | ||
(Apt, 'x86', 'apt-get install -y --no-install-recommends package1:i386=0.1 package2:i386=0.2'), | ||
(Yum, 'x86', 'yum install -y package1-0.1.i?86 package2-0.2.i?86'), | ||
(Dnf, 'x86', 'dnf install -y package1-0.1.i?86 package2-0.2.i?86'), | ||
(Brew, 'x86', 'brew install [email protected] [email protected]'), | ||
(Pkg, 'x86', 'pkg install -y package1-0.1 package2-0.2'), | ||
(PkgUtil, 'x86', 'pkgutil --install --yes [email protected] [email protected]'), | ||
(Chocolatey, 'x86', 'choco install --yes package1 --version 0.1 package2 --version 0.2'), | ||
(PacMan, 'x86', 'pacman -S --noconfirm package1-lib32 package2-lib32'), | ||
(Zypper, 'x86', 'zypper --non-interactive in package1=0.1 package2=0.2'), | ||
]) | ||
def test_tools_install_mode_install_different_archs_with_version(tool_class, arch_host, result): | ||
conanfile = ConanFileMock() | ||
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") | ||
with mock.patch('conan.ConanFile.context', new_callable=PropertyMock) as context_mock: | ||
context_mock.return_value = "host" | ||
tool = tool_class(conanfile) | ||
|
||
def fake_check(*args, **kwargs): | ||
return ["package1=0.1", "package2=0.2"] | ||
from conan.tools.system.package_manager import _SystemPackageManagerTool | ||
with patch.object(_SystemPackageManagerTool, 'check', MagicMock(side_effect=fake_check)): | ||
tool.install(["package1=0.1", "package2=0.2"]) | ||
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, arch_host, result", [ | ||
# Install build machine package and not cross-compile -> do not add host architecture | ||
(Apk, 'x86_64', 'apk add --no-cache package1 package2'), | ||
|
@@ -288,6 +329,48 @@ def fake_check(*args, **kwargs): | |
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, arch_host, result", [ | ||
# Install build machine package and not cross-compile -> do not add host architecture | ||
(Apk, 'x86_64', 'apk add --no-cache package1=0.1 package2=0.2'), | ||
(Apt, 'x86_64', 'apt-get install -y --no-install-recommends package1=0.1 package2=0.2'), | ||
(Yum, 'x86_64', 'yum install -y package1-0.1 package2-0.2'), | ||
(Dnf, 'x86_64', 'dnf install -y package1-0.1 package2-0.2'), | ||
(Brew, 'x86_64', 'brew install [email protected] [email protected]'), | ||
(Pkg, 'x86_64', 'pkg install -y package1-0.1 package2-0.2'), | ||
(PkgUtil, 'x86_64', 'pkgutil --install --yes [email protected] [email protected]'), | ||
(Chocolatey, 'x86_64', 'choco install --yes package1 --version 0.1 package2 --version 0.2'), | ||
(PacMan, 'x86_64', 'pacman -S --noconfirm package1 package2'), | ||
(Zypper, 'x86_64', 'zypper --non-interactive in package1=0.1 package2=0.2'), | ||
# Install build machine package and cross-compile -> do not add host architecture | ||
(Apt, 'x86', 'apt-get install -y --no-install-recommends package1=0.1 package2=0.2'), | ||
(Yum, 'x86', 'yum install -y package1-0.1 package2-0.2'), | ||
(Dnf, 'x86', 'dnf install -y package1-0.1 package2-0.2'), | ||
(Brew, 'x86', 'brew install [email protected] [email protected]'), | ||
(Pkg, 'x86', 'pkg install -y package1-0.1 package2-0.2'), | ||
(PkgUtil, 'x86', 'pkgutil --install --yes [email protected] [email protected]'), | ||
(Chocolatey, 'x86', 'choco install --yes package1 --version 0.1 package2 --version 0.2'), | ||
(PacMan, 'x86', 'pacman -S --noconfirm package1 package2'), | ||
(Zypper, 'x86', 'zypper --non-interactive in package1=0.1 package2=0.2'), | ||
]) | ||
def test_tools_install_mode_install_to_build_machine_arch_with_version(tool_class, arch_host, result): | ||
conanfile = ConanFileMock() | ||
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") | ||
with mock.patch('conan.ConanFile.context', new_callable=PropertyMock) as context_mock: | ||
context_mock.return_value = "host" | ||
tool = tool_class(conanfile) | ||
|
||
def fake_check(*args, **kwargs): | ||
return ["package1=0.1", "package2=0.2"] | ||
from conan.tools.system.package_manager import _SystemPackageManagerTool | ||
with patch.object(_SystemPackageManagerTool, 'check', MagicMock(side_effect=fake_check)): | ||
tool.install(["package1=0.1", "package2=0.2"], host_package=False) | ||
|
||
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, result", [ | ||
# cross-compile but arch_names=None -> do not add host architecture | ||
# https://github.com/conan-io/conan/issues/12320 because the package is archless | ||
|
@@ -315,9 +398,36 @@ def fake_check(*args, **kwargs): | |
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, result", [ | ||
# cross-compile but arch_names=None -> do not add host architecture | ||
# https://github.com/conan-io/conan/issues/12320 because the package is archless | ||
(Apt, 'apt-get install -y --no-install-recommends package1=0.1 package2=0.2'), | ||
(Yum, 'yum install -y package1-0.1 package2-0.2'), | ||
(Dnf, 'dnf install -y package1-0.1 package2-0.2'), | ||
(PacMan, 'pacman -S --noconfirm package1 package2'), | ||
]) | ||
def test_tools_install_archless_with_version(tool_class, result): | ||
conanfile = ConanFileMock() | ||
conanfile.settings = MockSettings({"arch": "x86"}) | ||
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") | ||
with mock.patch('conan.ConanFile.context', new_callable=PropertyMock) as context_mock: | ||
context_mock.return_value = "host" | ||
tool = tool_class(conanfile, arch_names={}) | ||
|
||
def fake_check(*args, **kwargs): | ||
return ["package1=0.1", "package2=0.2"] | ||
from conan.tools.system.package_manager import _SystemPackageManagerTool | ||
with patch.object(_SystemPackageManagerTool, 'check', MagicMock(side_effect=fake_check)): | ||
tool.install(["package1=0.1", "package2=0.2"]) | ||
|
||
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, result", [ | ||
(Apk, 'apk info -e package'), | ||
(Apt, 'dpkg-query -W -f=\'${Status}\' package | grep -q "ok installed"'), | ||
(Apt, 'dpkg-query -W -f=\'${Architecture}\' package | grep -qEx \'(amd64|all)\''), | ||
(Yum, 'rpm -q package'), | ||
(Dnf, 'rpm -q package'), | ||
(Brew, 'test -n "$(brew ls --versions package)"'), | ||
|
@@ -337,3 +447,27 @@ def test_tools_check(tool_class, result): | |
tool.check(["package"]) | ||
|
||
assert tool._conanfile.command == result | ||
|
||
|
||
@pytest.mark.parametrize("tool_class, result", [ | ||
(Apk, 'apk info package | grep "0.1"'), | ||
(Apt, 'dpkg-query -W -f=\'${Architecture} ${Version}\' package | grep -qEx \'(amd64|all) 0.1\''), | ||
(Yum, 'rpm -q package-0.1'), | ||
(Dnf, 'rpm -q package-0.1'), | ||
(Brew, 'brew list --versions package | grep "0.1"'), | ||
(Pkg, 'pkg info package | grep "Version: 0.1"'), | ||
(PkgUtil, 'test -n "`pkgutil --list package`"'), | ||
(Chocolatey, 'choco list --local-only package | findstr /i "0.1"'), | ||
(PacMan, 'pacman -Qi package'), | ||
(Zypper, 'rpm -q package-0.1'), | ||
]) | ||
def test_tools_check_with_version(tool_class, result): | ||
conanfile = ConanFileMock() | ||
conanfile.settings = Settings() | ||
conanfile.conf.define("tools.system.package_manager:tool", tool_class.tool_name) | ||
with mock.patch('conan.ConanFile.context', new_callable=PropertyMock) as context_mock: | ||
context_mock.return_value = "host" | ||
tool = tool_class(conanfile) | ||
tool.check(["package=0.1"]) | ||
|
||
assert tool._conanfile.command == result |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed these lines because
dpkg -l
doesn't print anything if it doesn't find any package with thesearch pattern