Skip to content

Conversation

@sveinuah
Copy link
Contributor

@sveinuah sveinuah commented Oct 12, 2025

Changelog: Bugfix: Fixes an issue where the Apt packages for the build arch would be reported missing, in cross-compiling scenarios, even though they are installed.
Docs: Omit

Fixes #19073

@CLAassistant
Copy link

CLAassistant commented Oct 12, 2025

CLA assistant check
All committers have signed the CLA.

@memsharded memsharded added this to the 2.22.0 milestone Oct 13, 2025
Comment on lines 231 to 234
if host_package:
check_arch = self._arch or self._conanfile.settings_build.get_safe('arch')
else:
check_arch = self._conanfile.settings_build.get_safe('arch')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sveinuah,
Thanks a lot for the contribution. I think we could simplify the code to this?

Suggested change
if host_package:
check_arch = self._arch or self._conanfile.settings_build.get_safe('arch')
else:
check_arch = self._conanfile.settings_build.get_safe('arch')
check_arch = self._arch if host_package else self._conanfile.settings_build.get_safe('arch')

Because when host_package=True, we should use the host architecture (self._arch) and not fallback to settings_build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original thought as well, but the test_tools_check tests failed when I tried. I kept the old implementation in the host_package branch, in case there was a specific reason for it.

test/integration/tools/system/package_manager_test.py:449: AssertionError
____________ test_tools_check_with_version[Apt-dpkg-query -W -f='${Architecture} ${Version}\\n' package | grep -qEx '(amd64|all) 0.1']
...

E       assert "dpkg-query -...one|all) 0.1'" == "dpkg-query -...d64|all) 0.1'"
E         Skipping 60 identical leading characters in diff, use -v to show
E         - ep -qEx '(amd64|all) 0.1'
E         ?           ^^^^^
E         + ep -qEx '(None|all) 0.1'
E         ?  

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. It may just have been a missing setting in the test. Adding the patch below, makes the tests pass.
Should I add this to the PR, and apply your suggestion?

Adding

diff --git a/test/integration/tools/system/package_manager_test.py b/test/integration/tools/system/package_manager_test.py
index e6b40c51a..ad9360731 100644
--- a/test/integration/tools/system/package_manager_test.py
+++ b/test/integration/tools/system/package_manager_test.py
@@ -439,7 +439,7 @@ def test_tools_install_archless_with_version(tool_class, result):
 ])
 def test_tools_check(tool_class, result):
     conanfile = ConanFileMock()
-    conanfile.settings = Settings()
+    conanfile.settings = MockSettings({"arch": "x86_64"})
     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"
@@ -463,7 +463,7 @@ def test_tools_check(tool_class, result):
 ])
 def test_tools_check_with_version(tool_class, result):
     conanfile = ConanFileMock()
-    conanfile.settings = Settings()
+    conanfile.settings = MockSettings({"arch": "x86_64"})
     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"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that the test should have the MockSettings({"arch": "x86_64"} defined, that's the reason the test was failing.

@sveinuah sveinuah force-pushed the feature/fix-apt-install-no-host-pkg-arch branch from 1fe966a to 3dda692 Compare October 13, 2025 17:04
Apt.check(<pkg>, host_package=False) added the host arch,
instead of the build arch to the dpkg query, if used in
a recipe during cross-building conan install invocations.
This fix ensures that the `settings_build.arch` is used
to make the query in this context.

Issue: conan-io#19073
@sveinuah sveinuah force-pushed the feature/fix-apt-install-no-host-pkg-arch branch from 3dda692 to ef8ff91 Compare October 13, 2025 17:07
The mocked settings was missing an `arch`,
causing `_SystemPackageManagerTool._arch` to
be unset in the tests, leading to erroneous
test failures.
@sveinuah sveinuah force-pushed the feature/fix-apt-install-no-host-pkg-arch branch from ef8ff91 to 9679012 Compare October 13, 2025 17:16
@sveinuah
Copy link
Contributor Author

Updated PR with the MockSettings, and your suggestion @czoido. Should be good to go from my side now :)

@czoido czoido merged commit 414cad2 into conan-io:develop2 Oct 14, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Host arch is used instead of build arch during Apt.check, when cross-building and host_package==False

5 participants