Skip to content

Commit

Permalink
pcre2: fix invalid pcre2-config output for static libs
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Oct 16, 2023
1 parent d2f965e commit ecea763
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
10 changes: 9 additions & 1 deletion recipes/pcre2/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ 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.36":
replace_in_file(self, cmakelists,
"CONFIGURE_FILE(libpcre2-posix.pc.in",
('if(NOT BUILD_SHARED_LIBS)\n'
' string(PREPEND LIB_POSTFIX "-static")\n'
'endif()\n'
'CONFIGURE_FILE(libpcre2-posix.pc.in'))

def build(self):
self._patch_sources()
Expand Down Expand Up @@ -166,7 +174,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.
Expand Down
34 changes: 33 additions & 1 deletion recipes/pcre2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
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):
settings = "os", "arch", "compiler", "build_type"
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()
cmake.build()

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}."

0 comments on commit ecea763

Please sign in to comment.