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

Fix XcodeDeps includes skipped dependencies #13880

Merged
merged 15 commits into from
May 12, 2023
16 changes: 9 additions & 7 deletions conan/tools/apple/xcodedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _conf_xconfig_file(self, require, pkg_name, comp_name, package_folder, trans
"""
def _merged_vars(name):
merged = [var for cpp_info in transitive_cpp_infos for var in getattr(cpp_info, name)]
return list(OrderedDict.fromkeys(merged).keys())
czoido marked this conversation as resolved.
Show resolved Hide resolved
return list(set(merged))
czoido marked this conversation as resolved.
Show resolved Hide resolved

# TODO: Investigate if paths can be made relative to "root" folder
fields = {
Expand Down Expand Up @@ -206,9 +206,10 @@ def _all_xconfig_file(self, deps, content):
"""
content_multi = content or self._all_xconfig

for req, dep in deps.items():
dep_name = _format_name(dep.ref.name)
content_multi = content_multi + '\n#include "conan_{}.xcconfig"\n'.format(dep_name)
for dep in deps.values():
include_file = f'conan_{_format_name(dep.ref.name)}.xcconfig'
if include_file not in content_multi:
czoido marked this conversation as resolved.
Show resolved Hide resolved
content_multi = content_multi + f'\n#include "{include_file}"\n'
return content_multi

def _pkg_xconfig_file(self, components):
Expand Down Expand Up @@ -288,8 +289,8 @@ def _transitive_components(component):
_transitive_components(comp_cpp_info)

# remove duplicates
transitive_internal = list(OrderedDict.fromkeys(transitive_internal).keys())
transitive_external = list(OrderedDict.fromkeys(transitive_external).keys())
transitive_internal = list(set(transitive_internal))
transitive_external = list(set(transitive_external))
czoido marked this conversation as resolved.
Show resolved Hide resolved

# In case dep is editable and package_folder=None
pkg_folder = dep.package_folder or dep.recipe_folder
Expand All @@ -301,8 +302,9 @@ def _transitive_components(component):
result.update(component_content)
else:
public_deps = []
transitive_requires = [r for r, _ in get_transitive_requires(self._conanfile, dep).items()]
for r, d in dep.dependencies.direct_host.items():
if not r.visible:
if r not in transitive_requires:
continue
if d.cpp_info.has_components:
sorted_components = d.cpp_info.get_sorted_components().items()
Expand Down
24 changes: 23 additions & 1 deletion conans/test/integration/toolchains/apple/test_xcodedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from conans.test.assets.genconanfile import GenConanfile
from conans.test.integration.toolchains.apple.test_xcodetoolchain import _get_filename
from conans.test.utils.tools import TestClient
from conans.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID

_expected_dep_xconfig = [
"HEADER_SEARCH_PATHS = $(inherited) $(HEADER_SEARCH_PATHS_{name}_{name})",
Expand Down Expand Up @@ -456,3 +456,25 @@ def package_info(self):
assert '#include "conan_lib_c_cmp1.xcconfig"' in lib_b_xconfig
assert '#include "conan_lib_c_cmp1.xcconfig"' in lib_b_xconfig
assert '#include "conan_lib_c_lib_c.xcconfig"' not in lib_b_xconfig


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS")
def test_skipped_not_included():
# https://github.com/conan-io/conan/issues/13818
client = TestClient()
pkg_info = {"components": {"component": {"defines": ["SOMEDEFINE"]}}}

client.save({"dep/conanfile.py": GenConanfile().with_package_type("header-library")
.with_package_info(cpp_info=pkg_info,
env_info={}),
"pkg/conanfile.py": GenConanfile().with_requirement("dep/0.1")
.with_package_type("library")
.with_shared_option(),
"consumer/conanfile.py": GenConanfile().with_requires("pkg/0.1")
.with_settings("os", "build_type", "arch")})
client.run("create dep --name=dep --version=0.1")
client.run("create pkg --name=pkg --version=0.1")
client.run("install consumer -g XcodeDeps -s arch=x86_64 -s build_type=Release")
client.assert_listed_binary({"dep/0.1": (NO_SETTINGS_PACKAGE_ID, "Skip")})
dep_xconfig = client.load("consumer/conan_pkg_pkg.xcconfig")
assert "conan_dep.xcconfig" not in dep_xconfig