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

[openssl] Update test_package for Conan v2 #15801

Merged
merged 3 commits into from
Feb 8, 2023
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: 1 addition & 1 deletion recipes/openssl/1.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def _patch_install_name(self):
old_str = '-install_name $(INSTALLTOP)/$(LIBDIR)/'
new_str = '-install_name @rpath/'
makefile = "Makefile" if self._full_version >= "1.1.1" else "Makefile.shared"
replace_in_file(self, makefile, old_str, new_str, strict=self.in_local_cache)
replace_in_file(self, makefile, old_str, new_str)
if self._use_nmake:
# NMAKE interprets trailing backslash as line continuation
if self._full_version >= "1.1.0":
Expand Down
8 changes: 3 additions & 5 deletions recipes/openssl/1.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ foreach(_custom_var ${_custom_vars})
endif()
endforeach()

add_executable(digest digest.c)
target_link_libraries(digest OpenSSL::SSL)
if(OPENSSL_WITH_ZLIB)
target_compile_definitions(digest PRIVATE WITH_ZLIB)
endif()
add_executable(${PROJECT_NAME} digest.c)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL)
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:${OPENSSL_WITH_ZLIB}>:WITH_ZLIB>)
24 changes: 17 additions & 7 deletions recipes/openssl/1.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from conan.tools.scm import Version
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
from conan.tools.files import save, load
import os

required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2"
import json


class TestPackageConan(ConanFile):
Expand All @@ -13,16 +13,25 @@ class TestPackageConan(ConanFile):
test_type = "explicit"

@property
def _skip_test(self):
def _skip_test_filename(self):
return os.path.join(self.build_folder, "skip_test.json")

def _generate_skip_test_file(self):
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
# Actually the workaround should be to add cmake/3.22.0 to build requires,
# but for the specific case of openssl it fails because it is also a requirement of cmake.
# see https://github.com/conan-io/conan/pull/9839
return self.settings.os == "Macos" and self.settings.arch == "armv8" \
and self.options["openssl"].shared
dict_test = {"skip_test": self.settings.os == "Macos" and \
self.settings.arch == "armv8" and \
bool(self.dependencies[self.tested_reference_str].options.shared)}
save(self, self._skip_test_filename, json.dumps(dict_test))

@property
def _skip_test(self):
return bool(json.loads(load(self, self._skip_test_filename)).get("skip_test"))

def requirements(self):
self.requires(self.tested_reference_str)
Expand All @@ -34,13 +43,14 @@ def generate(self):
tc = CMakeToolchain(self)
if self.settings.os == "Android":
tc.cache_variables["CONAN_LIBCXX"] = ""
openssl = self.dependencies["openssl"]
openssl = self.dependencies[self.tested_reference_str]
openssl_version = Version(openssl.ref.version)
if openssl_version.major == "1" and openssl_version.minor == "1":
tc.cache_variables["OPENSSL_WITH_ZLIB"] = False
else:
tc.cache_variables["OPENSSL_WITH_ZLIB"] = not openssl.options.no_zlib
tc.generate()
self._generate_skip_test_file()


def build(self):
Expand All @@ -51,5 +61,5 @@ def build(self):

def test(self):
if not self._skip_test and can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "digest")
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
32 changes: 2 additions & 30 deletions recipes/openssl/1.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,5 @@ project(test_package C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

option(OPENSSL_WITH_ZLIB "OpenSSL with zlib support" ON)

set(OpenSSL_DEBUG 1)
find_package(OpenSSL REQUIRED)

# Test whether variables from https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
# are properly defined in conan generators
set(_custom_vars
OPENSSL_FOUND
OPENSSL_INCLUDE_DIR
OPENSSL_CRYPTO_LIBRARY
OPENSSL_CRYPTO_LIBRARIES
OPENSSL_SSL_LIBRARY
OPENSSL_SSL_LIBRARIES
OPENSSL_LIBRARIES
OPENSSL_VERSION
)
foreach(_custom_var ${_custom_vars})
if(DEFINED _custom_var)
message(STATUS "${_custom_var}: ${${_custom_var}}")
else()
message(FATAL_ERROR "${_custom_var} not defined")
endif()
endforeach()

add_executable(digest ../test_package/digest.c)
target_link_libraries(digest OpenSSL::SSL)
if(OPENSSL_WITH_ZLIB)
target_compile_definitions(digest PRIVATE WITH_ZLIB)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
5 changes: 1 addition & 4 deletions recipes/openssl/1.x.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from conan.tools.build import cross_building
import os

required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2"


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
Expand Down Expand Up @@ -37,6 +35,5 @@ def build(self):

def test(self):
if not self._skip_test and not cross_building(self):
bin_path = os.path.join("bin", "digest")
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
assert os.path.exists(os.path.join(self.deps_cpp_info["openssl"].rootpath, "licenses", "LICENSE"))