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

Deprecated names, filenames and build_modules #369

Closed
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
8 changes: 8 additions & 0 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"KB-H061": "NO BUILD SYSTEM FUNCTIONS",
"KB-H062": "TOOLS CROSS BUILDING",
"KB-H064": "INVALID TOPICS",
"KB-H065": "DEPRECATED NAMES, FILENAMES AND BUILD_MODULES",
}


Expand Down Expand Up @@ -724,6 +725,13 @@ def test(out):
out.warn("The topic '{}' is invalid; even names and acronyms should be formatted "
"entirely in lowercase.".format(topic))

@run_test("KB-H065", output)
def test(out):
pattern = re.compile(r"self\.cpp_info.*\.(names\[|filenames\[|build_modules)")
if pattern.search(conanfile_content):
out.error("Using 'names', 'filenames' and 'build_modules' is deprecated from Conan 1.42. "
"Use 'set_property' and 'get_property' methods of the cpp_info object instead.")


@raise_if_error_output
def post_export(output, conanfile, conanfile_path, reference, **kwargs):
Expand Down
52 changes: 52 additions & 0 deletions tests/test_hooks/conan-center/test_deprecated_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import textwrap

import pytest
from conans import tools
from parameterized import parameterized


from tests.utils.test_cases.conan_client import ConanClientTestCase


class TestDeprecatedProperties(ConanClientTestCase):
conanfile = textwrap.dedent("""\
from conans import ConanFile
class AConan(ConanFile):
def package_info(self):
{}
""")

def _get_environ(self, **kwargs):
kwargs = super(TestDeprecatedProperties, self)._get_environ(**kwargs)
kwargs.update({'CONAN_HOOKS': os.path.join(os.path.dirname(__file__), '..', '..', '..',
'hooks', 'conan-center')})
return kwargs

@parameterized.expand([
'self.cpp_info.names["cmake_find_package_multi"] = "myname"',
'self.cpp_info.components["mycomp"].names["cmake_find_package_multi"] = "myname"',
'self.cpp_info.filenames["cmake_find_package_multi"] = "myname"',
'self.cpp_info.components["mycomp"].filenames["cmake_find_package_multi"] = "myname"',
'self.cpp_info.build_modules["cmake_find_package_multi"] = "myname"',
'self.cpp_info.build_modules = ["/my/path/m.cmake", "my/other/path/m2.cmake"]',
])
def test_deprecated_properties(self, pkg_info_line):
tools.save('conanfile.py', content=self.conanfile.format(pkg_info_line))
output = self.conan(['export', '.', 'name/version@user/channel'])
self.assertIn("[DEPRECATED NAMES, FILENAMES AND BUILD_MODULES (KB-H065)] Using 'names', "
"'filenames' and 'build_modules' is deprecated from Conan 1.42. "
"Use 'set_property' and 'get_property' methods of the cpp_info object instead.", output)

@parameterized.expand([
'self.cpp_info.set_property("cmake_file_name", "MyFileName")',
'self.cpp_info.set_property("cmake_target_name", "MyTargetName")',
'self.cpp_info.components["mycomp"].set_property("cmake_target_name", "mycomponent-name")',
'self.cpp_info.components["mycomp"].set_property("cmake_build_modules", ["lib/m2.cmake", "lib/m3.cmake"])',
'self.cpp_info.components["mycomp"].set_property("pkg_config_name", "mypkg-config-name")',
'self.cpp_info.components["mycomp"].set_property("custom_name", "mycomponent-name", "custom_generator")',
])
def test_valid_properties(self, pkg_info_line):
tools.save('conanfile.py', content=self.conanfile.format(pkg_info_line))
output = self.conan(['export', '.', 'name/version@user/channel'])
self.assertIn("[DEPRECATED NAMES, FILENAMES AND BUILD_MODULES (KB-H065)] OK", output)