From 25e51336e27e520f2a4c36b4fdf339a5aac2f54d Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 16 Oct 2023 11:12:16 +0300 Subject: [PATCH 01/14] pcre2: fix invalid pcre2-config output for static libs --- recipes/pcre2/all/conanfile.py | 7 ++++- recipes/pcre2/all/test_package/conanfile.py | 34 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/recipes/pcre2/all/conanfile.py b/recipes/pcre2/all/conanfile.py index 14600c9abe85c..089bd5d7016a5 100644 --- a/recipes/pcre2/all/conanfile.py +++ b/recipes/pcre2/all/conanfile.py @@ -118,6 +118,11 @@ def _patch_sources(self): replace_in_file(self, cmakelists, "RUNTIME DESTINATION bin", "RUNTIME DESTINATION bin BUNDLE DESTINATION bin") + # pcre2-config does not correctly include '-static' in static library names + if Version(self.version) >= "10.38" and is_msvc(self) and not self.options.shared: + replace_in_file(self, cmakelists, + "CONFIGURE_FILE(libpcre2-posix.pc.in", + 'string(PREPEND LIB_POSTFIX "-static")\nCONFIGURE_FILE(libpcre2-posix.pc.in') def build(self): self._patch_sources() @@ -166,7 +171,7 @@ def package_info(self): if self.options.build_pcre2grep: bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bin_path)) + self.output.info(f"Appending PATH environment variable: {bin_path}") self.env_info.PATH.append(bin_path) # FIXME: This is a workaround to avoid ConanException. zlib and bzip2 # are optional requirements of pcre2grep executable, not of any pcre2 lib. diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 0a6bc68712d90..d0bc51cb53f7a 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -1,7 +1,10 @@ from conan import ConanFile from conan.tools.build import can_run +from conan.tools.files import save, load from conan.tools.cmake import CMake, cmake_layout +from conan.tools.scm import Version import os +from io import StringIO class TestPackageConan(ConanFile): @@ -9,12 +12,29 @@ class TestPackageConan(ConanFile): generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" test_type = "explicit" + @property + def _settings_build(self): + return getattr(self, "settings_build", self.settings) + def layout(self): cmake_layout(self) def requirements(self): self.requires(self.tested_reference_str) + def build_requirements(self): + self.tool_requires(self.tested_reference_str) + if self._settings_build.os == "Windows": + self.win_bash = True + if not self.conf.get("tools.microsoft.bash:path", check_type=str): + self.tool_requires("msys2/cci.latest") + + def generate(self): + pcre2_cpp_info = self.dependencies["pcre2"].cpp_info.aggregated_components() + save(self, os.path.join(self.build_folder, "bindir"), pcre2_cpp_info.bindir) + save(self, os.path.join(self.build_folder, "libdir"), pcre2_cpp_info.libdir) + save(self, os.path.join(self.build_folder, "libs"), " ".join(pcre2_cpp_info.libs)) + def build(self): cmake = CMake(self) cmake.configure() @@ -22,5 +42,17 @@ def build(self): def test(self): if can_run(self): - bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") + + if Version(self.tested_reference_str.split("/")[1]) >= "10.36": + bindir = load(self, os.path.join(self.build_folder, "bindir")) + libdir = load(self, os.path.join(self.build_folder, "libdir")).replace("\\", "/") + libs = load(self, os.path.join(self.build_folder, "libs")).split(" ") + output = StringIO() + self.run(f"bash {bindir}/pcre2-config --libs8", output) + conf = output.getvalue().strip().split(" ") + assert f"-L{libdir}" in conf, f"Expected '-L{libdir}' not set by pcre2-config: {conf}" + for param in conf: + if param.startswith("-l"): + assert param[2:] in libs, f"Invalid library target '{param[2:]}' output by pcre2-config. Not found in {libs}." From e4265c39867e2b10e92952aebb7fac098c21332c Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 16 Oct 2023 13:55:04 +0300 Subject: [PATCH 02/14] pcre2: ignore noise from self.run() --- recipes/pcre2/all/test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index d0bc51cb53f7a..b90d2fd41cd1e 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -51,7 +51,7 @@ def test(self): libs = load(self, os.path.join(self.build_folder, "libs")).split(" ") output = StringIO() self.run(f"bash {bindir}/pcre2-config --libs8", output) - conf = output.getvalue().strip().split(" ") + conf = next(l for l in output.getvalue().splitlines() if l.lower().startswith("-l")).strip().split(" ") assert f"-L{libdir}" in conf, f"Expected '-L{libdir}' not set by pcre2-config: {conf}" for param in conf: if param.startswith("-l"): From 48cfbd4689b2daba3ff71e3bb1d619adc63d2a51 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 17 Oct 2023 11:05:30 +0300 Subject: [PATCH 03/14] pcre2: make pcre2-config test a bit more robust --- recipes/pcre2/all/test_package/conanfile.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index b90d2fd41cd1e..7ff46545f66d9 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -32,7 +32,6 @@ def build_requirements(self): def generate(self): pcre2_cpp_info = self.dependencies["pcre2"].cpp_info.aggregated_components() save(self, os.path.join(self.build_folder, "bindir"), pcre2_cpp_info.bindir) - save(self, os.path.join(self.build_folder, "libdir"), pcre2_cpp_info.libdir) save(self, os.path.join(self.build_folder, "libs"), " ".join(pcre2_cpp_info.libs)) def build(self): @@ -45,14 +44,12 @@ def test(self): bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") - if Version(self.tested_reference_str.split("/")[1]) >= "10.36": + if Version(self.tested_reference_str.split("/")[1]) >= "10.38": bindir = load(self, os.path.join(self.build_folder, "bindir")) - libdir = load(self, os.path.join(self.build_folder, "libdir")).replace("\\", "/") libs = load(self, os.path.join(self.build_folder, "libs")).split(" ") output = StringIO() self.run(f"bash {bindir}/pcre2-config --libs8", output) conf = next(l for l in output.getvalue().splitlines() if l.lower().startswith("-l")).strip().split(" ") - assert f"-L{libdir}" in conf, f"Expected '-L{libdir}' not set by pcre2-config: {conf}" for param in conf: if param.startswith("-l"): assert param[2:] in libs, f"Invalid library target '{param[2:]}' output by pcre2-config. Not found in {libs}." From 0718c174364d38bf5f7c9dd5983a95dffc204049 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 23 Oct 2023 15:26:38 +0300 Subject: [PATCH 04/14] pcre2: handle debug postfix correctly --- recipes/pcre2/all/conanfile.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/recipes/pcre2/all/conanfile.py b/recipes/pcre2/all/conanfile.py index 089bd5d7016a5..caab27203574b 100644 --- a/recipes/pcre2/all/conanfile.py +++ b/recipes/pcre2/all/conanfile.py @@ -119,10 +119,13 @@ def _patch_sources(self): "RUNTIME DESTINATION bin", "RUNTIME DESTINATION bin BUNDLE DESTINATION bin") # pcre2-config does not correctly include '-static' in static library names - if Version(self.version) >= "10.38" and is_msvc(self) and not self.options.shared: + if Version(self.version) >= "10.38" and is_msvc(self): + postfix = "-static" if not self.options.shared else "" + if self.settings.build_type == "Debug": + postfix += "d" replace_in_file(self, cmakelists, - "CONFIGURE_FILE(libpcre2-posix.pc.in", - 'string(PREPEND LIB_POSTFIX "-static")\nCONFIGURE_FILE(libpcre2-posix.pc.in') + "CONFIGURE_FILE(pcre2-config.in", + f'set(LIB_POSTFIX "{postfix}")\nCONFIGURE_FILE(pcre2-config.in') def build(self): self._patch_sources() From b793e463aefd510231a3484114433c034a489082 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 18 Nov 2023 09:21:52 +0200 Subject: [PATCH 05/14] pcre2: no need for win_bash = True --- recipes/pcre2/all/test_package/conanfile.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 7ff46545f66d9..5e049ccb96d97 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -25,11 +25,11 @@ def requirements(self): def build_requirements(self): self.tool_requires(self.tested_reference_str) if self._settings_build.os == "Windows": - self.win_bash = True if not self.conf.get("tools.microsoft.bash:path", check_type=str): self.tool_requires("msys2/cci.latest") def generate(self): + # Workaround for Conan v1: store dependency info for later use in test() pcre2_cpp_info = self.dependencies["pcre2"].cpp_info.aggregated_components() save(self, os.path.join(self.build_folder, "bindir"), pcre2_cpp_info.bindir) save(self, os.path.join(self.build_folder, "libs"), " ".join(pcre2_cpp_info.libs)) @@ -44,12 +44,14 @@ def test(self): bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") + # Check that pcre2-config outputs correct link flags if Version(self.tested_reference_str.split("/")[1]) >= "10.38": bindir = load(self, os.path.join(self.build_folder, "bindir")) libs = load(self, os.path.join(self.build_folder, "libs")).split(" ") output = StringIO() self.run(f"bash {bindir}/pcre2-config --libs8", output) - conf = next(l for l in output.getvalue().splitlines() if l.lower().startswith("-l")).strip().split(" ") - for param in conf: - if param.startswith("-l"): - assert param[2:] in libs, f"Invalid library target '{param[2:]}' output by pcre2-config. Not found in {libs}." + ldflags_str = next(l for l in output.getvalue().splitlines() if l.lower().startswith("-l")).strip() + ldflags = ldflags_str.split() + for flag in ldflags: + if flag.startswith("-l"): + assert flag[2:] in libs, f"Invalid library target '{flag[2:]}' output by pcre2-config. Not found in {libs}." From 33c866e98f0b3f64daa9c4dd3159ab31a4160ff7 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sat, 18 Nov 2023 18:31:31 +0200 Subject: [PATCH 06/14] pcre2: drop self.tool_requires(self.tested_reference_str) --- recipes/pcre2/all/test_package/conanfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 5e049ccb96d97..e659e57578585 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -23,7 +23,6 @@ def requirements(self): self.requires(self.tested_reference_str) def build_requirements(self): - self.tool_requires(self.tested_reference_str) if self._settings_build.os == "Windows": if not self.conf.get("tools.microsoft.bash:path", check_type=str): self.tool_requires("msys2/cci.latest") From bcd3701c7943a493f6f6292413c5a7650310d480 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 17:00:16 +0200 Subject: [PATCH 07/14] Update recipes/pcre2/all/test_package/conanfile.py --- recipes/pcre2/all/test_package/conanfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index e659e57578585..71ed1e780e7cf 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -1,6 +1,5 @@ from conan import ConanFile from conan.tools.build import can_run -from conan.tools.files import save, load from conan.tools.cmake import CMake, cmake_layout from conan.tools.scm import Version import os From dcd058e996c9dd89c83a63cf9bf8c1702f141b18 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 17:00:24 +0200 Subject: [PATCH 08/14] Update recipes/pcre2/all/test_package/conanfile.py --- recipes/pcre2/all/test_package/conanfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 71ed1e780e7cf..7fa64e3cb5532 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -1,7 +1,6 @@ from conan import ConanFile from conan.tools.build import can_run from conan.tools.cmake import CMake, cmake_layout -from conan.tools.scm import Version import os from io import StringIO From f517621b78167b7a54c4eb1cfda1fbcdd1c044cc Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 17:00:32 +0200 Subject: [PATCH 09/14] Update recipes/pcre2/all/test_package/conanfile.py --- recipes/pcre2/all/test_package/conanfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 7fa64e3cb5532..f9f08fc17382e 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -2,7 +2,6 @@ from conan.tools.build import can_run from conan.tools.cmake import CMake, cmake_layout import os -from io import StringIO class TestPackageConan(ConanFile): From cf894bffc7da0da4b592eda542b93e083c2bd72a Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 17:00:43 +0200 Subject: [PATCH 10/14] Update recipes/pcre2/all/test_package/conanfile.py --- recipes/pcre2/all/test_package/conanfile.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index f9f08fc17382e..8d2bcef424f5a 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -9,10 +9,6 @@ class TestPackageConan(ConanFile): generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" test_type = "explicit" - @property - def _settings_build(self): - return getattr(self, "settings_build", self.settings) - def layout(self): cmake_layout(self) From c4607a031ad4de6e8e80ed4f1cb5f695cb744be6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 17:00:50 +0200 Subject: [PATCH 11/14] Update recipes/pcre2/all/test_package/conanfile.py --- recipes/pcre2/all/test_package/conanfile.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index 8d2bcef424f5a..f99ae575dd0ad 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -35,15 +35,3 @@ def test(self): if can_run(self): bin_path = os.path.join(self.cpp.build.bindir, "test_package") self.run(bin_path, env="conanrun") - - # Check that pcre2-config outputs correct link flags - if Version(self.tested_reference_str.split("/")[1]) >= "10.38": - bindir = load(self, os.path.join(self.build_folder, "bindir")) - libs = load(self, os.path.join(self.build_folder, "libs")).split(" ") - output = StringIO() - self.run(f"bash {bindir}/pcre2-config --libs8", output) - ldflags_str = next(l for l in output.getvalue().splitlines() if l.lower().startswith("-l")).strip() - ldflags = ldflags_str.split() - for flag in ldflags: - if flag.startswith("-l"): - assert flag[2:] in libs, f"Invalid library target '{flag[2:]}' output by pcre2-config. Not found in {libs}." From 11c96ce25ef94f0cfeacec76341d87a2817cdd1d Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 12 Jun 2024 17:01:00 +0200 Subject: [PATCH 12/14] Update recipes/pcre2/all/test_package/conanfile.py --- recipes/pcre2/all/test_package/conanfile.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/recipes/pcre2/all/test_package/conanfile.py b/recipes/pcre2/all/test_package/conanfile.py index f99ae575dd0ad..fafba71d30d56 100644 --- a/recipes/pcre2/all/test_package/conanfile.py +++ b/recipes/pcre2/all/test_package/conanfile.py @@ -15,17 +15,6 @@ def layout(self): def requirements(self): self.requires(self.tested_reference_str) - def build_requirements(self): - if self._settings_build.os == "Windows": - if not self.conf.get("tools.microsoft.bash:path", check_type=str): - self.tool_requires("msys2/cci.latest") - - def generate(self): - # Workaround for Conan v1: store dependency info for later use in test() - pcre2_cpp_info = self.dependencies["pcre2"].cpp_info.aggregated_components() - save(self, os.path.join(self.build_folder, "bindir"), pcre2_cpp_info.bindir) - save(self, os.path.join(self.build_folder, "libs"), " ".join(pcre2_cpp_info.libs)) - def build(self): cmake = CMake(self) cmake.configure() From f5987078d34ce0889dfe9e4a43de54d64b368802 Mon Sep 17 00:00:00 2001 From: danimtb Date: Thu, 13 Jun 2024 09:29:58 +0200 Subject: [PATCH 13/14] fix replace for 10.43 --- recipes/pcre2/all/conanfile.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/recipes/pcre2/all/conanfile.py b/recipes/pcre2/all/conanfile.py index 406aa5f10b135..5b3acc0095ae6 100644 --- a/recipes/pcre2/all/conanfile.py +++ b/recipes/pcre2/all/conanfile.py @@ -119,13 +119,15 @@ def _patch_sources(self): "RUNTIME DESTINATION bin", "RUNTIME DESTINATION bin BUNDLE DESTINATION bin") # pcre2-config does not correctly include '-static' in static library names - if Version(self.version) >= "10.38" and is_msvc(self): + if is_msvc(self): + if Version(self.version) > "10.42": + replace = "configure_file(pcre2-config.in" + elif Version(self.version) >= "10.38": + replace = "CONFIGURE_FILE(pcre2-config.in" postfix = "-static" if not self.options.shared else "" if self.settings.build_type == "Debug": postfix += "d" - replace_in_file(self, cmakelists, - "CONFIGURE_FILE(pcre2-config.in", - f'set(LIB_POSTFIX "{postfix}")\nCONFIGURE_FILE(pcre2-config.in') + replace_in_file(self, cmakelists, replace, f'set(LIB_POSTFIX "{postfix}")\n{replace}') def build(self): self._patch_sources() From e2d8c6f3267583839396380d4fa1e6f3df561474 Mon Sep 17 00:00:00 2001 From: danimtb Date: Thu, 13 Jun 2024 10:01:04 +0200 Subject: [PATCH 14/14] fix fix replace --- recipes/pcre2/all/conanfile.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/recipes/pcre2/all/conanfile.py b/recipes/pcre2/all/conanfile.py index 5b3acc0095ae6..d16eb670e2c83 100644 --- a/recipes/pcre2/all/conanfile.py +++ b/recipes/pcre2/all/conanfile.py @@ -120,14 +120,16 @@ def _patch_sources(self): "RUNTIME DESTINATION bin BUNDLE DESTINATION bin") # pcre2-config does not correctly include '-static' in static library names if is_msvc(self): + replace = None if Version(self.version) > "10.42": replace = "configure_file(pcre2-config.in" elif Version(self.version) >= "10.38": replace = "CONFIGURE_FILE(pcre2-config.in" postfix = "-static" if not self.options.shared else "" - if self.settings.build_type == "Debug": - postfix += "d" - replace_in_file(self, cmakelists, replace, f'set(LIB_POSTFIX "{postfix}")\n{replace}') + if replace: + if self.settings.build_type == "Debug": + postfix += "d" + replace_in_file(self, cmakelists, replace, f'set(LIB_POSTFIX "{postfix}")\n{replace}') def build(self): self._patch_sources()