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

libest: migrate to Conan v2 #18947

Merged
merged 10 commits into from
Jan 12, 2024
Merged
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
2 changes: 0 additions & 2 deletions recipes/libest/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
url: "https://github.com/cisco/libest/archive/r3.2.0.tar.gz"
sha256: "324b3a2b16cd14ea4234d75fa90f08b29509bac9cd3795c44268e22f906ee0ad"
patches:
"3.2.0":
- patch_file: "patches/0001-examples-are-broken-don-t-build-them.patch"

Check warning on line 7 in recipes/libest/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0001-exa ... ^ (line: 7)
base_path: "source_subfolder"
- patch_file: "patches/0002-add-extern.patch"

Check warning on line 8 in recipes/libest/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0002-add ... ^ (line: 8)
base_path: "source_subfolder"
120 changes: 70 additions & 50 deletions recipes/libest/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,100 @@
import os
from conans import ConanFile, tools, AutoToolsBuildEnvironment
from conans.errors import ConanInvalidConfiguration

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building
from conan.tools.env import VirtualRunEnv
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, replace_in_file
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.layout import basic_layout

required_conan_version = ">=1.53.0"


class LibEstConan(ConanFile):
name = "libest"
license = "BSD-3-Clause"
description = "EST is used for secure certificate enrollment"
topics = ("conan", "EST", "RFC 7030", "certificate enrollment")
homepage = "https://github.com/cisco/libest"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "compiler", "build_type", "arch"
exports_sources = "patches/**"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

_autotools = None
homepage = "https://github.com/cisco/libest"
topics = ("EST", "RFC 7030", "certificate enrollment")

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.settings.os in ("Windows", "Macos"):
raise ConanInvalidConfiguration(
"Platform is currently not supported by this recipe")
if self.settings.os == "Windows" or is_apple_os(self):
raise ConanInvalidConfiguration("Platform is currently not supported by this recipe")
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("openssl/1.1.1q")
self.requires("openssl/1.1.1w", transitive_headers=True, transitive_libs=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.requires("openssl/1.1.1w", transitive_headers=True, transitive_libs=True)
self.requires("openssl/[>=1.1 <4]", transitive_headers=True, transitive_libs=True)

In case it does not support OpenSSL 3.x, you still can use range, but [>=1.1 <3]

https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/dependencies.md#version-ranges

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Using <2 did not work for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uilianries Yeah, this fails on Conan v1 for some reason. Quite annoying.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: Version range '>=1.1 <3' from requirement 'openssl/[>=1.1 <3]' required by 'libest/3.2.0' could not be resolved in remote 'conan-center'

Only in Conan v1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I'll take a look.


def build_requirements(self):
self.tool_requires("libtool/2.4.7")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-r" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_autotools(self):
if not self._autotools:
self._autotools = AutoToolsBuildEnvironment(self)
# TODO:
# - Static only build: https://github.com/cisco/libest/blob/70824ddc09bee661329b9416082d88566efefb32/intro.txt#L140
# - Release build: https://github.com/cisco/libest/blob/70824ddc09bee661329b9416082d88566efefb32/intro.txt#L253
args = []
if self.options.shared:
args.extend(["--enable-shared", "--disable-static"])
else:
args.extend(["--disable-shared", "--enable-static"])
self._autotools.configure(args=args)
return self._autotools
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
tc = AutotoolsToolchain(self)
tc.generate()
deps = AutotoolsDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
# Remove duplicate AM_INIT_AUTOMAKE
replace_in_file(self, os.path.join(self.source_folder, "configure.ac"),
"AM_INIT_AUTOMAKE\n", "")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
with tools.chdir(self._source_subfolder):
autotools = self._configure_autotools()
self._patch_sources()
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()

def package(self):
self.copy("*LICENSE", src=self._source_subfolder, dst="licenses")
with tools.chdir(self._source_subfolder):
autotools = self._configure_autotools()
autotools.install()
copy(self, "*LICENSE",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"))
with chdir(self, self.source_folder):
autotools = Autotools(self)
if self.settings.build_type in ["Release", "MinSizeRel"]:
# https://github.com/cisco/libest/blob/r3.2.0/intro.txt#L244-L254
autotools.install(target="install-strip")
else:
autotools.install()
os.unlink(os.path.join(self.package_folder, "lib", "libest.la"))

def package_info(self):
self.cpp_info.libs = ["est"]
if self.settings.os == "Linux":
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["dl", "pthread"]
7 changes: 3 additions & 4 deletions recipes/libest/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(PackageTest C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(libest REQUIRED CONFIG)

add_executable(example example.c)
target_link_libraries(example ${CONAN_LIBS})
target_link_libraries(example PRIVATE libest::libest)
24 changes: 17 additions & 7 deletions recipes/libest/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os

class CAresTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "example")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/libest/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
16 changes: 16 additions & 0 deletions recipes/libest/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

class CAresTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)