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

Add pybind11 to the whitelist for KB-h016 #145

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ def test(out):
"be located using generators and the declared `cpp_info` information")
out.error("Found files: {}".format("; ".join(bad_files)))


@run_test("KB-H016", output)
def test(out):
if conanfile.name in ["cmake", "msys2", "strawberryperl", "pybind11", "ignition-cmake",
Expand Down Expand Up @@ -1034,6 +1035,33 @@ def post_package_info(output, conanfile, reference, **kwargs):
if not hasattr(this, "reference") or str(reference) != this.reference:
return

@run_test("KB-H016", output)
def test(out):
if conanfile.name in ["cmake", "msys2", "strawberryperl"]:
return
bad_files = _get_files_following_patterns(conanfile.package_folder, ["Find*.cmake",
"*Config.cmake",
"*-config.cmake"])

target = "find{}.cmake".format(conanfile.name.lower())
try:
target = "find{}.cmake".format(conanfile.cpp_info.names["cmake_find_package"].lower())
except:
pass

for bad_file in bad_files:
bad_file_name = os.path.basename(bad_file).lower()
if bad_file_name.startswith("find") and bad_file_name.endswith(
".cmake") and bad_file_name != target:
bad_files.remove(bad_file)
break

if bad_files:
out.error("The conan-center repository doesn't allow the packages to contain CMake "
"find modules or config files. The packages have to "
"be located using generators and the declared `cpp_info` information")
out.error("Found files:\n{}".format("\n".join(bad_files)))

@run_test("KB-H019", output)
def test(out):
if conanfile.name in ["android-ndk", "cmake", "msys2", "strawberryperl"]:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_hooks/conan-center/test_cmake_bad_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def test_find_and_config_files(self):
def test_find_and_find_files(self):
tools.save('conanfile.py', content=self.conan_file.format("", "FindXXX.cmake"))
output = self.conan(['create', '.', 'name/version@user/channel'])

self.assertNotIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)]", output)

self.assertIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files: ./FindXXX.cmake",
output)

Expand Down Expand Up @@ -126,3 +129,24 @@ def package_info(self):
tools.save('conanfile.py', content=conanfile)
output = self.conan(['create', '.', 'name/version@user/channel'])
self.assertNotIn("ERROR: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output)

def test_find_package_names(self):
tools.save('conanfile.py', content=self.conan_file.format("lib/foo/cmake", "FindFoo.cmake"))
output = self.conan(['create', '.', 'foo/version@user/channel'])
self.assertIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files:\n./lib/foo/cmake/FindFoo.cmake",
output)

conan_file3 = textwrap.dedent("""\
import os
from conans import ConanFile, tools
class AConan(ConanFile):
def package(self):
tools.save(os.path.join(self.package_folder, "lib", "foo", "cmake", "FindBar.cmake"), "foo")

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "Bar"
""")
tools.save('conanfile.py', conan_file3)
output = self.conan(['create', '.', 'foo/version@user/channel'])
self.assertIn("ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files:\n./lib/foo/cmake/FindBar.cmake",
output)