diff --git a/hooks/conan-center.py b/hooks/conan-center.py index 2d8a3f47..e0c4b7d4 100644 --- a/hooks/conan-center.py +++ b/hooks/conan-center.py @@ -70,6 +70,7 @@ "KB-H064": "INVALID TOPICS", "KB-H065": "NO REQUIRED_CONAN_VERSION", "KB-H066": "SHORT_PATHS USAGE", + "KB-H067": "OLD TARGETS", } @@ -763,6 +764,26 @@ def _find_required_conan_version(conanfile_content): "Please add `required_conan_version >= \"{0}\"`" "".format(str(required_version))) + @run_test("KB-H065", output) + def test(out): + + def check_old_integrations(cmakelists_path): + cmake_content = tools.load(cmakelists_path) + if "CONAN_PKG::" in cmake_content: + out.error("The usage of CONAN_PKG:: targets in {} is deprecated and will not be supported " + "in future (conan 2.0). Replace these targets with ones provided by the " + "cmake_find_package_multi generator.".format(os.path.relpath(cmakelists_path))) + if "CONAN_LIBS" in cmake_content: + out.error("The usage of CONAN_LIBS in {} is deprecated and will not be supported " + "in future (conan 2.0). Replace these variables with targets provided by the " + "cmake_find_package_multi generator.".format(os.path.relpath(cmakelists_path))) + + dir_path = os.path.dirname(conanfile_path) + for cmake_path in [os.path.join(dir_path, "CMakeLists.txt"), + os.path.join(dir_path, "test_package", "CMakeLists.txt")]: + if os.path.exists(cmake_path): + check_old_integrations(cmake_path) + @raise_if_error_output def post_export(output, conanfile, conanfile_path, reference, **kwargs): diff --git a/tests/test_hooks/conan-center/test_conan-center.py b/tests/test_hooks/conan-center/test_conan-center.py index 8f8e7cc2..88b4af15 100644 --- a/tests/test_hooks/conan-center/test_conan-center.py +++ b/tests/test_hooks/conan-center/test_conan-center.py @@ -1118,6 +1118,37 @@ def source(self): output = self.conan(['export', 'conanfile.py', 'name/version@user/test']) self.assertIn("WARN: [TOOLS CROSS BUILDING (KB-H062)] The 'tools.cross_building(self.settings)' syntax in conanfile.py",output) + def test_old_targets(self): + conanfile = self.conanfile_base.format(placeholder="exports_sources = \"CMakeLists.txt\"") + + cmake = textwrap.dedent(""" + cmake_minimum_required(VERSION 2.8.11) + project(test) + """) + tools.save('conanfile.py', content=conanfile) + tools.save('CMakeLists.txt', content=cmake) + output = self.conan(['create', '.', 'name/version@user/test']) + self.assertIn("[OLD TARGETS (KB-H065)] OK", output) + + cmake = textwrap.dedent(""" + cmake_minimum_required(VERSION 2.8.11) + project(test) + message(STATUS "CONAN_LIBS ${CONAN_LIBS}) + """) + tools.save('CMakeLists.txt', content=cmake) + output = self.conan(['create', '.', 'name/version@user/test']) + self.assertIn("ERROR: [OLD TARGETS (KB-H065)]", output) + + cmake = textwrap.dedent(""" + cmake_minimum_required(VERSION 2.8.11) + project(test) + if(TARGET CONAN_PKG::boost) + endif() + """) + tools.save('CMakeLists.txt', content=cmake) + output = self.conan(['create', '.', 'name/version@user/test']) + self.assertIn("ERROR: [OLD TARGETS (KB-H065)]", output) + def test_strip_root_required_conan_version(self): # no required_conan_version conanfile = textwrap.dedent("""\