Repository navigation
cmake: correctly handle absolute install dir paths - #3876
whispersofthedawn wants to merge 1 commit into
Conversation
| "lib${SSL_LIB_NAME}.${SHIM_LIB_EXT}" | ||
| "${CMAKE_CURRENT_BINARY_DIR}/libssl.${SHIM_LIB_EXT}") | ||
| install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libssl.${SHIM_LIB_EXT}" | ||
| DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
There was a problem hiding this comment.
We should apply the same fix to the header shim. With an absolute CMAKE_INSTALL_INCLUDEDIR, installation exits successfully but leaves out the openssl include symlink, so shim consumers can silently pick up the system's OpenSSL headers while linking AWS-LC. A split-directory case in the install tests would catch this, and I think it should also check the bin/openssl and bin/c_rehash links, which have no coverage today.
There was a problem hiding this comment.
We should apply the same fix to the header shim. With an absolute
CMAKE_INSTALL_INCLUDEDIR, installation exits successfully but leaves out theopensslinclude symlink, so shim consumers can silently pick up the system's OpenSSL headers while linking AWS-LC.
Done.
A split-directory case in the install tests would catch this, and I think it should also check the
bin/opensslandbin/c_rehashlinks, which have no coverage today.
Thanks, this seems like a very good idea. However, I'm having some trouble figuring out how to implement this nicely. The best idea I have so far is a patch like so, but this involves refactoring that whole test. Would you like me to do something like that, or do you have a less invasive idea?
Patch I was drafting (collapsed, click to expand)
diff --git a/tests/ci/run_dist_pkg_install_tests.sh b/tests/ci/run_dist_pkg_install_tests.sh
index 8959e63dec..49e686874b 100755
--- a/tests/ci/run_dist_pkg_install_tests.sh
+++ b/tests/ci/run_dist_pkg_install_tests.sh
@@ -39,11 +39,40 @@ function fail() {
exit 1
}
+function resolve_install_paths() {
+ local INSTALL_NAME=$1
+ local LAYOUT_MODE=$2
+
+ if [[ "${LAYOUT_MODE}" == "split" ]]; then
+ local BASE_DIR="${SCRATCH_DIR}/${INSTALL_NAME}-split"
+
+ PREFIX_DIR="${BASE_DIR}/prefix"
+ INCLUDE_DIR="${BASE_DIR}/store-dev/include"
+ LIB_DIR="${BASE_DIR}/store-lib/lib"
+ BIN_DIR="${BASE_DIR}/store-bin/bin"
+ CMAKE_PREFIX_PATHS="${PREFIX_DIR};${BASE_DIR}/store-lib;${BASE_DIR}/store-dev"
+ else
+ PREFIX_DIR="${SCRATCH_DIR}/${INSTALL_NAME}"
+ INCLUDE_DIR="${PREFIX_DIR}/include"
+
+ local REL_LIB_DIR
+ REL_LIB_DIR=$(get_lib_dir "${PREFIX_DIR}")
+
+ LIB_DIR="${PREFIX_DIR}/${REL_LIB_DIR}"
+ BIN_DIR="${PREFIX_DIR}/bin"
+ CMAKE_PREFIX_PATHS="${PREFIX_DIR}"
+ fi
+}
+
function install_aws_lc_dist_pkg() {
- local INSTALL_DIR=${SCRATCH_DIR}/$1
- local BUILD_SHARED_LIBS=$2 # "BUILD_SHARED_LIBS=ON" or "BUILD_SHARED_LIBS=OFF"
- local OPENSSL_SHIM=$3 # "ON" or "OFF"
- local BUILD_LIBSSL=${4:-ON} # "ON" or "OFF"
+ local INSTALL_NAME=$1
+ local LAYOUT_MODE=$2
+ local BUILD_SHARED_LIBS=$3 # "BUILD_SHARED_LIBS=ON" or "BUILD_SHARED_LIBS=OFF"
+ local OPENSSL_SHIM=$4 # "ON" or "OFF"
+ local BUILD_LIBSSL=${5:-ON} # "ON" or "OFF"
+
+ local PREFIX_DIR INCLUE_DIR LIB_DIR BIN_DIR
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
local BUILD_DIR=${SCRATCH_DIR}/build
rm -rf "${BUILD_DIR:?}"
@@ -53,7 +82,7 @@ function install_aws_lc_dist_pkg() {
"-H${AWS_LC_DIR}"
"-B${BUILD_DIR}"
"-GNinja"
- "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}"
+ "-DCMAKE_INSTALL_PREFIX=${PREFIX_DIR}"
"-DBUILD_TESTING=OFF"
"-DENABLE_DIST_PKG=ON"
"-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}"
@@ -69,19 +98,27 @@ function install_aws_lc_dist_pkg() {
CMAKE_FLAGS+=("-DBUILD_TOOL=OFF")
fi
+ if [[ "${LAYOUT_MODE}" == "split" ]]; then
+ CMAKE_FLAGS+=(
+ "-DCMAKE_INSTALL_BINDIR=${BIN_DIR}"
+ "-DCMAKE_INSTALL_INCLUDEDIR=${INCLUDE_DIR}"
+ "-DCMAKE_INSTALL_LIBDIR=${LIB_DIR}"
+ )
+ fi
+
${CMAKE_COMMAND} "${CMAKE_FLAGS[@]}"
${CMAKE_COMMAND} --build "${BUILD_DIR}" --target install
}
# Verify installation structure for ENABLE_DIST_PKG
function verify_dist_pkg_structure() {
- local INSTALL_DIR=${SCRATCH_DIR}/$1
- local LIB_EXT=$2 # ".so" or ".a"
- local OPENSSL_SHIM=$3 # "ON" or "OFF"
+ local INSTALL_NAME=$1
+ local LAYOUT_MODE=$2
+ local LIB_EXT=$3 # ".so" or ".a"
+ local OPENSSL_SHIM=$4 # "ON" or "OFF"
- # Detect library directory (lib or lib64)
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
+ local PREFIX_DIR INCLUDE_DIR LIB_DIR BIN_DIR CMAKE_PREFIX_PATHS
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
echo ""
echo "=============================================="
@@ -92,89 +129,89 @@ function verify_dist_pkg_structure() {
echo "=============================================="
# Check headers are in aws-lc subdirectory (COHABITANT_HEADERS)
- if [[ ! -d "${INSTALL_DIR}/include/aws-lc/openssl" ]]; then
+ if [[ ! -d "${INCLUDE_DIR}/aws-lc/openssl" ]]; then
fail "Headers not installed in include/aws-lc/openssl/ directory"
fi
# Check that at least one expected header exists
- if [[ ! -f "${INSTALL_DIR}/include/aws-lc/openssl/ssl.h" ]]; then
+ if [[ ! -f "${INCLUDE_DIR}/aws-lc/openssl/ssl.h" ]]; then
fail "ssl.h not found in include/aws-lc/openssl/"
fi
- if [[ ! -f "${INSTALL_DIR}/include/aws-lc/openssl/crypto.h" ]]; then
+ if [[ ! -f "${INCLUDE_DIR}/aws-lc/openssl/crypto.h" ]]; then
fail "crypto.h not found in include/aws-lc/openssl/"
fi
# Check libraries have -awslc suffix (SET_LIB_SONAME)
if [[ "${LIB_EXT}" == ".so" ]]; then
# For shared libraries, check for .so files
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/libcrypto-awslc.so" ]]; then
+ if [[ ! -f "${LIB_DIR}/libcrypto-awslc.so" ]]; then
fail "libcrypto-awslc.so not found in ${LIB_DIR}/"
fi
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/libssl-awslc.so" ]]; then
+ if [[ ! -f "${LIB_DIR}/libssl-awslc.so" ]]; then
fail "libssl-awslc.so not found in ${LIB_DIR}/"
fi
else
# For static libraries, check for .a files
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/libcrypto-awslc.a" ]]; then
+ if [[ ! -f "${LIB_DIR}/libcrypto-awslc.a" ]]; then
fail "libcrypto-awslc.a not found in ${LIB_DIR}/"
fi
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/libssl-awslc.a" ]]; then
+ if [[ ! -f "${LIB_DIR}/libssl-awslc.a" ]]; then
fail "libssl-awslc.a not found in ${LIB_DIR}/"
fi
fi
# Check pkg-config files
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/pkgconfig/aws-lc.pc" ]]; then
+ if [[ ! -f "${LIB_DIR}/pkgconfig/aws-lc.pc" ]]; then
fail "aws-lc.pc not found in ${LIB_DIR}/pkgconfig/"
fi
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/pkgconfig/libcrypto-awslc.pc" ]]; then
+ if [[ ! -f "${LIB_DIR}/pkgconfig/libcrypto-awslc.pc" ]]; then
fail "libcrypto-awslc.pc not found in ${LIB_DIR}/pkgconfig/"
fi
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/pkgconfig/libssl-awslc.pc" ]]; then
+ if [[ ! -f "${LIB_DIR}/pkgconfig/libssl-awslc.pc" ]]; then
fail "libssl-awslc.pc not found in ${LIB_DIR}/pkgconfig/"
fi
# Check OpenSSL shim symlinks
if [[ "${OPENSSL_SHIM}" == "ON" ]]; then
# Check header symlink
- if [[ ! -L "${INSTALL_DIR}/include/openssl" ]]; then
+ if [[ ! -L "${INCLUDE_DIR}/openssl" ]]; then
fail "include/openssl symlink not found (OpenSSL shim enabled)"
fi
# Verify symlink points to aws-lc/openssl
local SYMLINK_TARGET
- SYMLINK_TARGET=$(readlink "${INSTALL_DIR}/include/openssl")
+ SYMLINK_TARGET=$(readlink "${INCLUDE_DIR}/openssl")
if [[ "${SYMLINK_TARGET}" != "aws-lc/openssl" ]]; then
fail "include/openssl symlink points to '${SYMLINK_TARGET}' instead of 'aws-lc/openssl'"
fi
# Check library symlinks
if [[ "${LIB_EXT}" == ".so" ]]; then
- if [[ ! -L "${INSTALL_DIR}/${LIB_DIR}/libcrypto.so" ]]; then
+ if [[ ! -L "${LIB_DIR}/libcrypto.so" ]]; then
fail "libcrypto.so symlink not found in ${LIB_DIR}/ (OpenSSL shim enabled)"
fi
- if [[ ! -L "${INSTALL_DIR}/${LIB_DIR}/libssl.so" ]]; then
+ if [[ ! -L "${LIB_DIR}/libssl.so" ]]; then
fail "libssl.so symlink not found in ${LIB_DIR}/ (OpenSSL shim enabled)"
fi
else
- if [[ ! -L "${INSTALL_DIR}/${LIB_DIR}/libcrypto.a" ]]; then
+ if [[ ! -L "${LIB_DIR}/libcrypto.a" ]]; then
fail "libcrypto.a symlink not found in ${LIB_DIR}/ (OpenSSL shim enabled)"
fi
- if [[ ! -L "${INSTALL_DIR}/${LIB_DIR}/libssl.a" ]]; then
+ if [[ ! -L "${LIB_DIR}/libssl.a" ]]; then
fail "libssl.a symlink not found in ${LIB_DIR}/ (OpenSSL shim enabled)"
fi
fi
# Check openssl.pc exists
- if [[ ! -f "${INSTALL_DIR}/${LIB_DIR}/pkgconfig/openssl.pc" ]]; then
+ if [[ ! -f "${LIB_DIR}/pkgconfig/openssl.pc" ]]; then
fail "openssl.pc not found in ${LIB_DIR}/pkgconfig/ (OpenSSL shim enabled)"
fi
# Shim pc files must exist and must not name the cohabitant include dir.
local PC_FILE
for PC_FILE in libcrypto.pc libssl.pc; do
- local PC_PATH="${INSTALL_DIR}/${LIB_DIR}/pkgconfig/${PC_FILE}"
+ local PC_PATH="${LIB_DIR}/pkgconfig/${PC_FILE}"
if [[ ! -f "${PC_PATH}" ]]; then
fail "${PC_FILE} not found in ${LIB_DIR}/pkgconfig/ (OpenSSL shim enabled)"
fi
@@ -184,22 +221,22 @@ function verify_dist_pkg_structure() {
done
else
# When OpenSSL shim is disabled, symlinks should NOT exist
- if [[ -e "${INSTALL_DIR}/include/openssl" ]]; then
+ if [[ -e "${INCLUDE_DIR}/openssl" ]]; then
fail "include/openssl should not exist when OpenSSL shim is disabled"
fi
if [[ "${LIB_EXT}" == ".so" ]]; then
- if [[ -e "${INSTALL_DIR}/${LIB_DIR}/libcrypto.so" ]]; then
+ if [[ -e "${LIB_DIR}/libcrypto.so" ]]; then
fail "libcrypto.so should not exist in ${LIB_DIR}/ when OpenSSL shim is disabled"
fi
- if [[ -e "${INSTALL_DIR}/${LIB_DIR}/libssl.so" ]]; then
+ if [[ -e "${LIB_DIR}/libssl.so" ]]; then
fail "libssl.so should not exist in ${LIB_DIR}/ when OpenSSL shim is disabled"
fi
else
- if [[ -e "${INSTALL_DIR}/${LIB_DIR}/libcrypto.a" ]]; then
+ if [[ -e "${LIB_DIR}/libcrypto.a" ]]; then
fail "libcrypto.a should not exist in ${LIB_DIR}/ when OpenSSL shim is disabled"
fi
- if [[ -e "${INSTALL_DIR}/${LIB_DIR}/libssl.a" ]]; then
+ if [[ -e "${LIB_DIR}/libssl.a" ]]; then
fail "libssl.a should not exist in ${LIB_DIR}/ when OpenSSL shim is disabled"
fi
fi
@@ -207,7 +244,7 @@ function verify_dist_pkg_structure() {
# Nor should the shim pc files exist
local PC_FILE
for PC_FILE in openssl.pc libcrypto.pc libssl.pc; do
- if [[ -e "${INSTALL_DIR}/${LIB_DIR}/pkgconfig/${PC_FILE}" ]]; then
+ if [[ -e "${LIB_DIR}/pkgconfig/${PC_FILE}" ]]; then
fail "${PC_FILE} should not exist when OpenSSL shim is disabled"
fi
done
@@ -356,12 +393,12 @@ endif()
# matters: the failure only surfaces in the final link command.
function test_cmake_find_package_openssl() {
local INSTALL_NAME=$1
- local IS_STATIC=$2 # "ON" for static, "OFF" for shared
- local WITH_SSL=${3:-ON}
- local INSTALL_DIR=${SCRATCH_DIR}/${INSTALL_NAME}
+ local LAYOUT_MODE=$2
+ local IS_STATIC=$3 # "ON" for static, "OFF" for shared
+ local WITH_SSL=${4:-ON}
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
+ local PREFIX_DIR INCLUDE_DIR LIB_DIR BIN_DIR CMAKE_PREFIX_PATHS
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
echo ""
echo "=============================================="
@@ -377,24 +414,22 @@ function test_cmake_find_package_openssl() {
"-H${SCRATCH_DIR}/openssl-consumer-src"
"-B${BUILD_DIR}"
"-GNinja"
- "-DEXPECTED_PREFIX=${INSTALL_DIR}"
+ "-DEXPECTED_PREFIX=${PREFIX_DIR}"
"-DWITH_SSL=${WITH_SSL}"
- # FindOpenSSL hints come from OPENSSL_ROOT_DIR and pkg-config, so point
- # both at the prefix under test; a system OpenSSL must not win.
- "-DOPENSSL_ROOT_DIR=${INSTALL_DIR}"
+ "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATHS}"
)
if [[ "${IS_STATIC}" == "ON" ]]; then
# Makes FindOpenSSL use --static, resolving Requires.private.
CMAKE_FLAGS+=("-DOPENSSL_USE_STATIC_LIBS=TRUE")
fi
- local PKG_CONFIG_PATH="${INSTALL_DIR}/${LIB_DIR}/pkgconfig"
+ local PKG_CONFIG_PATH="${LIB_DIR}/pkgconfig"
export PKG_CONFIG_PATH
${CMAKE_COMMAND} "${CMAKE_FLAGS[@]}"
${CMAKE_COMMAND} --build "${BUILD_DIR}"
- run_with_library_path "${INSTALL_DIR}/${LIB_DIR}" \
+ run_with_library_path "${LIB_DIR}" \
"${BUILD_DIR}/opensslconsumer" || fail "find_package(OpenSSL) consumer failed to run"
echo "Standard CMake find_package(OpenSSL) test passed!"
@@ -403,12 +438,11 @@ function test_cmake_find_package_openssl() {
# Build and run test app using CMake find_package
function test_cmake_find_package() {
local INSTALL_NAME=$1
- local BUILD_SHARED_LIBS=$2
- local INSTALL_DIR=${SCRATCH_DIR}/${INSTALL_NAME}
+ local LAYOUT_MODE=$2
+ local BUILD_SHARED_LIBS=$3
- # Detect library directory (lib or lib64)
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
+ local PREFIX_DIR INCLUDE_DIR LIB_DIR BIN_DIR CMAKE_PREFIX_PATHS
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
echo ""
echo "=============================================="
@@ -426,12 +460,12 @@ function test_cmake_find_package() {
-B${BUILD_DIR} \
-GNinja \
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} \
- -DCMAKE_PREFIX_PATH=${INSTALL_DIR}
+ -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATHS}
${CMAKE_COMMAND} --build ${BUILD_DIR}
# Run the application with the installed shared libraries.
- run_with_library_path "${INSTALL_DIR}/${LIB_DIR}" \
+ run_with_library_path "${LIB_DIR}" \
"${BUILD_DIR}/myapp" || fail "Test application failed to run"
echo "CMake find_package test passed!"
@@ -440,13 +474,12 @@ function test_cmake_find_package() {
# Test pkg-config
function test_pkg_config() {
local INSTALL_NAME=$1
- local PC_NAME=$2 # e.g., "aws-lc" or "openssl"
- local IS_STATIC=$3 # "ON" for static, "OFF" for shared
- local INSTALL_DIR=${SCRATCH_DIR}/${INSTALL_NAME}
+ local LAYOUT_MODE=$2
+ local PC_NAME=$3 # e.g., "aws-lc" or "openssl"
+ local IS_STATIC=$4 # "ON" for static, "OFF" for shared
- # Detect library directory (lib or lib64)
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
+ local PREFIX_DIR INCLUE_DIR LIB_DIR BIN_DIR
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
# Set pkg-config --static flag for static builds
local PKG_CONFIG_STATIC_FLAG=""
@@ -462,7 +495,7 @@ function test_pkg_config() {
echo "Static: ${IS_STATIC}"
echo "=============================================="
- local PKG_CONFIG_PATH="${INSTALL_DIR}/${LIB_DIR}/pkgconfig"
+ local PKG_CONFIG_PATH="${LIB_DIR}/pkgconfig"
export PKG_CONFIG_PATH
# Check if package exists
@@ -497,7 +530,7 @@ function test_pkg_config() {
# Compile using pkg-config flags
${CC:-cc} ${TEST_DIR}/test.c ${CFLAGS} ${LIBS} -o ${TEST_DIR}/test
- run_with_library_path "${INSTALL_DIR}/${LIB_DIR}" \
+ run_with_library_path "${LIB_DIR}" \
"${TEST_DIR}/test" || fail "pkg-config test application failed to run"
echo "pkg-config test passed for ${PC_NAME}!"
@@ -508,13 +541,12 @@ function test_pkg_config() {
# module and linker names they reference are unsuffixed.
function test_openssl_compat_pkg_config() {
local INSTALL_NAME=$1
- local IS_STATIC=$2 # "ON" for static, "OFF" for shared
- local INSTALL_DIR=${SCRATCH_DIR}/${INSTALL_NAME}
+ local LAYOUT_MODE=$2
+ local IS_STATIC=$3 # "ON" for static, "OFF" for shared
- # Detect library directory (lib or lib64)
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
- local PC_DIR="${INSTALL_DIR}/${LIB_DIR}/pkgconfig"
+ local PREFIX_DIR INCLUE_DIR LIB_DIR BIN_DIR
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
+ local PC_DIR="${LIB_DIR}/pkgconfig"
local PKG_CONFIG_STATIC_FLAG=""
if [[ "${IS_STATIC}" == "ON" ]]; then
@@ -546,15 +578,15 @@ function test_openssl_compat_pkg_config() {
# would leak it into every consumer of libcrypto.
local RESOLVED_INCLUDEDIR
RESOLVED_INCLUDEDIR=$(pkg-config --variable=includedir "${PC_NAME}")
- if [[ "${RESOLVED_INCLUDEDIR}" != "${INSTALL_DIR}/include" ]]; then
- fail "'${PC_NAME}' includedir is '${RESOLVED_INCLUDEDIR}', expected '${INSTALL_DIR}/include'"
+ if [[ "${RESOLVED_INCLUDEDIR}" != "${INCLUDE_DIR}" ]]; then
+ fail "'${PC_NAME}' includedir is '${RESOLVED_INCLUDEDIR}', expected '${INCLUDE_DIR}'"
fi
local CFLAGS
CFLAGS=$(pkg-config --cflags "${PC_NAME}")
echo "${PC_NAME} CFLAGS: ${CFLAGS}"
- assert_exact_token "${CFLAGS}" "-I${INSTALL_DIR}/include" "'${PC_NAME}' Cflags"
- assert_no_exact_token "${CFLAGS}" "-I${INSTALL_DIR}/include/aws-lc" "'${PC_NAME}' Cflags"
+ assert_exact_token "${CFLAGS}" "-I${INCLUDE_DIR}" "'${PC_NAME}' Cflags"
+ assert_no_exact_token "${CFLAGS}" "-I${INCLUDE_DIR}/aws-lc" "'${PC_NAME}' Cflags"
# No dependency field of a shim-facing file may name a suffixed token.
assert_no_suffixed_openssl_tokens "${PC_DIR}/${PC_NAME}.pc"
@@ -566,7 +598,7 @@ function test_openssl_compat_pkg_config() {
for PC_NAME in libcrypto openssl; do
LIBS=$(pkg-config ${PKG_CONFIG_STATIC_FLAG} --libs "${PC_NAME}")
echo "${PC_NAME} LIBS: ${LIBS}"
- assert_exact_token "${LIBS}" "-L${INSTALL_DIR}/${LIB_DIR}" "'${PC_NAME}' Libs"
+ assert_exact_token "${LIBS}" "-L${LIB_DIR}" "'${PC_NAME}' Libs"
assert_exact_token "${LIBS}" "-lcrypto" "'${PC_NAME}' Libs"
assert_no_exact_token "${LIBS}" "-lcrypto${SUFFIX}" "'${PC_NAME}' Libs"
assert_no_exact_token "${LIBS}" "-lssl${SUFFIX}" "'${PC_NAME}' Libs"
@@ -629,7 +661,7 @@ function test_openssl_compat_pkg_config() {
${CC:-cc} ${SSL_TEST_DIR}/test.c ${SSL_CFLAGS} ${SSL_LIBS} -o ${SSL_TEST_DIR}/test
- run_with_library_path "${INSTALL_DIR}/${LIB_DIR}" \
+ run_with_library_path "${LIB_DIR}" \
"${SSL_TEST_DIR}/test" || fail "shim libssl+libcrypto consumer failed to run"
# The libssh2 pattern: pkg-config resolves Requires.private to compute
@@ -659,12 +691,12 @@ function test_openssl_compat_pkg_config() {
# and linker names, and the cohabitant include directory.
function test_native_pkg_config_unchanged() {
local INSTALL_NAME=$1
+ local LAYOUT=$2
local IS_STATIC=$2 # "ON" for static, "OFF" for shared
- local INSTALL_DIR=${SCRATCH_DIR}/${INSTALL_NAME}
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
- local PC_DIR="${INSTALL_DIR}/${LIB_DIR}/pkgconfig"
+ local PREFIX_DIR INCLUE_DIR LIB_DIR BIN_DIR
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
+ local PC_DIR="${LIB_DIR}/pkgconfig"
local PKG_CONFIG_STATIC_FLAG=""
if [[ "${IS_STATIC}" == "ON" ]]; then
@@ -690,8 +722,8 @@ function test_native_pkg_config_unchanged() {
fi
local RESOLVED_INCLUDEDIR
RESOLVED_INCLUDEDIR=$(pkg-config --variable=includedir "${PC_NAME}")
- if [[ "${RESOLVED_INCLUDEDIR}" != "${INSTALL_DIR}/include/aws-lc" ]]; then
- fail "native '${PC_NAME}' includedir is '${RESOLVED_INCLUDEDIR}', expected '${INSTALL_DIR}/include/aws-lc'"
+ if [[ "${RESOLVED_INCLUDEDIR}" != "${INCLUDE_DIR}/aws-lc" ]]; then
+ fail "native '${PC_NAME}' includedir is '${RESOLVED_INCLUDEDIR}', expected '${INCLUDE_DIR}/aws-lc'"
fi
done
@@ -725,11 +757,11 @@ function test_native_pkg_config_unchanged() {
# require one -- a dangling requirement makes 'pkg-config --exists' fail.
function test_pkg_config_no_libssl() {
local INSTALL_NAME=$1
- local INSTALL_DIR=${SCRATCH_DIR}/${INSTALL_NAME}
-
- local LIB_DIR
- LIB_DIR=$(get_lib_dir "${INSTALL_DIR}")
- local PC_DIR="${INSTALL_DIR}/${LIB_DIR}/pkgconfig"
+ local LAYOUT_MODE=$2
+
+ local PREFIX_DIR INCLUE_DIR LIB_DIR BIN_DIR
+ resolve_install_paths "${INSTALL_NAME}" "${LAYOUT_MODE}"
+ local PC_DIR="${LIB_DIR}/pkgconfig"
local SUFFIX
SUFFIX=$(require_product_suffix "${PC_DIR}")
@@ -751,10 +783,10 @@ function test_pkg_config_no_libssl() {
# caught by -L without -e.
local LIB_FILE
for LIB_FILE in "libssl.so" "libssl.a" "libssl${SUFFIX}.so" "libssl${SUFFIX}.a"; do
- if [[ -e "${INSTALL_DIR}/${LIB_DIR}/${LIB_FILE}" ]]; then
+ if [[ -e "${LIB_DIR}/${LIB_FILE}" ]]; then
fail "${LIB_FILE} should not be installed when BUILD_LIBSSL=OFF"
fi
- if [[ -L "${INSTALL_DIR}/${LIB_DIR}/${LIB_FILE}" ]]; then
+ if [[ -L "${LIB_DIR}/${LIB_FILE}" ]]; then
fail "${LIB_FILE} is a dangling symlink; it should not be installed when BUILD_LIBSSL=OFF"
fi
done
@@ -819,80 +851,87 @@ function test_pkg_config_no_libssl() {
setup_test_app
setup_openssl_consumer_app
-# Test 1: ENABLE_DIST_PKG only (shared libs)
-echo ""
-echo "############################################"
-echo "# Test 1: ENABLE_DIST_PKG (shared libs) #"
-echo "############################################"
-install_aws_lc_dist_pkg install-dist-pkg-shared ON OFF
-verify_dist_pkg_structure install-dist-pkg-shared .so OFF
-test_cmake_find_package install-dist-pkg-shared ON
-test_pkg_config install-dist-pkg-shared aws-lc OFF
-
-# Symbol versioning tests (reuse the shared-lib install from Test 1)
-echo ""
-echo "############################################"
-echo "# Symbol Versioning Tests #"
-echo "############################################"
-"${AWS_LC_DIR}/tests/ci/run_symbol_version_test.sh" "${SCRATCH_DIR}/install-dist-pkg-shared"
-
-# Test 2: ENABLE_DIST_PKG + OPENSSL_SHIM (shared libs)
-echo ""
-echo "############################################"
-echo "# Test 2: ENABLE_DIST_PKG + SHIM (shared) #"
-echo "############################################"
-install_aws_lc_dist_pkg install-dist-pkg-shim-shared ON ON
-verify_dist_pkg_structure install-dist-pkg-shim-shared .so ON
-test_cmake_find_package install-dist-pkg-shim-shared ON
-test_pkg_config install-dist-pkg-shim-shared aws-lc OFF
-test_pkg_config install-dist-pkg-shim-shared openssl OFF
-# test_openssl_compat_pkg_config subsumes a standalone libcrypto compile: it
-# token-checks all three OpenSSL module names and compiles/runs a consumer
-# against 'libssl libcrypto'.
-test_openssl_compat_pkg_config install-dist-pkg-shim-shared OFF
-test_cmake_find_package_openssl install-dist-pkg-shim-shared OFF ON
-
-# Test 3: ENABLE_DIST_PKG only (static libs)
-echo ""
-echo "############################################"
-echo "# Test 3: ENABLE_DIST_PKG (static libs) #"
-echo "############################################"
-install_aws_lc_dist_pkg install-dist-pkg-static OFF OFF
-verify_dist_pkg_structure install-dist-pkg-static .a OFF
-test_cmake_find_package install-dist-pkg-static OFF
-test_pkg_config install-dist-pkg-static aws-lc ON
-
-# Test 4: ENABLE_DIST_PKG + OPENSSL_SHIM (static libs)
-echo ""
-echo "############################################"
-echo "# Test 4: ENABLE_DIST_PKG + SHIM (static) #"
-echo "############################################"
-install_aws_lc_dist_pkg install-dist-pkg-shim-static OFF ON
-verify_dist_pkg_structure install-dist-pkg-shim-static .a ON
-test_cmake_find_package install-dist-pkg-shim-static OFF
-test_pkg_config install-dist-pkg-shim-static aws-lc ON
-test_pkg_config install-dist-pkg-shim-static openssl ON
-test_openssl_compat_pkg_config install-dist-pkg-shim-static ON
-# The native pc files are identical across the shared and static shim
-# installs, so they are checked once, here, where --static also resolves the
-# Requires.private/Libs.private fields.
-test_native_pkg_config_unchanged install-dist-pkg-shim-static ON
-# The static install reproduces the original FindOpenSSL failure: its
-# extra-dependency path only runs when the library it found is a static archive.
-test_cmake_find_package_openssl install-dist-pkg-shim-static ON ON
-
-# Test 5: ENABLE_DIST_PKG + OPENSSL_SHIM, BUILD_LIBSSL=OFF
-echo ""
-echo "############################################"
-echo "# Test 5: SHIM + BUILD_LIBSSL=OFF #"
-echo "############################################"
-install_aws_lc_dist_pkg install-dist-pkg-shim-nossl ON ON OFF
-test_pkg_config_no_libssl install-dist-pkg-shim-nossl
-test_pkg_config install-dist-pkg-shim-nossl openssl OFF
-# Unlike the shim-shared/shim-static configs, this is the only compile/run
-# against the shim modules here, so the libcrypto smoke test stays.
-test_pkg_config install-dist-pkg-shim-nossl libcrypto OFF
-test_cmake_find_package_openssl install-dist-pkg-shim-nossl OFF OFF
+function run_dist_pkg_suite() {
+ local LAYOUT_MODE=$1
+
+ # Test 1: ENABLE_DIST_PKG only (shared libs)
+ echo ""
+ echo "############################################"
+ echo "# Test 1: ENABLE_DIST_PKG (shared libs) #"
+ echo "############################################"
+ install_aws_lc_dist_pkg install-dist-pkg-shared "${LAYOUT_MODE}" ON OFF
+ verify_dist_pkg_structure install-dist-pkg-shared "${LAYOUT_MODE}" .so OFF
+ test_cmake_find_package install-dist-pkg-shared "${LAYOUT_MODE}" ON
+ test_pkg_config install-dist-pkg-shared "${LAYOUT_MODE}" aws-lc OFF
+
+ # Symbol versioning tests (reuse the shared-lib install from Test 1)
+ echo ""
+ echo "############################################"
+ echo "# Symbol Versioning Tests #"
+ echo "############################################"
+ "${AWS_LC_DIR}/tests/ci/run_symbol_version_test.sh" "${SCRATCH_DIR}/install-dist-pkg-shared"
+
+ # Test 2: ENABLE_DIST_PKG + OPENSSL_SHIM (shared libs)
+ echo ""
+ echo "############################################"
+ echo "# Test 2: ENABLE_DIST_PKG + SHIM (shared) #"
+ echo "############################################"
+ install_aws_lc_dist_pkg install-dist-pkg-shim-shared "${LAYOUT_MODE}" ON ON
+ verify_dist_pkg_structure install-dist-pkg-shim-shared "${LAYOUT_MODE}" .so ON
+ test_cmake_find_package install-dist-pkg-shim-shared "${LAYOUT_MODE}" ON
+ test_pkg_config install-dist-pkg-shim-shared "${LAYOUT_MODE}" aws-lc OFF
+ test_pkg_config install-dist-pkg-shim-shared "${LAYOUT_MODE}" openssl OFF
+ # test_openssl_compat_pkg_config subsumes a standalone libcrypto compile: it
+ # token-checks all three OpenSSL module names and compiles/runs a consumer
+ # against 'libssl libcrypto'.
+ test_openssl_compat_pkg_config install-dist-pkg-shim-shared "${LAYOUT_MODE}" OFF
+ test_cmake_find_package_openssl install-dist-pkg-shim-shared "${LAYOUT_MODE}" OFF ON
+
+ # Test 3: ENABLE_DIST_PKG only (static libs)
+ echo ""
+ echo "############################################"
+ echo "# Test 3: ENABLE_DIST_PKG (static libs) #"
+ echo "############################################"
+ install_aws_lc_dist_pkg install-dist-pkg-static "${LAYOUT_MODE}" OFF OFF
+ verify_dist_pkg_structure install-dist-pkg-static "${LAYOUT_MODE}" .a OFF
+ test_cmake_find_package install-dist-pkg-static "${LAYOUT_MODE}" OFF
+ test_pkg_config install-dist-pkg-static "${LAYOUT_MODE}" aws-lc ON
+
+ # Test 4: ENABLE_DIST_PKG + OPENSSL_SHIM (static libs)
+ echo ""
+ echo "############################################"
+ echo "# Test 4: ENABLE_DIST_PKG + SHIM (static) #"
+ echo "############################################"
+ install_aws_lc_dist_pkg install-dist-pkg-shim-static "${LAYOUT_MODE}" OFF ON
+ verify_dist_pkg_structure install-dist-pkg-shim-static "${LAYOUT_MODE}" .a ON
+ test_cmake_find_package install-dist-pkg-shim-static "${LAYOUT_MODE}" OFF
+ test_pkg_config install-dist-pkg-shim-static "${LAYOUT_MODE}" aws-lc ON
+ test_pkg_config install-dist-pkg-shim-static "${LAYOUT_MODE}" openssl ON
+ test_openssl_compat_pkg_config install-dist-pkg-shim-static "${LAYOUT_MODE}" ON
+ # The native pc files are identical across the shared and static shim
+ # installs, so they are checked once, here, where --static also resolves the
+ # Requires.private/Libs.private fields.
+ test_native_pkg_config_unchanged install-dist-pkg-shim-static "${LAYOUT_MODE}" ON
+ # The static install reproduces the original FindOpenSSL failure: its
+ # extra-dependency path only runs when the library it found is a static archive.
+ test_cmake_find_package_openssl install-dist-pkg-shim-static "${LAYOUT_MODE}" ON ON
+
+ # Test 5: ENABLE_DIST_PKG + OPENSSL_SHIM, BUILD_LIBSSL=OFF
+ echo ""
+ echo "############################################"
+ echo "# Test 5: SHIM + BUILD_LIBSSL=OFF #"
+ echo "############################################"
+ install_aws_lc_dist_pkg install-dist-pkg-shim-nossl "${LAYOUT_MODE}" ON ON OFF
+ test_pkg_config_no_libssl install-dist-pkg-shim-nossl "${LAYOUT_MODE}"
+ test_pkg_config install-dist-pkg-shim-nossl "${LAYOUT_MODE}" openssl OFF
+ # Unlike the shim-shared/shim-static configs, this is the only compile/run
+ # against the shim modules here, so the libcrypto smoke test stays.
+ test_pkg_config install-dist-pkg-shim-nossl "${LAYOUT_MODE}" libcrypto OFF
+ test_cmake_find_package_openssl install-dist-pkg-shim-nossl "${LAYOUT_MODE}" OFF OFF
+}
+
+run_dist_pkg_suite standard
+run_dist_pkg_suite split
echo ""
echo "############################################"| execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink | ||
| "${AWSLC_BIN_PREFIX}openssl" "${CMAKE_CURRENT_BINARY_DIR}/openssl") | ||
| execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink | ||
| "${AWSLC_BIN_PREFIX}c_rehash" "${CMAKE_CURRENT_BINARY_DIR}/c_rehash") |
There was a problem hiding this comment.
The staged links should go in a dedicated subdirectory rather than next to build outputs. Here the c_rehash link replaces the build-tree copy of the script with a dangling link, and the library links leave dangling libcrypto.so/libssl.so at the top of the build tree.
There was a problem hiding this comment.
Done. Now installing them into "${CMAKE_CURRENT_BINARY_DIR}/install_symlinks". Let me know if this is not what you intended.
The current CMake configuration assumes that CMAKE_INSTALL_LIBDIR and
CMAKE_INSTALL_LIBDIR are always relative paths within
CMAKE_INSTALL_PREFIX. This would be correct for normal configurations
with CMAKE_INSTALL_PREFIX as `/usr`, CMAKE_INSTALL_LIBDIR as `lib` or
`lib64`, and CMAKE_INSTALL_BINDIR as `bin`. However, these flags can
also take absolute paths, and CMake generally handles that correctly.
In some places, AWS-LC installs symlinks to CMAKE_INSTALL_PREFIX
concatenated to the install lib/bin/include directory, which fails for
obvious reasons with absolute paths. In order to avoid this, we produce
these symlinks in CMAKE_CURRENT_BINARY_DIR and let CMake install them
into the correct directories, exactly as it knows how. This lets both
relative and absolute install directories be handled naturally.
Note that while GNUInstallDirs provides CMAKE_INSTALL_FULL_{dir}
variables that would handle absolute paths correctly, that only works
when users specify the install prefix at *configure* time, instead of at
install time (e.g. with `cmake --install`'s `--prefix` option). See
the disclaimers at https://cmake.org/cmake/help/v4.5/module/GNUInstallDirs.html.
We encountered the need for this in Nixpkgs, which does not use the
Filesystem Hierarchy Standard (FHS). In Nix, AWS-LC is install across
multiple directories without a shared install prefix, such as having
libraries in `/nix/store/aaaaaa-aws-lc-5.15.0`, binaries in
`/nix/store/bbbbbb-aws-lc-5.15.0-bin`, and headers in
`/nix/store/cccccc-aws-lc-5.15.0-dev`. Despite this being somewhat
unique, CMake is able to handle this naturally, and we feel that it
makes sense for AWS-LC to use CMake's primitives to handle it
automatically as well.
99c3d79 to
9aa9561
Compare
Context and motivation
The current CMake configuration assumes that CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR are always relative paths within CMAKE_INSTALL_PREFIX. This would be correct for normal configurations with CMAKE_INSTALL_PREFIX as
/usr, CMAKE_INSTALL_LIBDIR asliborlib64, and CMAKE_INSTALL_BINDIR asbin. However, these flags can also take absolute paths, and CMake generally handles that correctly.In some places, AWS-LC installs symlinks to CMAKE_INSTALL_PREFIX concatenated to the install lib/bin/include directory, which fails for obvious reasons with absolute paths.
We encountered the need for this in Nixpkgs, which does not use the Filesystem Hierarchy Standard (FHS). In Nix, AWS-LC is installed across multiple directories without a shared install prefix, such as having libraries in
/nix/store/aaaaaa-aws-lc-5.15.0, binaries in/nix/store/bbbbbb-aws-lc-5.15.0-bin, and headers in/nix/store/cccccc-aws-lc-5.15.0-dev. Despite this being somewhat unique, CMake is able to handle this naturally, and we feel that it makes sense for AWS-LC to use CMake's primitives to handle it automatically as well.Description of changes
In order to avoid this issue of mishandling absolute paths, we produce these symlinks in CMAKE_CURRENT_BINARY_DIR and let CMake install them into the correct directories, exactly as it knows how. This lets both relative and absolute install directories be handled naturally.
Note that while GNUInstallDirs provides CMAKE_INSTALL_FULL_{dir} variables that would handle absolute paths correctly, that only works when users specify the install prefix at configure time, instead of at install time (e.g. with
cmake --install's--prefixoption). See the disclaimers at https://cmake.org/cmake/help/v4.5/module/GNUInstallDirs.html.Testing
No tests were added, as this is a purely CMake change. I've manually tested this in whatever configurations I could come up with, but I'm far from a CMake expert. I'm not sure how else one would test this, but I'm happy to make any adjustments as needed.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.