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

[conan-center] KB-H071 Validate relocable shared libraries #403

Draft
wants to merge 3 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
14 changes: 14 additions & 0 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"KB-H065": "NO REQUIRED_CONAN_VERSION",
"KB-H066": "SHORT_PATHS USAGE",
"KB-H068": "TEST_TYPE MANAGEMENT",
"KB-H071": "RELOCATABLE SHARED LIBS",
}


Expand Down Expand Up @@ -794,6 +795,19 @@ def test(out):
except Exception as e:
out.warn("Invalid conanfile: {}".format(e))

@run_test("KB-H071", output)
def test(out):
cmakefile_path = os.path.join(os.path.dirname(conanfile_path), "CMakeLists.txt")
if os.path.isfile(cmakefile_path):
cmakefile_content = tools.load(cmakefile_path)
if "conan_basic_setup(keep_rpaths)" not in cmakefile_content.lower():
out.warn("Did not find 'conan_basic_setup(KEEP_RPATHS)' in CMakeLists.txt. Update your CMakeLists.txt.")
if "CMAKE_POLICY_DEFAULT_CMP0042" not in conanfile_content:
match = re.search(r"cmake_minimum_required\s?\(VERSION (\d?\.?\d?\.?\d+)\)", cmakefile_content, re.I)
if match and tools.Version(match.group(1)) < "3.0":
out.warn("CMake policy CMP0042 is not enabled. Use 'cmake_minimum_required(VERSION 3.0)' or "
"enable 'CMAKE_POLICY_DEFAULT_CMP0042' definition.")


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

from conans import tools

from tests.utils.test_cases.conan_client import ConanClientTestCase


class TestRelocatableLibraries(ConanClientTestCase):
conanfile = textwrap.dedent("""\
from conans import ConanFile

class AConan(ConanFile):
exports_sources = "CMakeLists.txt"
generators = "cmake"
""")
cmakefile = textwrap.dedent("""\
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)
include(conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)
add_subdirectory(source_subfolder)
""")

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

def test_with_keep_rpaths(self):
tools.save('conanfile.py', content=self.conanfile)
tools.save('CMakeLists.txt', content=self.cmakefile)
output = self.conan(['export', '.', 'name/version@user/test'])
self.assertIn("[RELOCATABLE SHARED LIBS (KB-H071)] OK", output)
self.assertNotIn("WARN: [RELOCATABLE SHARED LIBS (KB-H071)]", output)

def test_without_keep_rpaths(self):
tools.save('conanfile.py', content=self.conanfile)
tools.save('CMakeLists.txt', content=self.cmakefile.replace("KEEP_RPATHS", ""))
output = self.conan(['export', '.', 'name/version@user/test'])
self.assertIn("[RELOCATABLE SHARED LIBS (KB-H071)] OK", output)
self.assertIn("WARN: [RELOCATABLE SHARED LIBS (KB-H071)] Did not find "
"'conan_basic_setup(KEEP_RPATHS)' in CMakeLists.txt. "
"Update your CMakeLists.txt.", output)

def test_cmp0042_without_cmake_version(self):
tools.save('conanfile.py', content=self.conanfile)
tools.save('CMakeLists.txt', content=self.cmakefile.replace("3.1", "2.8"))
output = self.conan(['export', '.', 'name/version@user/test'])
self.assertIn("[RELOCATABLE SHARED LIBS (KB-H071)] OK", output)
self.assertIn("WARN: [RELOCATABLE SHARED LIBS (KB-H071)] CMake policy CMP0042 is not enabled."
" Use 'cmake_minimum_required(VERSION 3.0)' or "
"enable 'CMAKE_POLICY_DEFAULT_CMP0042' definition.", output)

def test_cmp0042_with_cmake_policy_def(self):
conanfile = textwrap.dedent("""\
from conans import ConanFile, CMake

class AConan(ConanFile):
exports_sources = "CMakeLists.txt"
generators = "cmake"
def build(self):
cmake = CMake(self)
cmake.definitions['CMAKE_POLICY_DEFAULT_CMP0042'] = 'YES'
cmake.configure()
""")
tools.save('conanfile.py', content=conanfile)
tools.save('CMakeLists.txt', content=self.cmakefile.replace("3.1", "2.8"))
output = self.conan(['export', '.', 'name/version@user/test'])
self.assertIn("[RELOCATABLE SHARED LIBS (KB-H071)] OK", output)
self.assertNotIn("WARN: [RELOCATABLE SHARED LIBS (KB-H071)]", output)