Skip to content

Commit

Permalink
ci/arm: update copy-deps script
Browse files Browse the repository at this point in the history
Signed-off-by: Bindea Cristian <[email protected]>
  • Loading branch information
bindea-cristian committed Nov 18, 2024
1 parent 6322fde commit 29238d6
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 38 deletions.
8 changes: 4 additions & 4 deletions ci/arm/arm_build_process.sh
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ create_appdir(){
mkdir -p $APP_DIR/usr/lib/scopy/plugins/resources
cp $EMU_CONFIG $APP_DIR/usr/lib/scopy/plugins/resources

$COPY_DEPS ${TOOLCHAIN_HOST} $APP_DIR/usr/bin/scopy $APP_DIR/usr/lib
$COPY_DEPS ${TOOLCHAIN_HOST} $APP_DIR/usr/bin/iio-emu $APP_DIR/usr/lib
$COPY_DEPS ${TOOLCHAIN_HOST} $APP_DIR/usr/bin/scopy $APP_DIR/usr/lib
$COPY_DEPS ${TOOLCHAIN_HOST} "$APP_DIR/usr/lib/scopy/plugins/*.so" $APP_DIR/usr/lib
$COPY_DEPS --lib-dir ${SYSROOT}:${BUILD_FOLDER} --output-dir $APP_DIR/usr/lib $APP_DIR/usr/bin/scopy
$COPY_DEPS --lib-dir ${SYSROOT}:${BUILD_FOLDER} --output-dir $APP_DIR/usr/lib $APP_DIR/usr/bin/iio-emu
$COPY_DEPS --lib-dir ${SYSROOT}:${BUILD_FOLDER} --output-dir $APP_DIR/usr/lib $APP_DIR/usr/bin/scopy
$COPY_DEPS --lib-dir ${SYSROOT}:${BUILD_FOLDER} --output-dir $APP_DIR/usr/lib "$APP_DIR/usr/lib/scopy/plugins/*.so"
cp -r $QT_LOCATION/plugins $APP_DIR/usr

# search for the python version linked by cmake and copy inside the appimage the same version
Expand Down
145 changes: 111 additions & 34 deletions ci/arm/copy-deps.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,120 @@
#!/bin/bash

set -e
SRC_DIR=$(git rev-parse --show-toplevel 2>/dev/null ) || \
SRC_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && cd ../../ && pwd )
source $SRC_DIR/ci/arm/arm_build_config.sh $1

BINARY=$2
LOCATION=$3
usage()
{
echo "test"

}
COPY=""

while [ "$1" != "" ]
do
case "$1" in
"--help"| "-h")
usage
exit
;;
"--lib-dir" | "-l")
SYSROOT="$2:$SYSROOT"
shift
;;
"--output-dir" | "-o")
OUTPUT_DIR="$2"
COPY="true"
shift
;;
*)
FILES="$FILES $1"
;;
esac
shift
done

