From 730ba2b1b6ff34ed991d7cdb5ffd5c2f0bbebe86 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 08:40:24 +0200 Subject: [PATCH 1/9] start --- conans/test/integration/toolchains/apple/test_xcodedeps.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conans/test/integration/toolchains/apple/test_xcodedeps.py b/conans/test/integration/toolchains/apple/test_xcodedeps.py index 37881b813dc..7071ad442b0 100644 --- a/conans/test/integration/toolchains/apple/test_xcodedeps.py +++ b/conans/test/integration/toolchains/apple/test_xcodedeps.py @@ -174,3 +174,9 @@ def package_info(self): # folders are aggregated assert "mylibdir" in component4_vars + + +@pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS") +def test_xcodedeps_traits(): + client = TestClient() + From eab60587889cb530bc760cbf37fe74369bd2fef0 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 11:37:36 +0200 Subject: [PATCH 2/9] wip --- conan/tools/apple/xcodedeps.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index 6fd2c4f182d..d1f2753e84b 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -122,7 +122,7 @@ def generate(self): for generator_file, content in generator_files.items(): save(generator_file, content) - def _conf_xconfig_file(self, pkg_name, comp_name, transitive_cpp_infos): + def _conf_xconfig_file(self, require, pkg_name, comp_name, transitive_cpp_infos): """ content for conan_poco_x86_release.xcconfig, containing the activation """ @@ -130,6 +130,24 @@ 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()) + def _process_traits(): + if not require.headers: + fields["include_dirs"] = "" + + if not require.libs: + fields["lib_dirs"] = "" + fields["libs"] = "" + fields["system_libs"] = "" + fields["frameworkdirs"] = "" + fields["frameworks"] = "" + + if not require.libs and not require.headers: + fields["definitions"] = "" + fields["c_compiler_flags"] = "" + fields["cxx_compiler_flags"] = "" + fields["linker_flags"] = "" + fields["exe_flags"] = "" + fields = { 'pkg_name': pkg_name, 'comp_name': comp_name, @@ -137,7 +155,7 @@ def _merged_vars(name): 'lib_dirs': " ".join('"{}"'.format(p) for p in _merged_vars("libdirs")), 'libs': " ".join("-l{}".format(lib) for lib in _merged_vars("libs")), 'system_libs': " ".join("-l{}".format(sys_lib) for sys_lib in _merged_vars("system_libs")), - 'frameworksdirs': " ".join('"{}"'.format(p) for p in _merged_vars("frameworkdirs")), + 'frameworkdirs': " ".join('"{}"'.format(p) for p in _merged_vars("frameworkdirs")), 'frameworks': " ".join("-framework {}".format(framework) for framework in _merged_vars("frameworks")), 'definitions': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("defines")), 'c_compiler_flags': " ".join('"{}"'.format(p.replace('"', '\\"')) for p in _merged_vars("cflags")), @@ -147,6 +165,8 @@ def _merged_vars(name): 'condition': _xcconfig_conditional(self._conanfile.settings) } + _process_traits() + template = Template(self._conf_xconfig) content_multi = template.render(**fields) return content_multi @@ -197,13 +217,13 @@ def _global_xconfig_content(self): GLOBAL_XCCONFIG_TEMPLATE, [self.general_name]) - def get_content_for_component(self, pkg_name, component_name, transitive_internal, transitive_external): + def get_content_for_component(self, require, pkg_name, component_name, transitive_internal, transitive_external): result = {} conf_name = _xcconfig_settings_filename(self._conanfile.settings) props_name = "conan_{}_{}{}.xcconfig".format(pkg_name, component_name, conf_name) - result[props_name] = self._conf_xconfig_file(pkg_name, component_name, transitive_internal) + result[props_name] = self._conf_xconfig_file(require, pkg_name, component_name, transitive_internal) # The entry point for each package file_dep_name = "conan_{}_{}.xcconfig".format(pkg_name, component_name) @@ -220,8 +240,8 @@ def _content(self): # All components are included in the conan_pkgname.xcconfig file host_req = self._conanfile.dependencies.host test_req = self._conanfile.dependencies.test - all_deps = list(host_req.values()) + list(test_req.values()) - for dep in all_deps: + + for require, dep in list(host_req.items()) + list(test_req.items()): dep_name = _format_name(dep.ref.name) @@ -260,7 +280,7 @@ def _transitive_components(component): transitive_internal = list(OrderedDict.fromkeys(transitive_internal).keys()) transitive_external = list(OrderedDict.fromkeys(transitive_external).keys()) - component_content = self.get_content_for_component(dep_name, comp_name, + component_content = self.get_content_for_component(require, dep_name, comp_name, transitive_internal, transitive_external) include_components_names.append((dep_name, comp_name)) From 314d3ed65cbd6be6840fe26933afa240d5698d3d Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 11:37:55 +0200 Subject: [PATCH 3/9] wip --- conan/tools/apple/xcodedeps.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index d1f2753e84b..99674bd440f 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -141,13 +141,6 @@ def _process_traits(): fields["frameworkdirs"] = "" fields["frameworks"] = "" - if not require.libs and not require.headers: - fields["definitions"] = "" - fields["c_compiler_flags"] = "" - fields["cxx_compiler_flags"] = "" - fields["linker_flags"] = "" - fields["exe_flags"] = "" - fields = { 'pkg_name': pkg_name, 'comp_name': comp_name, From f7077d5bd00c6e6619274fa3dd13b94b63f0b5d1 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 11:40:48 +0200 Subject: [PATCH 4/9] test --- .../toolchains/apple/test_xcodedeps.py | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/conans/test/integration/toolchains/apple/test_xcodedeps.py b/conans/test/integration/toolchains/apple/test_xcodedeps.py index 7071ad442b0..b09b5bce172 100644 --- a/conans/test/integration/toolchains/apple/test_xcodedeps.py +++ b/conans/test/integration/toolchains/apple/test_xcodedeps.py @@ -179,4 +179,94 @@ def package_info(self): @pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS") def test_xcodedeps_traits(): client = TestClient() + conanfile_py = textwrap.dedent(""" + from conan import ConanFile + class LibConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + {package_info} + {requirements} + """) + + package_info = """ + def package_info(self): + self.cpp_info.components["cmp1"].includedirs = ["cmp1_includedir"] + self.cpp_info.components["cmp2"].includedirs = ["cmp2_includedir"] + self.cpp_info.components["cmp1"].libdirs = ["cmp1_libdir"] + self.cpp_info.components["cmp2"].libdirs = ["cmp2_libdir"] + self.cpp_info.components["cmp1"].libs = ["cmp1_lib"] + self.cpp_info.components["cmp2"].libs = ["cmp2_lib"] + self.cpp_info.components["cmp1"].system_libs = ["cmp1_system_lib"] + self.cpp_info.components["cmp2"].system_libs = ["cmp2_system_lib"] + self.cpp_info.components["cmp1"].frameworkdirs = ["cmp1_frameworkdir"] + self.cpp_info.components["cmp2"].frameworkdirs = ["cmp2_frameworkdir"] + self.cpp_info.components["cmp1"].frameworks = ["cmp1_framework"] + self.cpp_info.components["cmp2"].frameworks = ["cmp2_framework"] + self.cpp_info.components["cmp1"].defines = ["cmp1_define"] + self.cpp_info.components["cmp2"].defines = ["cmp2_define"] + self.cpp_info.components["cmp1"].cflags = ["cmp1_cflag"] + self.cpp_info.components["cmp2"].cflags = ["cmp2_cflag"] + self.cpp_info.components["cmp1"].cflags = ["cmp1_cflag"] + self.cpp_info.components["cmp2"].cflags = ["cmp2_cflag"] + self.cpp_info.components["cmp1"].cxxflags = ["cmp1_cxxflag"] + self.cpp_info.components["cmp2"].cxxflags = ["cmp2_cxxflag"] + self.cpp_info.components["cmp1"].sharedlinkflags = ["cmp1_sharedlinkflag"] + self.cpp_info.components["cmp2"].sharedlinkflags = ["cmp2_sharedlinkflag"] + self.cpp_info.components["cmp1"].exelinkflags = ["cmp1_exelinkflag"] + self.cpp_info.components["cmp2"].exelinkflags = ["cmp2_exelinkflag"] + """ + + client.save({"lib_a.py": conanfile_py.format(requirements="", package_info=package_info)}) + + client.run("create lib_a.py --name=lib_a --version=1.0") + + requirements = """ + def requirements(self): + self.requires("lib_a/1.0", headers=False) + """ + + client.save({"lib_b.py": conanfile_py.format(requirements=requirements, package_info="")}, + clean_first=True) + + client.run("install lib_b.py -g XcodeDeps") + + comp1_info = client.load("conan_lib_a_cmp1_release_x86_64.xcconfig") + comp2_info = client.load("conan_lib_a_cmp2_release_x86_64.xcconfig") + + assert "cmp1_include" not in comp1_info + assert "cmp2_include" not in comp2_info + + requirements = """ + def requirements(self): + self.requires("lib_a/1.0", libs=False) + """ + + client.save({"lib_b.py": conanfile_py.format(requirements=requirements, package_info="")}, + clean_first=True) + client.run("install lib_b.py -g XcodeDeps") + + comp1_info = client.load("conan_lib_a_cmp1_release_x86_64.xcconfig") + comp2_info = client.load("conan_lib_a_cmp2_release_x86_64.xcconfig") + + assert "cmp1_frameworkdir" not in comp1_info + assert "cmp2_frameworkdir" not in comp2_info + + assert "-lcmp1_lib -lcmp1_system_lib -framework cmp1_framework" not in comp1_info + assert "-lcmp2_lib -lcmp2_system_lib -framework cmp2_framework" not in comp2_info + + requirements = """ + def requirements(self): + self.requires("lib_a/1.0", headers=False, libs=False) + """ + + client.save({"lib_b.py": conanfile_py.format(requirements=requirements, package_info="")}, + clean_first=True) + client.run("install lib_b.py -g XcodeDeps") + + not_existing = ["conan_lib_a_cmp1_release_x86_64.xcconfig", "conan_lib_a_cmp1.xcconfig", + "conan_lib_a_cmp2_release_x86_64.xcconfig", "conan_lib_a_cmp2.xcconfig", + "conan_lib_a.xcconfig"] + + for file in not_existing: + assert not os.path.exists(os.path.join(client.current_folder, file)) + assert '#include "conan_lib_a.xcconfig"' not in client.load("conandeps.xcconfig") From fcd3fa84274bce3893773d344a80c9f04a4c115a Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 13:09:29 +0200 Subject: [PATCH 5/9] fix --- conan/tools/apple/xcodedeps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index 99674bd440f..39d85a0f200 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -282,7 +282,7 @@ def _transitive_components(component): public_deps = [(_format_name(d.ref.name),) * 2 for r, d in dep.dependencies.direct_host.items() if r.visible] required_components = dep.cpp_info.required_components if dep.cpp_info.required_components else public_deps - root_content = self.get_content_for_component(dep_name, dep_name, [dep.cpp_info], + root_content = self.get_content_for_component(require, dep_name, dep_name, [dep.cpp_info], required_components) include_components_names.append((dep_name, dep_name)) result.update(root_content) From 61f9d2cbdfa098aefc18a91fd9fd32e7e364616f Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 13:55:10 +0200 Subject: [PATCH 6/9] minor changes --- conan/tools/apple/xcodedeps.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index 39d85a0f200..be6eeb630ea 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -130,17 +130,6 @@ 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()) - def _process_traits(): - if not require.headers: - fields["include_dirs"] = "" - - if not require.libs: - fields["lib_dirs"] = "" - fields["libs"] = "" - fields["system_libs"] = "" - fields["frameworkdirs"] = "" - fields["frameworks"] = "" - fields = { 'pkg_name': pkg_name, 'comp_name': comp_name, @@ -158,7 +147,15 @@ def _process_traits(): 'condition': _xcconfig_conditional(self._conanfile.settings) } - _process_traits() + if not require.headers: + fields["include_dirs"] = "" + + if not require.libs: + fields["lib_dirs"] = "" + fields["libs"] = "" + fields["system_libs"] = "" + fields["frameworkdirs"] = "" + fields["frameworks"] = "" template = Template(self._conf_xconfig) content_multi = template.render(**fields) From d9f37a49f0d04792fc3509301f4fee8abb5badef Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 12 Jul 2022 14:50:57 +0200 Subject: [PATCH 7/9] simplify test --- .../integration/toolchains/apple/test_xcodedeps.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/conans/test/integration/toolchains/apple/test_xcodedeps.py b/conans/test/integration/toolchains/apple/test_xcodedeps.py index b09b5bce172..ed1ec0cdc57 100644 --- a/conans/test/integration/toolchains/apple/test_xcodedeps.py +++ b/conans/test/integration/toolchains/apple/test_xcodedeps.py @@ -201,18 +201,6 @@ def package_info(self): self.cpp_info.components["cmp2"].frameworkdirs = ["cmp2_frameworkdir"] self.cpp_info.components["cmp1"].frameworks = ["cmp1_framework"] self.cpp_info.components["cmp2"].frameworks = ["cmp2_framework"] - self.cpp_info.components["cmp1"].defines = ["cmp1_define"] - self.cpp_info.components["cmp2"].defines = ["cmp2_define"] - self.cpp_info.components["cmp1"].cflags = ["cmp1_cflag"] - self.cpp_info.components["cmp2"].cflags = ["cmp2_cflag"] - self.cpp_info.components["cmp1"].cflags = ["cmp1_cflag"] - self.cpp_info.components["cmp2"].cflags = ["cmp2_cflag"] - self.cpp_info.components["cmp1"].cxxflags = ["cmp1_cxxflag"] - self.cpp_info.components["cmp2"].cxxflags = ["cmp2_cxxflag"] - self.cpp_info.components["cmp1"].sharedlinkflags = ["cmp1_sharedlinkflag"] - self.cpp_info.components["cmp2"].sharedlinkflags = ["cmp2_sharedlinkflag"] - self.cpp_info.components["cmp1"].exelinkflags = ["cmp1_exelinkflag"] - self.cpp_info.components["cmp2"].exelinkflags = ["cmp2_exelinkflag"] """ client.save({"lib_a.py": conanfile_py.format(requirements="", package_info=package_info)}) From 8e6a3bdcb2c64e7723f9c54c3918315d964e246b Mon Sep 17 00:00:00 2001 From: czoido Date: Wed, 13 Jul 2022 14:17:29 +0200 Subject: [PATCH 8/9] put code back --- conan/tools/apple/xcodedeps.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index be6eeb630ea..45cbe072450 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -157,6 +157,13 @@ def _merged_vars(name): fields["frameworkdirs"] = "" fields["frameworks"] = "" + if not require.libs and not require.headers: + fields["definitions"] = "" + fields["c_compiler_flags"] = "" + fields["cxx_compiler_flags"] = "" + fields["linker_flags"] = "" + fields["exe_flags"] = "" + template = Template(self._conf_xconfig) content_multi = template.render(**fields) return content_multi From f041e90033fca565997d52ae40b8576873403b35 Mon Sep 17 00:00:00 2001 From: czoido Date: Thu, 14 Jul 2022 11:10:20 +0200 Subject: [PATCH 9/9] test run true --- .../toolchains/apple/test_xcodedeps.py | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/conans/test/integration/toolchains/apple/test_xcodedeps.py b/conans/test/integration/toolchains/apple/test_xcodedeps.py index 7619fb1abd5..2113a7dd92c 100644 --- a/conans/test/integration/toolchains/apple/test_xcodedeps.py +++ b/conans/test/integration/toolchains/apple/test_xcodedeps.py @@ -191,6 +191,7 @@ class LibConan(ConanFile): def package_info(self): self.cpp_info.components["cmp1"].includedirs = ["cmp1_includedir"] self.cpp_info.components["cmp2"].includedirs = ["cmp2_includedir"] + self.cpp_info.components["cmp1"].libdirs = ["cmp1_libdir"] self.cpp_info.components["cmp2"].libdirs = ["cmp2_libdir"] self.cpp_info.components["cmp1"].libs = ["cmp1_lib"] @@ -201,7 +202,18 @@ def package_info(self): self.cpp_info.components["cmp2"].frameworkdirs = ["cmp2_frameworkdir"] self.cpp_info.components["cmp1"].frameworks = ["cmp1_framework"] self.cpp_info.components["cmp2"].frameworks = ["cmp2_framework"] - """ + + self.cpp_info.components["cmp1"].defines = ["cmp1_define"] + self.cpp_info.components["cmp2"].defines = ["cmp2_define"] + self.cpp_info.components["cmp1"].cflags = ["cmp1_cflag"] + self.cpp_info.components["cmp2"].cflags = ["cmp2_cflag"] + self.cpp_info.components["cmp1"].cxxflags = ["cmp1_cxxflag"] + self.cpp_info.components["cmp2"].cxxflags = ["cmp2_cxxflag"] + self.cpp_info.components["cmp1"].sharedlinkflags = ["cmp1_sharedlinkflag"] + self.cpp_info.components["cmp2"].sharedlinkflags = ["cmp2_sharedlinkflag"] + self.cpp_info.components["cmp1"].exelinkflags = ["cmp1_exelinkflag"] + self.cpp_info.components["cmp2"].exelinkflags = ["cmp2_exelinkflag"] + """ client.save({"lib_a.py": conanfile_py.format(requirements="", package_info=package_info)}) @@ -259,6 +271,30 @@ def requirements(self): assert '#include "conan_lib_a.xcconfig"' not in client.load("conandeps.xcconfig") + requirements = """ + def requirements(self): + self.requires("lib_a/1.0", headers=False, libs=False, run=True) + """ + + client.save({"lib_b.py": conanfile_py.format(requirements=requirements, package_info="")}, + clean_first=True) + + client.run("install lib_b.py -g XcodeDeps") + + comp1_info = client.load("conan_lib_a_cmp1_release_x86_64.xcconfig") + comp2_info = client.load("conan_lib_a_cmp2_release_x86_64.xcconfig") + + assert "cmp1_define" not in comp1_info + assert "cmp2_define" not in comp2_info + assert "cmp1_cflag" not in comp1_info + assert "cmp2_cflag" not in comp2_info + assert "cmp1_cxxflag" not in comp1_info + assert "cmp2_cxxflag" not in comp2_info + assert "cmp1_sharedlinkflag" not in comp1_info + assert "cmp2_sharedlinkflag" not in comp2_info + assert "cmp1_exelinkflag" not in comp1_info + assert "cmp2_exelinkflag" not in comp2_info + @pytest.mark.skipif(platform.system() != "Darwin", reason="Only for MacOS") def test_xcodedeps_frameworkdirs():