Skip to content

Commit 0384d64

Browse files
czoidoaagor
andauthored
Fix regression with system package manager tools (#18872)
* package_manager (Apt): Fix check_command for all packages The current `check_command` for Apt at foreign architectures checks for `<package_name:<arch>`. However, this selector doesn't find all packages. The solution is to just check for the package name, dpkg-query will list the architecures and we check for the correct one. Docs: omit Close #18569 * package_manager (Apt): Fix check_command for multiple matches When `dpkg-query` finds multiple matches, it printed that on the same line, which broke the grep. Close #18862 * pass base_name * fix tests * Conan 2.20.1 * Update conan/tools/system/package_manager.py * fix potential issue with \n using raw strings --------- Co-authored-by: Alexander Krabler <alexander.krabler@kuka.com>
1 parent 6960af2 commit 0384d64

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

conan/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from conan.internal.model.workspace import Workspace
33
from conan.internal.model.version import Version
44

5-
__version__ = '2.20.0'
5+
__version__ = '2.20.1'
66
conan_version = Version(__version__)

conan/tools/system/package_manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def check_package(self, package, host_package=True):
233233
arch_name=arch_name,
234234
version="",
235235
version_separator="")
236-
command = self.check_command.format(tool=self.tool_name, package=package, arch_package=arch_package)
236+
command = self.check_command.format(tool=self.tool_name, package=package, arch_package=arch_package, base_name=name)
237+
237238
if version:
238239
if self.check_version_command:
239-
command = self.check_version_command.format(tool=self.tool_name, package=package, version=version, arch_package=arch_package)
240+
command = self.check_version_command.format(tool=self.tool_name, package=package, version=version, arch_package=arch_package,
241+
base_name=name)
240242
else:
241243
self._conanfile.output.warning(f"System requirements: \"{self.tool_name}\" doesn't support package versions,"
242244
f" \"{package}\" will be installed without a specific version.")
@@ -250,8 +252,8 @@ class Apt(_SystemPackageManagerTool):
250252
full_package_name = "{name}{arch_separator}{arch_name}{version_separator}{version}"
251253
install_command = "{sudo}{tool} install -y {recommends}{packages}"
252254
update_command = "{sudo}{tool} update"
253-
check_command = "dpkg-query -W -f='${{Architecture}}' {package} | grep -qEx '({arch_package}|all)'"
254-
check_version_command = "dpkg-query -W -f='${{Architecture}} ${{Version}}' {package} | grep -qEx '({arch_package}|all) {version}'"
255+
check_command = r"dpkg-query -W -f='${{Architecture}}\n' {base_name} | grep -qEx '({arch_package}|all)'"
256+
check_version_command = r"dpkg-query -W -f='${{Architecture}} ${{Version}}\n' {base_name} | grep -qEx '({arch_package}|all) {version}'"
255257

256258
def __init__(self, conanfile, arch_names=None):
257259
"""

test/integration/tools/system/package_manager_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def fake_check(*args, **kwargs):
427427

428428
@pytest.mark.parametrize("tool_class, result", [
429429
(Apk, 'apk info -e package'),
430-
(Apt, 'dpkg-query -W -f=\'${Architecture}\' package | grep -qEx \'(amd64|all)\''),
430+
(Apt, r"dpkg-query -W -f='${Architecture}\n' package | grep -qEx '(amd64|all)'"),
431431
(Yum, 'rpm -q package'),
432432
(Dnf, 'rpm -q package'),
433433
(Brew, 'test -n "$(brew ls --versions package)"'),
@@ -451,7 +451,7 @@ def test_tools_check(tool_class, result):
451451

452452
@pytest.mark.parametrize("tool_class, result", [
453453
(Apk, 'apk info package | grep "0.1"'),
454-
(Apt, 'dpkg-query -W -f=\'${Architecture} ${Version}\' package | grep -qEx \'(amd64|all) 0.1\''),
454+
(Apt, r"dpkg-query -W -f='${Architecture} ${Version}\n' package | grep -qEx '(amd64|all) 0.1'"),
455455
(Yum, 'rpm -q package-0.1'),
456456
(Dnf, 'rpm -q package-0.1'),
457457
(Brew, 'brew list --versions package | grep "0.1"'),
@@ -470,4 +470,4 @@ def test_tools_check_with_version(tool_class, result):
470470
tool = tool_class(conanfile)
471471
tool.check(["package=0.1"])
472472

473-
assert tool._conanfile.command == result
473+
assert tool._conanfile.command == result

0 commit comments

Comments
 (0)