Skip to content

Commit

Permalink
(#12079) add protobuf package version 3.21.4
Browse files Browse the repository at this point in the history
* add protobuf package version 3.21.4

* fix

* fix

* Use scm.Version

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Adopt new tools

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* remove old versions

* fix

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
pgeler and uilianries committed Aug 11, 2022
1 parent 613468f commit fd2811d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 189 deletions.
52 changes: 3 additions & 49 deletions recipes/protobuf/all/conandata.yml
@@ -1,66 +1,20 @@
sources:
"3.21.1":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.21.1.tar.gz"
sha256: "a295dd3b9551d3e2749a9969583dea110c6cdcc39d02088f7c7bb1100077e081"
"3.21.4":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.21.4.tar.gz"
sha256: "85d42d4485f36f8cec3e475a3b9e841d7d78523cd775de3a86dba77081f4ca25"
"3.20.0":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.20.0.tar.gz"
sha256: "b07772d38ab07e55eca4d50f4b53da2d998bb221575c60a4f81100242d4b4889"
"3.19.4":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.19.4.tar.gz"
sha256: "3bd7828aa5af4b13b99c191e8b1e884ebfa9ad371b0ce264605d347f135d2568"
"3.19.2":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.19.2.tar.gz"
sha256: "4dd35e788944b7686aac898f77df4e9a54da0ca694b8801bd6b2a9ffc1b3085e"
"3.18.1":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.18.1.tar.gz"
sha256: "9111bf0b542b631165fadbd80aa60e7fb25b25311c532139ed2089d76ddf6dd7"
"3.17.1":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.17.1.tar.gz"
sha256: "036d66d6eec216160dd898cfb162e9d82c1904627642667cc32b104d407bb411"
"3.16.0":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.16.0.tar.gz"
sha256: "7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5"
"3.15.8":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.15.8.tar.gz"
sha256: "0cbdc9adda01f6d2facc65a22a2be5cecefbefe5a09e5382ee8879b522c04441"
"3.15.5":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.15.5.tar.gz"
sha256: "bc3dbf1f09dba1b2eb3f2f70352ee97b9049066c9040ce0c9b67fb3294e91e4b"
"3.13.0":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz"
sha256: "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a"
"3.12.4":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.12.4.tar.gz"
sha256: "512e5a674bf31f8b7928a64d8adf73ee67b8fe88339ad29adaa3b84dbaa570d8"
"3.11.4":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz"
sha256: "a79d19dcdf9139fa4b81206e318e33d245c4c9da1ffed21c87288ed4380426f9"
"3.9.1":
url: "https://github.com/protocolbuffers/protobuf/archive/v3.9.1.tar.gz"
sha256: "98e615d592d237f94db8bf033fba78cd404d979b0b70351a9e5aaff725398357"
patches:
"3.19.4":
- patch_file: "patches/upstream-pr-9153-msvc-runtime.patch"
base_path: "source_subfolder"
"3.19.2":
- patch_file: "patches/upstream-pr-9153-msvc-runtime.patch"
base_path: "source_subfolder"
"3.15.5":
- patch_file: "patches/upstream-pr-8301-bundle-destination.patch"
base_path: "source_subfolder"
"3.13.0":
- patch_file: "patches/upstream-pr-7761-cmake-regex-fix.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-7288-android-log.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-8301-bundle-destination.patch"
base_path: "source_subfolder"
"3.12.4":
- patch_file: "patches/upstream-pr-7761-cmake-regex-fix.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-issue-7567-no-export-template-define.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-7288-android-log.patch"
base_path: "source_subfolder"
- patch_file: "patches/upstream-pr-8301-bundle-destination.patch"
base_path: "source_subfolder"
60 changes: 33 additions & 27 deletions recipes/protobuf/all/conanfile.py
@@ -1,7 +1,12 @@
from conan.tools.files import rename
from conan.tools.files import rename, get, apply_conandata_patches, replace_in_file, rmdir, rm

This comment has been minimized.

Copy link
@datalogics-kam

datalogics-kam Aug 19, 2022

Contributor

Importing rm changes the required_conan_version to 1.50.0, according to the changelog.

Also see: conan-io/conan#11443

from conan.tools.microsoft import msvc_runtime_flag
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan.tools.scm import Version
from conan.tools.build import cross_building
from conan.tools.apple.apple import is_apple_os
from conan.errors import ConanInvalidConfiguration
from conan import ConanFile
from conans import CMake

import functools
import os
import textwrap
Expand Down Expand Up @@ -60,7 +65,7 @@ def _is_clang_x86(self):

@property
def _can_disable_rtti(self):
return tools.Version(self.version) >= "3.15.4"
return Version(self.version) >= "3.15.4"

def export_sources(self):
self.copy("CMakeLists.txt")
Expand All @@ -86,21 +91,21 @@ def validate(self):
raise ConanInvalidConfiguration("Protobuf can't be built with shared + MT(d) runtimes")

if self.settings.compiler == "Visual Studio":
if tools.Version(self.settings.compiler.version) < "14":
if Version(self.settings.compiler.version) < "14":
raise ConanInvalidConfiguration("On Windows Protobuf can only be built with "
"Visual Studio 2015 or higher.")

if self.settings.compiler == "clang":
if tools.Version(self.version) >= "3.15.4" and tools.Version(self.settings.compiler.version) < "4":
if Version(self.version) >= "3.15.4" and Version(self.settings.compiler.version) < "4":
raise ConanInvalidConfiguration("protobuf {} doesn't support clang < 4".format(self.version))

if hasattr(self, "settings_build") and tools.cross_building(self) and \
if hasattr(self, "settings_build") and cross_building(self) and \
self.settings.os == "Macos" and self.options.shared:
# FIXME: should be allowed, actually build succeeds but it fails at build time of test package due to SIP
raise ConanInvalidConfiguration("protobuf shared not supported yet in CCI while cross-building on Macos")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
get(self, **self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

@property
Expand All @@ -116,7 +121,7 @@ def _configure_cmake(self):
cmake.definitions["protobuf_BUILD_PROTOC_BINARIES"] = True
if not self.options.debug_suffix:
cmake.definitions["protobuf_DEBUG_POSTFIX"] = ""
if tools.Version(self.version) >= "3.14.0":
if Version(self.version) >= "3.14.0":
cmake.definitions["protobuf_BUILD_LIBPROTOC"] = True
if self._can_disable_rtti:
cmake.definitions["protobuf_DISABLE_RTTI"] = not self.options.with_rtti
Expand All @@ -125,21 +130,20 @@ def _configure_cmake(self):
if not runtime:
runtime = self.settings.get_safe("compiler.runtime")
cmake.definitions["protobuf_MSVC_STATIC_RUNTIME"] = "MT" in runtime
if tools.Version(self.version) < "3.18.0" and self._is_clang_cl:
if Version(self.version) < "3.18.0" and self._is_clang_cl:
cmake.definitions["CMAKE_RC_COMPILER"] = os.environ.get("RC", "llvm-rc")
cmake.configure(build_folder=self._build_subfolder)
return cmake

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)

# Provide relocatable protobuf::protoc target and Protobuf_PROTOC_EXECUTABLE cache variable
# TODO: some of the following logic might be disabled when conan will
# allow to create executable imported targets in package_info()
protobuf_config_cmake = os.path.join(self._source_subfolder, "cmake", "protobuf-config.cmake.in")

tools.replace_in_file(
replace_in_file(self,
protobuf_config_cmake,
"@_protobuf_FIND_ZLIB@",
"# BEGIN CONAN PATCH\n#_protobuf_FIND_ZLIB@\n# END CONAN PATCH"
Expand All @@ -163,7 +167,7 @@ def _patch_sources(self):
set_property(TARGET protobuf::protoc PROPERTY IMPORTED_LOCATION ${{Protobuf_PROTOC_EXECUTABLE}})
endif()
""".format(protoc_rel_path=protoc_rel_path))
tools.replace_in_file(
replace_in_file(self,
protobuf_config_cmake,
"include(\"${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake\")",
protoc_target
Expand All @@ -172,16 +176,16 @@ def _patch_sources(self):
# Set DYLD_LIBRARY_PATH in command line to avoid issues with shared protobuf
# (even with virtualrunenv, this fix might be required due to SIP)
# Only works with cmake, cmake_find_package or cmake_find_package_multi generators
if tools.is_apple_os(self.settings.os):
tools.replace_in_file(
if is_apple_os(self.settings.os):
replace_in_file(self,
protobuf_config_cmake,
"add_custom_command(",
("set(CUSTOM_DYLD_LIBRARY_PATH ${CONAN_LIB_DIRS} ${Protobuf_LIB_DIRS} ${Protobuf_LIB_DIRS_RELEASE} ${Protobuf_LIB_DIRS_DEBUG} ${Protobuf_LIB_DIRS_RELWITHDEBINFO} ${Protobuf_LIB_DIRS_MINSIZEREL})\n"
"string(REPLACE \";\" \":\" CUSTOM_DYLD_LIBRARY_PATH \"${CUSTOM_DYLD_LIBRARY_PATH}\")\n"
"add_custom_command(")
)
cmd_str = "COMMAND protobuf::protoc" if tools.Version(self.version) < "3.20.0" else "COMMAND protobuf::protoc"
tools.replace_in_file(
cmd_str = "COMMAND protobuf::protoc" if Version(self.version) < "3.20.0" else "COMMAND protobuf::protoc"
replace_in_file(self,
protobuf_config_cmake,
cmd_str,
"COMMAND ${CMAKE_COMMAND} -E env \"DYLD_LIBRARY_PATH=${CUSTOM_DYLD_LIBRARY_PATH}\" $<TARGET_FILE:protobuf::protoc>"
Expand All @@ -190,21 +194,21 @@ def _patch_sources(self):
# Disable a potential warning in protobuf-module.cmake.in
# TODO: remove this patch? Is it really useful?
protobuf_module_cmake = os.path.join(self._source_subfolder, "cmake", "protobuf-module.cmake.in")
tools.replace_in_file(
replace_in_file(self,
protobuf_module_cmake,
"if(DEFINED Protobuf_SRC_ROOT_FOLDER)",
"if(0)\nif(DEFINED Protobuf_SRC_ROOT_FOLDER)",
)
tools.replace_in_file(
replace_in_file(self,
protobuf_module_cmake,
"# Define upper case versions of output variables",
"endif()",
)

# https://github.com/protocolbuffers/protobuf/issues/9916
# it will be solved in protobuf 3.21.0
if tools.Version(self.version) == "3.20.0":
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "google", "protobuf", "port_def.inc"),
if Version(self.version) == "3.20.0":
replace_in_file(self, os.path.join(self._source_subfolder, "src", "google", "protobuf", "port_def.inc"),
"#elif PROTOBUF_GNUC_MIN(12, 0)",
"#elif PROTOBUF_GNUC_MIN(12, 2)")

Expand All @@ -217,16 +221,16 @@ def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-config-version.cmake"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-targets.cmake"))
os.unlink(os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-targets-{}.cmake".format(str(self.settings.build_type).lower())))
rename(self, os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-config.cmake"),
os.path.join(self.package_folder, self._cmake_install_base_path, "protobuf-generate.cmake"))

if not self.options.lite:
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "libprotobuf-lite.*")
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "libprotobuf-lite.*")
rm(self, "libprotobuf-lite.*", os.path.join(self.package_folder, "lib"))
rm(self, "libprotobuf-lite.*", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
Expand Down Expand Up @@ -290,6 +294,8 @@ def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "Protobuf"
self.cpp_info.filenames["cmake_find_package_multi"] = "protobuf"
self.cpp_info.names["pkg_config"] ="protobuf_full_package"
self.cpp_info.components["libprotobuf"].build_modules = build_modules
for generator in ["cmake_find_package", "cmake_find_package_multi"]:
self.cpp_info.components["libprotobuf"].build_modules[generator] = build_modules
if self.options.lite:
self.cpp_info.components["libprotobuf-lite"].build_modules = build_modules
for generator in ["cmake_find_package", "cmake_find_package_multi"]:
self.cpp_info.components["libprotobuf-lite"].build_modules[generator] = build_modules

This file was deleted.

26 changes: 0 additions & 26 deletions recipes/protobuf/all/patches/upstream-pr-7288-android-log.patch

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 5 additions & 3 deletions recipes/protobuf/all/test_package/conanfile.py
@@ -1,4 +1,6 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import cross_building
from conans import CMake
import os


Expand All @@ -7,7 +9,7 @@ class TestPackageConan(ConanFile):
generators = "cmake", "cmake_find_package_multi"

def build_requirements(self):
if hasattr(self, "settings_build") and tools.cross_building(self):
if hasattr(self, "settings_build") and cross_building(self):
self.build_requires(str(self.requires["protobuf"]))

def build(self):
Expand All @@ -17,6 +19,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self):
if not cross_building(self):
self.run("protoc --version", run_environment=True)
self.run(os.path.join("bin", "test_package"), run_environment=True)
18 changes: 1 addition & 17 deletions recipes/protobuf/config.yml
@@ -1,27 +1,11 @@
versions:
"3.21.1":
"3.21.4":
folder: all
"3.20.0":
folder: all
"3.19.4":
folder: all
"3.19.2":
folder: all
"3.18.1":
folder: all
"3.17.1":
folder: all
"3.16.0":
folder: all
"3.15.8":
folder: all
"3.15.5":
folder: all
"3.13.0":
folder: all
"3.12.4":
folder: all
"3.11.4":
folder: all
"3.9.1":
folder: all

0 comments on commit fd2811d

Please sign in to comment.