LIBS_ARRAY=()
BLACKLISTED=($(wget --quiet https://raw.githubusercontent.com/probonopd/AppImages/master/excludelist -O - | sort | uniq | cut -d '#' -f 1 | grep -v "^#.*" | grep "[^-\s]"))

if [ ! -f "${SRC_DIR}"/ci/arm/ldd-mod ]; then
if [ ${TOOLCHAIN_HOST} == "aarch64-linux-gnu" ];then
sed 's|.*RTLDLIST=.*|RTLDLIST="/usr/aarch64-linux-gnu/lib/ld-2.31.so /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1"|' /usr/bin/ldd | tee "${SRC_DIR}"/ci/arm/ldd-mod
elif [ ${TOOLCHAIN_HOST} == "arm-linux-gnueabihf" ]; then
sed 's|.*RTLDLIST=.*|RTLDLIST="/usr/arm-linux-gnueabihf/lib/ld-2.31.so /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3"|' /usr/bin/ldd | tee "${SRC_DIR}"/ci/arm/ldd-mod
fi
chmod +x "${SRC_DIR}"/ci/arm/ldd-mod
# Separate SYSROOT into an array of SEARCH_PATHS
IFS=":" read -r -a SEARCH_PATHS <<< "$SYSROOT"

# If COPY is not true, display all dependencies without excluding any from the blacklist
if [[ $COPY != "true" ]]; then
BLACKLISTED=""
else
BLACKLISTED=($(wget --quiet https://raw.githubusercontent.com/probonopd/AppImages/master/excludelist -O - | sort | uniq | cut -d '#' -f 1 | grep -v "^#.*" | grep "[^-\s]"))
BLACKLISTED+=(ld-linux-armhf.so)
BLACKLISTED+=(ld-linux-aarch64.so.1)
fi

export LD_LIBRARY_PATH="${APP_DIR}/usr/lib:${SYSROOT}/lib:${SYSROOT}/lib/${TOOLCHAIN_HOST}:${SYSROOT}/usr/${TOOLCHAIN_HOST}/lib:${SYSROOT}/usr/local/qt5.15/lib:${SYSROOT}/usr/local/lib:${SRC_DIR}/build"
run_ldd(){
for library in $("${SRC_DIR}"/ci/arm/ldd-mod "$1" | cut -d '>' -f 2 | awk '{print $1}')
do
# check if the library exists at that path and if it was processed already or blacklisted
if ! [[ "${BLACKLISTED[*]}" =~ "${library##*/}" ]]; then
if [ -f "${library}" ] && ! [[ "${LIBS_ARRAY[*]}" =~ "${library}" ]]; then
LIBS_ARRAY+=("${library}")
echo "---Added new lib: ${library}"
if [ ! -f "${LOCATION}"/"${library##*/}" ]; then
cp "${library}" "${LOCATION}"
[ -L "${library}" ] && cp "$(realpath "${library}")" "${LOCATION}"
fi
run_ldd "${library}"
fi
fi
done
findlib()
{
LIB=$1
for path in "${SEARCH_PATHS[@]}"
do
LIB_PATH=$(find "$path" -name "${LIB%%.so*}.so*" -type f 2>/dev/null | sort | head -1)
[ "$LIB_PATH" != "" ] && break # Exit for at first succesful find
done

[ "$LIB_PATH" = "" ] && LIB_PATH="not found"
echo "$LIB_PATH"
}

for arg in $BINARY; do
run_ldd "${arg}"
done
copylib()
{
library=$1
destination=$2

lib_location=${library%/*}
lib_name=${library##*/}
lib_name_without_version=${lib_name%%.so*}.so

echo "${lib_name_without_version}"
echo -n copied:
cp --verbose "${library}" "${destination}"

#IFS=$'\n' read -r -a symlinks < <(find "$lib_location" -name "${lib_name_without_version}*" -type l 2>/dev/null) || echo "No symlinks to copy"

symlinks=($(find "$lib_location" -name "${lib_name_without_version}*" -type l 2>/dev/null))
for link in "${symlinks[@]}"
do
pushd ${destination} > /dev/null
[ -L "${link##*/}" ] && rm "${link##*/}"
echo -n linked:
ln --symbolic --verbose "${library##*/}" "${link##*/}"
popd > /dev/null
done
}

process_lib(){
DEPS=$(readelf -d "$1" 2> /dev/null | \
grep NEEDED | \
cut -d ":" -f 2 | \
sed -e 's,\[,,g' -e 's,],,g' -e 's,[ ]*,,g'| \
sort)

for library in $DEPS
do
# Check if the library is blacklisted or was already processed
if [[ ! "${BLACKLISTED[*]}" =~ "${library}" && ! "${LIBS_ARRAY[*]}" =~ "${library}" ]]; then

LIBS_ARRAY+=("${library}")
LIB_PATH=$(findlib "$library") # try to find the library in sysroot

if [[ $COPY == "true" ]]; then
if [[ $LIB_PATH == "not found" ]]; then
echo "Error: ${library} not found"
exit 1
fi
mkdir -p "$OUTPUT_DIR"
copylib "$LIB_PATH" "$OUTPUT_DIR"
fi

# If COPY is not true, display only the library and its location if found
[ "$COPY" != "true" ] && echo "$library => $LIB_PATH"
process_lib "$LIB_PATH"
fi
done
}

for arg in $FILES; do
process_lib "${arg}"
done

0 comments on commit 29238d6

Please sign in to comment.