Skip to content

Commit

Permalink
update packaging: add requirements into debian tar.gz files
Browse files Browse the repository at this point in the history
When using the tar balls - it's problematic sometime, since we don't
include the required libraries that are needed to run, and have no way to
communicate these to a end user (like a deb or rpm does).

This fixes that by adding a "required2tar" target which can be run after
"make package", which fixes this problem, by adding the required libraries
to the tar ball, just like we do for the windows zip file.

Signed-off-by: Robin Getz <rgetz@mathworks.com>
  • Loading branch information
rgetz committed Jun 22, 2023
1 parent cb2d9e0 commit 30a0a85
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions CI/azure/ci-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mkdir build && cd build
cmake .. -Werror=dev -DCOMPILE_WARNING_AS_ERROR=ON -DWITH_SERIAL_BACKEND=ON -DWITH_EXAMPLES=ON -DCPP_BINDINGS=ON -DPYTHON_BINDINGS=ON -DENABLE_PACKAGING=ON -DCPACK_SYSTEM_NAME="${ARTIFACTNAME}"
make
make package
make required2tar
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ stages:
fi
make
make package
make required2tar
displayName: 'Build'
- task: CopyFiles@2
inputs:
Expand Down
39 changes: 39 additions & 0 deletions cmake/LinuxPackaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ set(CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT})
set(CPACK_BUNDLE_NAME libiio)
set(CPACK_PACKAGE_VERSION ${LIBIIO_VERSION})

# Start with empty file
set(REQUIRES "${CMAKE_BINARY_DIR}/require_manifest.txt")
file(WRITE ${REQUIRES} "")

# Determine the distribution we are on
file(STRINGS /etc/os-release distro REGEX "^NAME=")
string(REGEX REPLACE "NAME=\"(.*)\"" "\\1" distro "${distro}")
Expand Down Expand Up @@ -209,12 +213,47 @@ foreach(package ${PACKAGES})
set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}"
"${match} >= ${RPM_VER}, ")
endif()
# find the actual so files
STRING(REGEX MATCHALL "libc6|glibc" TEMP_TEST ${match})
if(NOT "${TEMP_TEST}" STREQUAL "")
continue()
endif()
if (CPACK_GENERATOR MATCHES "DEB" AND DPKG_CMD)
# build up the so locations
execute_process(COMMAND "${DPKG_CMD}"
-L "${match}"
OUTPUT_VARIABLE DPK_RESULT)
elseif (CPACK_GENERATOR MATCHES "RPM" AND RPM_CMD)
execute_process(COMMAND "${RPM_CMD}" -ql ${match}
OUTPUT_VARIABLE DPK_RESULT)
else()
continue()
endif()
STRING(STRIP ${DPK_RESULT} STRIPPED)
STRING(REGEX REPLACE "[\r\n]" ";" POSSIBLE_SO "${STRIPPED}")
foreach(is_so ${POSSIBLE_SO})
# match with ".so." or ".so" (and the end)
STRING(REGEX MATCHALL "\\.so$|\\.so\\." TEMP_TEST ${is_so})
if("${TEMP_TEST}" STREQUAL "")
continue()
endif()
if(IS_SYMLINK ${is_so})
continue()
endif()
file(APPEND ${REQUIRES} "${is_so}\n")
endforeach(is_so)
endforeach(match)
endforeach(package)

configure_file( "${CMAKE_SOURCE_DIR}/cmake/add_requirements2tar.sh.in"
"${CMAKE_BINARY_DIR}/add_requirements2tar.sh"
IMMEDIATE @ONLY
)
add_custom_target(required2tar
COMMAND sh ${CMAKE_BINARY_DIR}/add_requirements2tar.sh
COMMENT "Adding requirements to tarball"
)

if (CPACK_GENERATOR MATCHES "DEB")
if (NOT DPKGQ_CMD)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${DEFAULT_DEB}")
Expand Down
69 changes: 69 additions & 0 deletions cmake/add_requirements2tar.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh
# should be called from "make required2tar"
set -e

cd @CMAKE_BINARY_DIR@

manifest=./require_manifest.txt
if [ ! -f ${manifest} ] ; then
echo "Can not find manifest at ${manifest}"
exit 1
fi

gz=$(ls ./libiio*.tar.gz)
if [ -z "${gz}" ] ; then
echo "try make package first"
exit 1
fi
if [ "$(echo -n ${gz} | tr -cd ' \t' | wc -c)" -ne "0" ] ; then
echo "too many tar, there should be only one, but found ${gz}"
exit 1
fi
tar=$(echo ${gz} | sed 's/\.gz$//')

#unzip the file (can not append while it is gzipped)
#gunzip ${gz}

# We should be able to just "tar --append -f ${tar} -T manufest.txt, but the tar on
# CenrOS7 doesn't support that - so we we need to split it apart, and add
# files manually.

if [ -d tarball_fixup ] ; then
rm -rf tarball_fixup
fi
mkdir tarball_fixup
tar -xzf ${gz} -C ./tarball_fixup

while read -r line
do
if [ -f ${line} ] ; then
echo "adding ${line} to architve"
#make sure the directory exists as a target
mkdir -p ./tarball_fixup$(dirname ${line})
cp ${line} ./tarball_fixup${line}

cd ./tarball_fixup$(dirname ${line})
line=$(basename ${line})

until echo ${line} | grep -q \.so.[0-9]*$
do
tmp=$(echo ${line} | sed 's/\.[0-9]*$//')
if [ ! -f "${tmp}" ] ; then
ln -s ${line} ${tmp}
else
echo "target ${tmp} already exists"
ls -l ${tmp}
fi
line=${tmp}
done
cd @CMAKE_BINARY_DIR@

else
echo "could not find ${line} to copy"
exit 1
fi
done < ${manifest}

tar -czf ${gz} -C ./tarball_fixup/ .
rm -rf tarball_fixup

0 comments on commit 30a0a85

Please sign in to comment.