From 6b1fcd9fb26f5532228a3d1d0282efd13e4cb927 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sun, 22 Jan 2023 18:09:44 +0100 Subject: [PATCH 1/4] add KB-H078 in conan-center to test that system libs are all lowercase if host OS is Windows --- hooks/conan-center.py | 24 ++++ .../test_windows_lowercase_system_libs.py | 105 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py diff --git a/hooks/conan-center.py b/hooks/conan-center.py index eb593f92..0ba8fdb2 100644 --- a/hooks/conan-center.py +++ b/hooks/conan-center.py @@ -91,6 +91,7 @@ "KB-H075": "REQUIREMENT OVERRIDE PARAMETER", "KB-H076": "EITHER STATIC OR SHARED OF EACH LIB", "KB-H077": "APPLE RELOCATABLE SHARED LIBS", + "KB-H078": "WINDOWS LOWERCASE SYSTEM LIBS", } @@ -1335,6 +1336,29 @@ def _test_component(component): for c in conanfile.cpp_info.components: _test_component(conanfile.cpp_info.components[c]) + @run_test("KB-H078", output) + def test(out): + if conanfile.settings.get_safe("os") != "Windows": + return + + uppercase_system_libs = [] + + def _collect_uppercase_system_libs(component): + uppercase_system_libs.extend([lib for lib in component.system_libs if lib != lib.lower()]) + + if not conanfile.cpp_info.components: + _collect_uppercase_system_libs(conanfile.cpp_info) + for c in conanfile.cpp_info.components: + _collect_uppercase_system_libs(conanfile.cpp_info.components[c]) + + if uppercase_system_libs: + uppercase_system_libs.sort() + out.error( + "All libs listed in system_libs should be lowercase if host OS is " + "Windows to support both native Windows build and cross-build from Linux. " + f"Found system libs with uppercase characters: {', '.join(uppercase_system_libs)}" + ) + def _get_files_following_patterns(folder, patterns): ret = [] diff --git a/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py b/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py new file mode 100644 index 00000000..d56287d2 --- /dev/null +++ b/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py @@ -0,0 +1,105 @@ +import os +import platform +import textwrap + +from parameterized import parameterized + +from conans import tools + +from tests.utils.test_cases.conan_client import ConanClientTestCase + + +class TestPackageInfoWindowsLowercaseSystemLibs(ConanClientTestCase): + + def _get_environ(self, **kwargs): + kwargs = super(TestPackageInfoWindowsLowercaseSystemLibs, self)._get_environ(**kwargs) + kwargs.update({ + "CONAN_HOOKS": os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, + os.pardir, "hooks", "conan-center") + }) + return kwargs + + @staticmethod + def _conanfile_test_global_cpp_info(system_lib=None): + system_libs = "[{}]".format(f"\"{system_lib}\"" if system_lib else "") + return textwrap.dedent(f"""\ + from conan import ConanFile + import os + + class AConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + options = {{"shared": [True, False], "status": [True, False]}} + default_options = {{"shared": False, "status": True}} + + def package_info(self): + if self.settings.os == "Windows": + self.cpp_info.system_libs = {system_libs} + else: + self.cpp_info.system_libs = ["FOO"] + """) + + @staticmethod + def _conanfile_test_components_cpp_info(system_lib_a=None, system_lib_b=None): + system_libs_a = "[{}]".format(f"\"{system_lib_a}\"" if system_lib_a else "") + system_libs_b = "[{}]".format(f"\"{system_lib_b}\"" if system_lib_b else "") + return textwrap.dedent(f"""\ + from conan import ConanFile + import os + + class AConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + options = {{"shared": [True, False], "status": [True, False]}} + default_options = {{"shared": False, "status": True}} + + def package_info(self): + if self.settings.os == "Windows": + self.cpp_info.components["a"].system_libs = {system_libs_a} + self.cpp_info.components["b"].system_libs = {system_libs_b} + else: + self.cpp_info.components["a"].system_libs = ["FOO"] + self.cpp_info.components["b"].system_libs = ["BAR"] + """) + + @parameterized.expand([(None, ), ("ws2_32", ), ("Ws2_32", )]) + def test_global_cpp_info(self, system_lib): + tools.save("conanfile.py", content=self._conanfile_test_global_cpp_info(system_lib)) + output = self.conan(["create", ".", "name/version@user/test"]) + if platform.system() != "Windows" or not system_lib or system_lib == system_lib.lower(): + self.assertIn("[WINDOWS LOWERCASE SYSTEM LIBS (KB-H078)] OK", output) + else: + error_message = ( + "ERROR: [WINDOWS LOWERCASE SYSTEM LIBS (KB-H078)] " + "All libs listed in system_libs should be lowercase if host OS is " + "Windows to support both native Windows build and cross-build from Linux. " + f"Found system libs with uppercase characters: {system_lib}" + ) + self.assertIn(error_message, output) + + @parameterized.expand([ + (None, None), + ("ws2_32", "ole32"), + ("Ws2_32", "ole32"), + ("ws2_32", "Ole32"), + ("Ws2_32", "Ole32"), + ]) + def test_components_cpp_info(self, system_lib_a, system_lib_b): + tools.save("conanfile.py", content=self._conanfile_test_components_cpp_info(system_lib_a, system_lib_b)) + output = self.conan(["create", ".", "name/version@user/test"]) + if platform.system() != "Windows" or \ + ((not system_lib_a or system_lib_a == system_lib_a.lower()) and \ + (not system_lib_b or system_lib_b == system_lib_b.lower())): + self.assertIn("[WINDOWS LOWERCASE SYSTEM LIBS (KB-H078)] OK", output) + else: + uppercase_libs = [] + if system_lib_a and system_lib_a != system_lib_a.lower(): + uppercase_libs.append(system_lib_a) + if system_lib_b and system_lib_b != system_lib_b.lower(): + uppercase_libs.append(system_lib_b) + uppercase_libs.sort() + error_message = ( + "ERROR: [WINDOWS LOWERCASE SYSTEM LIBS (KB-H078)] " + "All libs listed in system_libs should be lowercase if host OS is " + "Windows to support both native Windows build and cross-build from Linux. " + f"Found system libs with uppercase characters: {', '.join(uppercase_libs)}" + ) + self.assertIn(error_message, output) From 1f2de2193f1ce95c1699a51b91c6536636ca3fd6 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:43:30 +0100 Subject: [PATCH 2/4] use islower() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rubén Rincón Blanco --- hooks/conan-center.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/conan-center.py b/hooks/conan-center.py index 0ba8fdb2..1d61e497 100644 --- a/hooks/conan-center.py +++ b/hooks/conan-center.py @@ -1344,7 +1344,7 @@ def test(out): uppercase_system_libs = [] def _collect_uppercase_system_libs(component): - uppercase_system_libs.extend([lib for lib in component.system_libs if lib != lib.lower()]) + uppercase_system_libs.extend([lib for lib in component.system_libs if not lib.islower())]) if not conanfile.cpp_info.components: _collect_uppercase_system_libs(conanfile.cpp_info) From 7a6067cbaeb46ee8808398ee99431fe7b4d5b529 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:46:52 +0100 Subject: [PATCH 3/4] use islower() --- .../conan-center/test_windows_lowercase_system_libs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py b/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py index d56287d2..ffe0897f 100644 --- a/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py +++ b/tests/test_hooks/conan-center/test_windows_lowercase_system_libs.py @@ -64,7 +64,7 @@ def package_info(self): def test_global_cpp_info(self, system_lib): tools.save("conanfile.py", content=self._conanfile_test_global_cpp_info(system_lib)) output = self.conan(["create", ".", "name/version@user/test"]) - if platform.system() != "Windows" or not system_lib or system_lib == system_lib.lower(): + if platform.system() != "Windows" or not system_lib or system_lib.islower(): self.assertIn("[WINDOWS LOWERCASE SYSTEM LIBS (KB-H078)] OK", output) else: error_message = ( @@ -86,14 +86,14 @@ def test_components_cpp_info(self, system_lib_a, system_lib_b): tools.save("conanfile.py", content=self._conanfile_test_components_cpp_info(system_lib_a, system_lib_b)) output = self.conan(["create", ".", "name/version@user/test"]) if platform.system() != "Windows" or \ - ((not system_lib_a or system_lib_a == system_lib_a.lower()) and \ - (not system_lib_b or system_lib_b == system_lib_b.lower())): + ((not system_lib_a or system_lib_a.islower()) and \ + (not system_lib_b or system_lib_b.islower())): self.assertIn("[WINDOWS LOWERCASE SYSTEM LIBS (KB-H078)] OK", output) else: uppercase_libs = [] - if system_lib_a and system_lib_a != system_lib_a.lower(): + if system_lib_a and not system_lib_a.islower(): uppercase_libs.append(system_lib_a) - if system_lib_b and system_lib_b != system_lib_b.lower(): + if system_lib_b and not system_lib_b.islower(): uppercase_libs.append(system_lib_b) uppercase_libs.sort() error_message = ( From 1309eb49956d6be32e307abd20cbce3d3bbbc4de Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:48:24 +0100 Subject: [PATCH 4/4] typo --- hooks/conan-center.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/conan-center.py b/hooks/conan-center.py index 1d61e497..d1a51563 100644 --- a/hooks/conan-center.py +++ b/hooks/conan-center.py @@ -1344,7 +1344,7 @@ def test(out): uppercase_system_libs = [] def _collect_uppercase_system_libs(component): - uppercase_system_libs.extend([lib for lib in component.system_libs if not lib.islower())]) + uppercase_system_libs.extend([lib for lib in component.system_libs if not lib.islower()]) if not conanfile.cpp_info.components: _collect_uppercase_system_libs(conanfile.cpp_info)