Skip to content
Open
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
16 changes: 14 additions & 2 deletions conan/tools/qbs/qbsdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def render(self):
class _QbsDepGenerator:
""" Handles a single package, can create multiple modules in case of several components
"""
def __init__(self, conanfile, dep, build_bindirs):
def __init__(self, conanfile, dep, build_bindirs, use_cmake_file_name):
Copy link
Member

Choose a reason for hiding this comment

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

Probably no need of the new argument, if we are going to use properties, maybe the approach should be similar to CMakeDeps and allow a local QBSDeps.set_property() that can override the upstream property, and also allows defining the property locally. This would be general for any property that the generator might use in the future too.

self._conanfile = conanfile
self._dep = dep
self._build_bindirs = build_bindirs
self._use_cmake_file_name = use_cmake_file_name

@property
def content(self):
Expand All @@ -68,6 +69,8 @@ def content(self):
def _get_package_name(dep):
# TODO: pkgconfig uses suffix, do we need it? see:
# https://github.com/conan-io/conan/blob/develop2/conan/tools/gnu/pkgconfigdeps.py#L319
if self._use_cmake_file_name:
return dep.cpp_info.get_property("cmake_file_name") or dep.ref.name
return dep.cpp_info.get_property("pkg_config_name") or dep.ref.name

def _get_component_name(dep, comp_name):
Expand Down Expand Up @@ -166,6 +169,15 @@ def __init__(self, conanfile):
:param conanfile: The current recipe object. Always use ``self``.
"""
self._conanfile = conanfile
self._use_cmake_file_name = False

@property
def use_cmake_file_name(self):
return self._use_cmake_file_name

@use_cmake_file_name.setter
def use_cmake_file_name(self, value):
self._use_cmake_file_name = value
Comment on lines +175 to +180
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, probably no need of new setter/getter, and the QBSDeps.set_property() is the way to go


@property
def content(self):
Expand All @@ -186,7 +198,7 @@ def content(self):
continue

dep_build_bindirs = build_bindirs.get(dep.ref.name, [])
qbs_files.update(_QbsDepGenerator(self._conanfile, dep, dep_build_bindirs).content)
qbs_files.update(_QbsDepGenerator(self._conanfile, dep, dep_build_bindirs, self._use_cmake_file_name).content)
return qbs_files

def generate(self):
Expand Down
35 changes: 35 additions & 0 deletions test/integration/toolchains/qbs/test_qbsdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ def package_info(self):
assert os.path.exists(module_path)


def test_cmake_file_name():
# Checks we can override module name using the "test_cmake_file_name" property
conanfile = textwrap.dedent('''
from conan import ConanFile

class Recipe(ConanFile):
name = 'mylib'
version = '0.1'
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "MyFirstLib")
''')
client = TestClient()
client.save({'conanfile.py': conanfile})
client.run('create .')

client2 = TestClient(cache_folder=client.cache_folder)
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.qbs import QbsDeps

class ConsumerConan(ConanFile):
requires = "mylib/0.1"

def generate(self):
deps = QbsDeps(self)
deps.use_cmake_file_name = True
deps.generate()
""")
client2.save({"conanfile.py": conanfile})
client2.run("install .")

module_path = os.path.join(client2.current_folder, 'conan-qbs-deps', 'MyFirstLib.json')
assert os.path.exists(module_path)


@pytest.mark.parametrize('host_os, arch, build_type', [
('Linux', 'x86_64', 'Debug'),
('Linux', 'x86_64', 'Release'),
Expand Down
Loading