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

Fixes cpp_info.name vs. cpp_info.names issue in pkg_config generator #6223

Merged
merged 2 commits into from Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions conans/client/generators/pkg_config.py
Expand Up @@ -35,12 +35,7 @@ def compiler(self):
def content(self):
ret = {}
for depname, cpp_info in self.deps_build_info.dependencies:
# the name for the pc will be converted to lowercase when cpp_info.name is specified
# but with cpp_info.names["pkg_config"] will be literal
if cpp_info.name and cpp_info.get_name("pkg_config") != cpp_info.name:
name = cpp_info.get_name("pkg_config")
else:
name = cpp_info.name.lower() if cpp_info.name != depname else depname
name = _get_name(depname, cpp_info)
ret["%s.pc" % name] = self.single_pc_file_contents(name, cpp_info)
return ret

Expand Down Expand Up @@ -88,13 +83,24 @@ def single_pc_file_contents(self, name, cpp_info):
["-D%s" % d for d in cpp_info.defines]]))

if cpp_info.public_deps:
pkg_config_names = [self.deps_build_info[public_dep].get_name("pkg_config") for
public_dep in cpp_info.public_deps]
pkg_config_names = []
for public_dep in cpp_info.public_deps:
pkg_config_names.append(_get_name(public_dep, self.deps_build_info[public_dep]))
public_deps = " ".join(pkg_config_names)
lines.append("Requires: %s" % public_deps)
return "\n".join(lines) + "\n"


def _get_name(depname, cpp_info):
# the name for the pc will be converted to lowercase when cpp_info.name is specified
# but with cpp_info.names["pkg_config"] will be literal
if "pkg_config" in cpp_info.names:
name = cpp_info.names["pkg_config"]
else:
name = cpp_info.name.lower() if cpp_info.name != depname else depname
return name


def _concat_if_not_empty(groups):
return " ".join([param for group in groups for param in group if param and param.strip()])

Expand Down
33 changes: 31 additions & 2 deletions conans/test/unittests/client/generators/pkg_config_test.py
Expand Up @@ -85,6 +85,7 @@ def variables_setup_test(self):
def pkg_config_custom_names_test(self):
conanfile = ConanFile(TestBufferConanOutput(), None)
conanfile.initialize(Settings({}), EnvValues())

ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
cpp_info = CppInfo("dummy_root_folder1")
cpp_info.name = "my_pkg"
Expand Down Expand Up @@ -116,6 +117,25 @@ def pkg_config_custom_names_test(self):
cpp_info.cxxflags = ["-cxxflag"]
cpp_info.public_deps = ["MyPkg", "MyPkg1"]
conanfile.deps_cpp_info.update(cpp_info, ref.name)

ref = ConanFileReference.loads("zlib/1.2.11@lasote/stable")
cpp_info = CppInfo("dummy_root_folder_zlib")
cpp_info.name = "ZLIB"
cpp_info.defines = ["MYZLIBDEFINE2"]
cpp_info.version = "1.2.11"
conanfile.deps_cpp_info.update(cpp_info, ref.name)

ref = ConanFileReference.loads("bzip2/0.1@lasote/stables")
cpp_info = CppInfo("dummy_root_folder2")
cpp_info.name = "BZip2"
cpp_info.names["pkg_config"] = "BZip2"
cpp_info.defines = ["MYDEFINE2"]
cpp_info.version = "2.3"
cpp_info.exelinkflags = ["-exelinkflag"]
cpp_info.sharedlinkflags = ["-sharedlinkflag"]
cpp_info.cxxflags = ["-cxxflag"]
cpp_info.public_deps = ["MyPkg", "MyPkg1", "zlib"]
conanfile.deps_cpp_info.update(cpp_info, ref.name)
generator = PkgConfigGenerator(conanfile)
files = generator.content

Expand All @@ -130,7 +150,6 @@ def pkg_config_custom_names_test(self):
Cflags: -I${includedir} -cxxflag -DMYDEFINE2
Requires: my_pkg_custom_name my_pkg1_custom_name
""")

self.assertEqual(files["my_pkg1_custom_name.pc"], """prefix=dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include
Expand All @@ -141,7 +160,6 @@ def pkg_config_custom_names_test(self):
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=21 -DMYDEFINE11
""")

self.assertEqual(files["my_pkg_custom_name.pc"], """prefix=dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include
Expand All @@ -151,6 +169,17 @@ def pkg_config_custom_names_test(self):
Version: 1.3
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=23 -DMYDEFINE1
""")
self.assertEqual(files["BZip2.pc"], """prefix=dummy_root_folder2
libdir=${prefix}/lib
includedir=${prefix}/include

Name: BZip2
Description: Conan package: BZip2
Version: 2.3
Libs: -L${libdir} -sharedlinkflag -exelinkflag
Cflags: -I${includedir} -cxxflag -DMYDEFINE2
Requires: my_pkg_custom_name my_pkg1_custom_name zlib
""")

def apple_frameworks_test(self):
Expand Down