Skip to content

Commit

Permalink
Added new hook for deprecated props
Browse files Browse the repository at this point in the history
  • Loading branch information
franramirez688 committed Nov 12, 2021
1 parent af7cd33 commit 663ca00
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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)

0 comments on commit 663ca00

Please sign in to comment.