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

- forbid CONAN_PKG and CONAN_LIBS #355

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"KB-H064": "INVALID TOPICS",
"KB-H065": "NO REQUIRED_CONAN_VERSION",
"KB-H066": "SHORT_PATHS USAGE",
"KB-H067": "OLD TARGETS",
}


Expand Down Expand Up @@ -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):
Expand Down
31 changes: 31 additions & 0 deletions tests/test_hooks/conan-center/test_conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("""\
Expand Down