diff --git a/hooks/conan-center.py b/hooks/conan-center.py index b0b7b52f..42ef11a6 100644 --- a/hooks/conan-center.py +++ b/hooks/conan-center.py @@ -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", @@ -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"]: diff --git a/tests/test_hooks/conan-center/test_cmake_bad_files.py b/tests/test_hooks/conan-center/test_cmake_bad_files.py index 5c323eed..e77ae21c 100644 --- a/tests/test_hooks/conan-center/test_cmake_bad_files.py +++ b/tests/test_hooks/conan-center/test_cmake_bad_files.py @@ -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) @@ -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) \ No newline at end of file